Last active
January 24, 2019 17:20
-
-
Save mskutta/ec27416cb6adc156eac7705d01f14c4e to your computer and use it in GitHub Desktop.
Sorting Sitecore Items by Popularity using xDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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