Skip to content

Instantly share code, notes, and snippets.

@SitecoreCpok
Created May 26, 2018 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SitecoreCpok/5943ed65e2fb349a4b4f740cd23b09c1 to your computer and use it in GitHub Desktop.
Save SitecoreCpok/5943ed65e2fb349a4b4f740cd23b09c1 to your computer and use it in GitHub Desktop.
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