0

Sitecore: 9.1 + JSS 11 - Integrated mode

Module: Path analyzer

Issue: We are using wild-card functionality to render certain pages in our application. In the path-analyzer report, we are seeing '*' (aestrik) under 'Name', not the name of the item to which the request had been resolved.

Are we missing something?

1

Out-of-the-box, Sitecore does not provide a solution for Wildcard pages and the related tools (Analytics Tracking, Path Analyzer, and so on).

You need to implement a custom solution for correctly instructing Sitecore what your Wildcard matches.

I am not sure if this code can run on Sitecore 9.1 (it is for 8.x), but it should give you a place to start.

using Sitecore;
using Sitecore.Analytics.Tracking;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Web;
using System;
using System.Web;
using Sitecore.Analytics.Pipelines.InitializeTracker;

namespace Someproject.Pipelines.InitializeTracker
{
    public class CustomCreatePage : InitializeTrackerProcessor
    {
        private void CreateAndInitializePage(HttpContextBase httpContext, CurrentInteraction visit)
        {
            IPageContext empty = visit.CreatePage();
            empty.SetUrl(WebUtil.GetRawUrl());
            DeviceItem device = Context.Device;
            if (device == null)
            {
                empty.SitecoreDevice.Id = Guid.Empty;
                empty.SitecoreDevice.Name = string.Empty;
            }
            else
            {
                empty.SitecoreDevice.Id = device.ID.Guid;
                empty.SitecoreDevice.Name = device.Name;
            }

            // Default Sitecore implementation
            Item item = Context.Item;

            // Our logic starts here: if the current item is a wildcard
            if (item != null && item.Name == "*")
            {
                // Perform a call to the logic which resolves the correct item
                var resolvedItem = this.ResolveWildcardItem(item);

                if (resolvedItem != null)
                {
                    item = resolvedItem;
                }
            }

            // Resume the default behaviour
            if (item == null)
            {
                return;
            }

            empty.SetItemProperties(item.ID.Guid, item.Language.Name, item.Version.Number);
        }

        public override void Process(InitializeTrackerArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.IsSessionEnd)
            {
                return;
            }
            HttpContextBase httpContext = args.HttpContext;
            if (httpContext == null)
            {
                args.AbortPipeline();
                return;
            }
            this.CreateAndInitializePage(httpContext, args.Session.Interaction);
        }

        private Item ResolveWildcardItem(Item item)
        {
            return Someproject.BusinessLogic.AbstactedData.GetDataSource(item, Someproject.BusinessLogic.SlugFactory.GetSlugPreSelected(item));
        }
    }
}

The code would need to be patched in:

<?xml version="1.0" ?>
<configuration xmlns :patch="http://www.sitecore.net/xmlconfig /" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <initializeTracker>
        <processor type="Someproject.Pipelines.InitializeTracker.CustomCreatePage,Someproject"            patch:instead="*[@type='Sitecore.Analytics.Pipelines.InitializeTracker.CreatePage, Sitecore.Analytics']" />
      </initializeTracker>
    </pipelines>
  </sitecore>
</configuration>

Sources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.