2

I created a custom page event under /Settings/Analytics/Page events/ and assigned it on a page using the ribbon option under Analytics -> Attributes.

I want to dynamically get the pageDefinitionId (GUID) of this custom event in code behind when registering the page event and not hard code the GUID.

I tried using Tracker.Current.CurrentPage.PageEvents but it returns null. Looks like we can get the pageDefinitionId only after page event is registered bypage.Register(pageEventData)

2

Assuming you have access to the context item, you can get the pageDefinitionId by reading the Tracking field on the item. Below is a code snippet that you can use to retrieve the event:

public static void GetEventDefinition(Item item)
{
    Assert.ArgumentNotNull(item, "item");

    var field = item.Fields["__Tracking"];

    if (field != null)
    {
        var trackingField = new TrackingField(field);

        foreach (var events in trackingField.Events)
        {
            var definitionId = events.DefinitionItem.ID;

            // Your processing goes here
        }
    }
}
  • I am trying to register a button click event on a page. For this as I mentioned earlier, created custom page event and assigned to the page. But the problem is: button event gets registered in xDB at session end though the button was not clicked. I want to register the click event programmatically but also provide flexibility to author to create events in Sitecore and assign to page. Are there any possible options to avoid registering events assigned to page and drive them programmatically? – Mohit Jun 16 '17 at 19:54
  • You need to create a new question for this one as the answer is not based on the question above. So it is preferable to create a new one where you can share more info and code if available – Hishaam Namooya Jun 16 '17 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.