if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null) { // Trigger a goal var goalItem = Sitecore.Context.Database.GetItem("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"); // Goal item if (goalItem != null) { var goal = new PageEventItem(goalItem); // Wrapper for goal var pageEventsRow = Tracker.Current.CurrentPage.Register(goal); // Goal rtecord to be stored pageEventsRow.Data = goalItem["Description"]; Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications(); } }The code above accesses the goal item in Sitecore via GUID (don't forget to publish!) and then registers it to the current page - also using the goals description as extra information.
On the goal item in Sitecore, you are also able to set if the goal is shown in events/latest events in the Experience Profile (a custom image can also be defined here).
This then means that the goal will show inside of the Experience Profile, which is great for a complete overview on site users.
Hi Ryan,
ReplyDeleteI've implemented the code like you mentioned in the post. I've one doubt here. I'm not able to view the activity,Goals in experience profile(like screen shot 2). Do we have to enable any option in settings to view as i'm using sitecore 8.
Looking forward hear your inputs on here.
Thanks in advance.. :)
Regards,
Kali Krishna
Hi Kali,
ReplyDeleteThe data may be being stored in the experience database (MongoDB), which may take time to aggregate into the analytics/reporting database in Sitecore (SQL Server). For dev/testing purposes you can flush your data through (for the current Sitecore session) using the C# code: Session.Abandon()