During the past few weeks, I have been working on a module which makes use of the Sitecore Analytics. I had to manipulates goals, profiles and outcomes programmatically. Especially Outcomes as it can only be triggered programmatically. Moreover, following a question on Sitecore StackExchange, I decided to blog about it.
Normally, you will receive the
pageDefinitionId once the page event has been registered. But what if, you require it before the page is registered? The different events, profiles and goals are all stored on the item in the Tracking Field. All we need to do first is to have the context item at hand in order to be able to continue.
Once we have the context item, the below code can be used to get the different attributes.
By converting the field to
TrackingField, you will have access to different properties as shown in below screenshot.
So, you can actually retrieve the values for the Profiles, Events and Campaigns. This is very useful in the sense that you don’t need to hard code the ID when instantiating the PageEventData.