Skip to content

Instantly share code, notes, and snippets.

@mskutta
Last active August 21, 2017 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mskutta/cf2f16d51493af87245b1df27594d1be to your computer and use it in GitHub Desktop.
Save mskutta/cf2f16d51493af87245b1df27594d1be to your computer and use it in GitHub Desktop.
Sorting Sitecore Items by Popularity using xDB
using System;
using Sitecore.Analytics;
using Sitecore.Diagnostics;
using Sitecore.Pipelines;
using Website.Logic.Common.Extensions;
using Sitecore.Data;
using Newtonsoft.Json;
namespace Website.Logic.Analytics.Views
{
public class ViewPageEventProcessor
{
public void Process(PipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
Assert.IsNotNull(Tracker.Current, "Tracker.Current is not initialized");
Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session is not initialized");
Assert.IsNotNull(Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized");
if (Tracker.Current.Session.Interaction == null)
return;
var currentPage = Tracker.Current.CurrentPage;
if (currentPage == null || currentPage.IsCancelled)
return;
var pageEventData = currentPage.Register(new Sitecore.Analytics.Data.PageEventData("View")
{
ItemId = item.ID.ToGuid(),
Text = string.Format("Template ID: {0}", item.TemplateID),
DataKey = item.TemplateID.ToString(),
Data = item.TemplateID.ToString()
});
}
}
}
@AdhirRamjiawan
Copy link

AdhirRamjiawan commented Aug 21, 2017

Hi, I've just been reading your blog post and tried to implement as your instructions but I cannot find where "item" used in the block on line 26 is supposed to be declared?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment