Skip to content

Instantly share code, notes, and snippets.

@mskutta
Last active January 24, 2019 17:20
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/ec27416cb6adc156eac7705d01f14c4e to your computer and use it in GitHub Desktop.
Save mskutta/ec27416cb6adc156eac7705d01f14c4e to your computer and use it in GitHub Desktop.
Sorting Sitecore Items by Popularity using xDB
using System;
using System.Linq;
using Sitecore.Analytics.Aggregation.Pipeline;
using Sitecore.Diagnostics;
namespace Website.Logic.Analytics.Views
{
public class ViewAggregationProcessor : AggregationProcessor
{
protected override void OnProcess(AggregationPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (args.Context.Visit.Pages == null)
return;
foreach (var page in args.Context.Visit.Pages)
{
if (page.PageEvents != null)
{
var fact = args.GetFact<ViewFact>();
foreach (var pageEvent in page.PageEvents.Where(p => p.Name == "View"))
{
var viewKey = new ViewKey {
Date = pageEvent.DateTime.Date,
ItemId = pageEvent.ItemId
};
var viewValue = new ViewValue
{
Count = 1,
TemplateId = new Guid(pageEvent.Data)
};
fact.Emit(viewKey, viewValue);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment