Sitecore Analytics – Get Page Definition Id Programmatically

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s