Created
May 17, 2018 17:12
-
-
Save hishaamn/3bd115e682f9decfba3743bfc15f7c4d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public void CreateClickContentEvent(Guid itemId) | |
| { | |
| if (Tracker.IsActive && Tracker.Current != null) | |
| { | |
| Assert.IsNotNull(Tracker.Current, "Tracker.Current"); | |
| if (Tracker.Current != null) | |
| { | |
| Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session"); | |
| CurrentInteraction interaction = Tracker.Current.Session.Interaction; | |
| Assert.IsNotNull(interaction, "Tracker.Current.Session.Interaction"); | |
| Assert.IsNotNull(interaction.CurrentPage, "Tracker.Current.Session.Interaction.CurrentPage"); | |
| } | |
| var clickEventName = $"{itemId}_click"; | |
| var itemPath = $"/sitecore/system/Settings/Analytics/Page Events/Content Events Click/{clickEventName}"; | |
| var clickEventItem = Context.Database.GetItem(itemPath, Language.Parse("en")); | |
| if (clickEventItem != null) | |
| { | |
| PageEventData pageEventData = new PageEventData(clickEventName, clickEventItem.ID.ToGuid()) | |
| { | |
| ItemId = itemId, | |
| Data = itemId.ToString(), | |
| DataKey = itemId.ToString("B"), | |
| PageEventDefinitionId = clickEventItem.ID.ToGuid(), | |
| Text = "Clicked", | |
| Name = clickEventName | |
| }; | |
| if (Tracker.Current.Contact != null) | |
| { | |
| try | |
| { | |
| Tracker.Current.Interaction.CurrentPage.Register(pageEventData); | |
| } | |
| catch (Exception) | |
| { | |
| Log.Error($"Error on register tracking... ", "CreatePageEventWithGoal"); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment