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)) { lastVisitedProducts.Add(product); ac++; } 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.
Visitor is not a property of SiteCore.Analytics.Tracker in 9.0.1
LikeLike
Does not work properly. I have suffered a lot and moved to the
cookie approach..
LikeLike