Path Analyzer: Custom Map Type and Ajax Call Filter

Sitecore Path Analyzer has been significantly improved in version 8.2 and is a great tool to view the various paths contacts took during their journey. Path Analyzer relies to a large extent on engagement value associated with different events and goals. Marketers and very often developers will need to make an effort on setting up engagement value and tracking events across the entire solution to make the best use of Path Analyzer.

By default, Sitecore will track ajax calls as PageViews within interactions. The following image illustrates Path Analyzer tree node which is, in fact, an ajax call and so does not have any content associated. Very often ajax calls will have no valuable information for Marketers, but very often ajax calls may have events associated and be an essential part of the engagement.

path analyzer results

This post is intended to demonstrate how to set up new Path Analyzer Map Type and filter out ajax calls from Path Analyzer reports.

One solution could be to stop tracking ajax calls in the analytics. The solution is described in the following stack exchange question and will probably suit well some projects. I would not recommend such approach, since the more information we have collected about contact behavior – the better. Who knows how we will use data in later versions and campaigns. Such solution also does not work for historical data, i.e. you will need to remove historical data from Collection database and rebuild Path Analyzer Maps.

So why not to use conditional Path Analyzer Maps, where beloved rules engine can be used to filter data to be included in the Map. A developer could have a custom condition created and deployed, a new MapGroup could be set up with a custom condition. Well, it will work, but you will get entire interaction filtered out. There is no way to filter out individual event or category of events from the interaction.

It is Sitecore, and of course, there is a nice solution available. Out of the box, there are 2 Path Analyzer Map Types available: Page Map and Experience Map. Page maps are built from sequences of page visits within a given interaction. Unlike the Page maps, Experience maps can include other interaction attributes, such as channels, campaigns, goals, events, and outcomes, in addition to pages. Essentially each Page type has its tree builder implementation that dictates what data is included in the tree. We can create and deploy our custom Map type that will filter out certain events from the tree data during aggregation.

First, we need to create a Map Type definition item where we specify implementation type and assembly of the tree builder type.

path analyzer builder type

Next, we create a template that will be used to denote our custom Map. Our template will be inherited from default Map template - /sitecore/Templates/System/Path Analyzer/Map. In the new template, we denote a new Filter [single line text] field. This field will be used to specify the value of the filter.

path analyzer filter

Then we want this Map template to be associated with our Map Type definition and set mapping to the Map item implementation Model. We do it in _Standard Values.

path analyzer map

In the implementation of FilteredPageMapItem model we need to make sure our Filter value is added to the map options. Map option will further be used in the tree builder to filter data. InnerItem is our Map item that will be created in a few moments.

   
   public class FilteredPageMapItem : MapItem
    {
        public FilteredPageMapItem(Item innerItem) : base(innerItem)
        {

        }
        protected override Dictionary<string, string> GetMapOptions()
        {
            Dictionary<string, string> mapOptions = base.GetMapOptions();
            string key = Constants.MapOptionKeys.Filter;
            string str = this.InnerItem[Constants.FieldIDs.FilteredPageMap.FilterMapFieldID];
            mapOptions.Add(key, str);

            return mapOptions;
        }
    }

  

Finally, we need to create an implementation for our FilteredPagesTreeBuilder. Because we want similar to PageMap type elements included, we inherit from PageTreeBuilder. There we override BuildSequence() method to add our custom filter logic. Note that Definition property will contain the dictionary of all Options including our custom Filter value as well as the collection of Rules if you want to use them in combination.

   

    public class FilteredPagesTreeBuilder : PageTreeBuilder
    {
        public FilteredPagesTreeBuilder(TreeDefinition definition) : base(definition)
        {

        }

        protected override IEnumerable<Record> BuildSequence(IVisitAggregationContext context, IEnumerable<PageData> filteredPages)
        {
            var updatedPages = FilterPages(filteredPages);

            return base.BuildSequence(context, updatedPages);
        }

        protected IEnumerable<PageData> FilterPages(IEnumerable<PageData> filteredPages)
        {
            return filteredPages.Where(page => !page.Url.Path.Contains(FilterOptionValue));
        }

        protected string FilterOptionValue
        {
            get {
                return this.Definition.GetStringOption(Constants.MapOptionKeys.Filter);
            }
        }
    }

  

Now we are ready to setup and deploy a new Map Type instance. We create Map item inserted from Filtered Map template. For the demo purpose, we will set Filter value to “/controller/” meaning we want to filter our all page visits containing such keyword in the path. Double check your Map Type and Map Item Type fields are set correctly.

path analyzer map

You will further need to Save and Deploy your newly created map. Sitecore will start processing map within 30-60 minutes by default and finish processing depending on the number of interactions in your project.

Now let’s compare All Visits default report.

path analyzer report

With one where ajax calls are filtered out. Our new report looks cleaner and Marketers will less likely miss some important insights from Path Analyzer.

Path analyzer image

Complete source code available for download on GitHub.

Fly high with Sitecore! Call Brimit for boost.