Skip to content

Instantly share code, notes, and snippets.

@hishaamn
hishaamn / DatabaseAgent.cs
Created April 25, 2018 06:51
Override Database Agent class to add display name
namespace Sitecore.Tools.Extensions
{
using System;
using System.Collections;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Jobs;
using Sitecore.Tasks;
public class DatabaseAgent : Tasks.DatabaseAgent
@hishaamn
hishaamn / z.Sitecore.Processing.config
Created April 25, 2018 06:59
Patch for Database Agent
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<scheduling>
<!-- An agent that processes scheduled tasks embedded as items in the master database. -->
<agent type="Sitecore.Tools.Extensions.DatabaseAgent" method="Run" interval="00:10:00" name="Master_Database_Agent">
<param desc="database">master</param>
<param desc="schedule root">/sitecore/system/tasks/schedules</param>
<LogActivity>true</LogActivity>
</agent>
private readonly ID clickPageEventCategoryItemId = new ID("Item ID of the Content Event Click");
public void OnItemSaved(object sender, EventArgs args)
{
var savedItem = Event.ExtractParameter(args, 0) as Item;
if (savedItem == null || savedItem.Database.Name.ToLower() != "master")
{
return;
}
public void CreateClickContentEvent(Guid itemId)
{
if (Tracker.IsActive && Tracker.Current != null)
{
Assert.IsNotNull(Tracker.Current, "Tracker.Current");
if (Tracker.Current != null)
{
Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session");
public class AnalyticsDownloadCrawler : AnalyticsObserverCrawler<DownloadEventIndexable>
{
}
@hishaamn
hishaamn / DownloadEventIndexable.cs
Created June 5, 2018 19:35
The implementation of the DownloadEventIndexable
public class DownloadEventIndexable : AbstractIndexable
{
public DownloadEventIndexable(PageEventData eventData, string url, Guid interactionId, Guid contactId)
{
var str = interactionId + url + eventData.DataKey;
this.Id = (IndexableId<string>)str;
this.UniqueId = new IndexableUniqueId<Guid, string>(contactId, $"downloadEvent|{str}");
this.DataSource = "sitecore_aggregation";
this.AbsolutePath = string.Empty;
this.Culture = CultureInfo.GetCultureInfo(ContentSearchManager.SearchConfiguration.AnalyticsDefaultLanguage);
@hishaamn
hishaamn / DownloadEventIndexableLoadFieldsPipelineArgs.cs
Created June 5, 2018 19:44
Argument class to pass data through pipelines
public class DownloadEventIndexableLoadFieldsPipelineArgs : IndexableLoadFieldsPipelineArgs
{
public DownloadEventIndexableLoadFieldsPipelineArgs(PageEventData eventData, string url, Guid interactionId, Guid contactId)
{
this.EventData = eventData;
this.Url = url;
this.InteractionId = interactionId;
this.ContactId = contactId;
}
@hishaamn
hishaamn / DownloadEventIndexableLoadFieldsPipeline.cs
Created June 5, 2018 19:46
Pipeline to run the load fields
public class DownloadEventIndexableLoadFieldsPipeline
{
public static List<IIndexableDataField> Run(ICorePipeline pipeline, DownloadEventIndexableLoadFieldsPipelineArgs args, string pipelineName = "downloadeventindexable.loadfields")
{
try
{
pipeline.Run(pipelineName, args);
}
catch
{
@hishaamn
hishaamn / DownloadLoadFields.cs
Created June 5, 2018 19:48
Processor to update the fields with the data
public class DownloadLoadFields : DownloadIndexableLoadFieldsProcessor
{
protected override IEnumerable<IIndexableDataField> GetFields(DownloadEventIndexableLoadFieldsPipelineArgs args)
{
Assert.ArgumentNotNull(args, nameof(args));
PageEventData eventData = args.EventData;
Assert.IsNotNull(eventData, "eventData");
public abstract class DownloadIndexableLoadFieldsProcessor
{
public virtual void Process(DownloadEventIndexableLoadFieldsPipelineArgs args)
{
if (args == null)
throw new ArgumentNullException(nameof(args));
args.Fields.AddRange(this.GetFields(args));
}
protected abstract IEnumerable<IIndexableDataField> GetFields(DownloadEventIndexableLoadFieldsPipelineArgs args);