Created
May 26, 2018 07:58
-
-
Save SitecoreCpok/5943ed65e2fb349a4b4f740cd23b09c1 to your computer and use it in GitHub Desktop.
Sitecore 9 Trigger Goal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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