Sitecore register page events

A Page Event in Sitecore is a way of tracking when a user have reached a goal by executing a call to action on a specific page, for example:

  • Downloaded a brochure
  • Clicked your banner
  • Done a search

A page event can be any text you like, and you can attach any data you wish.

You use the Sitecore.Analytics.Tracker to register the page event. Here is a small example on how to do it:

using System;
using Sitecore.Analytics;
using Sitecore.Analytics.Data;
using Sitecore.Analytics.Tracking;
using Sitecore.Diagnostics;

namespace MyNamespace
  public class RegisterPageDataService
    public void RegisterPageEvent(string eventName, string text, string data, string dataKey)

      if (!Tracker.IsActive)

      ICurrentPageContext currentPage = Tracker.Current.CurrentPage;
      if (currentPage == null)

      RegisterEventOnCurrentPage(eventName, text, data, dataKey, currentPage);

    private static void RegisterEventOnCurrentPage(string eventName, string text, string data, string dataKey, IPageContext currentPage)
      PageEventData pageEvent = new PageEventData(eventName) 
            Text = text, 
	    Data = data ?? string.Empty, 
            DataKey = string.IsNullOrEmpty(dataKey) ? string.Empty : dataKey
      catch (Exception exception)
        Log.Error(string.Format("{0} pageevent not created in current Sitecore Instance: {1}", eventName, exception), typeof(RegisterPageDataService));

Using the code is pretty straight forward:

// Registering a click goal
RegisterPageDataService service = new RegisterPageDataService();
service.RegisterPageEvent("Goal", "Clicked", string.Empty, string.Empty);

// Registering a search
RegisterPageDataService service = new RegisterPageDataService();
service.RegisterPageEvent("Search", "Freetext", "Pentia A/S", "Search");

The register page event ends up in the xDB (MongoDB) in the”Interactions” collection, look for “Pages” (this example is one of Sitecore’s events, not my event):

Page Event

Page Event





About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, General .NET, Sitecore 8 and tagged , , , , , . Bookmark the permalink.

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 )

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.