1

I want to trigger a goal programmatically to the website visitor/contact and retrieve this triggered goal during the contact's current visit and in his future visits. I could trigger the goal of using CurrentPage.Register() method under Analytics.Tracker API, but how can I retrieve this goal in the same session and future sessions?

Please help. Thanks!

EDIT: It is not clear how to check whether the current contact is a new contact or an existing contact. Looks like Sitecore.Analytics.Tracker.Current.Contact.IsNew behaves inconsistently

1

1 Answer 1

2

Goals of the current visit (interaction) are stored in the session and can be retrieved using Tracker API:

List<PageEventData> pageGoals = Sitecore.Analytics.Tracker.Current.Interaction.Pages
                                .SelectMany(p => p.PageEvents)
                                .Where(evt => evt.IsGoal)
                                .ToList();

To retrieve goals of previous interactions you can use xConnect (SE question that you mentioned) or KeyBehaviourCache:

IReadOnlyCollection<KeyBehaviorCacheEntry> contactGoals = Sitecore.Analytics.Tracker.Current.Contact.KeyBehaviorCache.Goals;

If you want to personalize based on the fact that a specific goal was triggered during current or past interactions consider using Sitecore rules condition: /sitecore/system/Settings/Rules/Definitions/Elements/Visit/Goal was triggered during a past or current interaction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.