Get last visited pages from a Sitecore DMS (OMS) Profile

Quite a few Sitecore developers have wondered how to get any useful information out of the Sitecore DMS (Digital Marketing System), formerly known as Sitecore OMS (Online Marketing Suite). I’ll call it the Sitecore Analytics, since the namespace is Sitecore.Analytics. The API for Sitecore DMS is – how should I put it – not of the same high quality standard as Sitecore itself. However, this has never stopped anyone, and since DMS is packed with visitor data, I’ll show how to utilize this.

This is a simple example on how to use the DMS. This function extracts the full history of which pages the current visitor have clicked:

IEnumerable allVisitedPages = Sitecore.Analytics.Tracker.Visitor.DataContext.Pages.Reverse();

This is the full history. I reverse the list to get the last visited pages at the top. If the user has visited a page twice, it will show up twice. And any page is in the list, also the web site frontpage.

So the list needs to be filtered somehow. This example creates a fictional list of the 10 last product pages the user has visited:

protected IEnumerable GetProducts(int count)
  IEnumerable allVisitedPages = Sitecore.Analytics.Tracker.Visitor.DataContext.Pages.Reverse();

  List lastVisitedProducts = new List();
  int ac = 0;
  IEnumerable products = allVisitedPages.Select(GetItem).Where(item => item != null && item.TemplateName == "product" );
  foreach (Item product in products)
    if (!lastVisitedProducts.Exists(p => p.ID == product.ID))
    if (ac == count)
      return lastVisitedProducts;
  return lastVisitedProducts;

The real gem here is that the user profile is stored in a cookie, so the data is persisted. The next time the user opens the website, the data is still there and you can display the last visited products list.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in .net, c#, Sitecore 6 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 )

Google+ photo

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

Connecting to %s