Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sitecore 9 Trigger Goal
try
{
//Check if tracker is active or not
if (!Sitecore.Analytics.Tracker.IsActive)
{
Sitecore.Analytics.Tracker.StartTracking();
}
if(Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null)
{
Sitecore.Data.Items.Item goalItem = Sitecore.Context.Database.GetItem("{FHHFO59F-EDR3-34VR-96TC-87GQ7E77Y6D}");
if(goalItem != null)
{
var goalTrigger = Sitecore.Analytics.Tracker.MarketingDefinitions.Goals[GoaltoTrigger.ID.ToGuid()];
var goalEventData = Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterGoal(goalTrigger);
goalEventData.Data = goalItem["Name"];
goalEventData.ItemId = goalItem.ID.ToGuid();
goalEventData.DataKey = goalItem.Paths.Path;
goalEventData.Text = "Goal for Logic";
Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.