Track the correct wildcard item

Have you always wanted to track the correct item in Sitecore when you are using a wildcard page? In this blog I will show you how you solve this issue.


For this blog I have used Sitecore 8.1 update 3 platform without any custom modules installed.

The wildcard solution
For some specific scenarios we use the wildcard construction in Sitecore. The wildcard construction means that the name of the item is “*”. This construction is often used for detail pages (i.e. news detail pages or blog detail pages) where the presentation is set on the wildcard item and the data is loaded by the url (like “~/news/news-item”). The news items are often stored on a shared location within your content tree.

Item Path: /news/*
Url: /news/news-item

When this construction is implemented correctly a very powerful construction is created. The content manager can manage the layout for every news item on single item instead of applying it to all news items. Another advantage is that you can share this item across multiple sites.

The problem

For analytics purposes there is an issue regarding the tracking part. Because the page which is tracked is the wildcard page and not the item which is actually viewed. When you view visits in the Experience Profile or the paths in the Path analyzer you will see the items are pointing to the wildcard page and not to the item where the content is.

After implementing the wildcard construction you are viewing the Experience Profile of your visitors.

When you want to see details about the viewed items you will see the wildcard item instead of the requested item (for this case the requested news item).

See the following example: the visitor did navigate to the home page, news overview page and the wildcard page. But in fact you want to see the requested news items instead of the wildcard page.

The cause of this behavior is related to the tracker. The tracker tracks the current Context Item and that is actually as expected the wildcard page.

How to fix this

The tracking behavior of Sitecore starts with a pipeline called “initializeTracker”. The available processors of this pipeline can be found in the “Sitecore.Analytics.Pipelines.InitializeTracker” namespace in the “Sitecore.Analytics” assembly.

The logic to determine the current item is in the CreatePage processor. In the following code snippet I have made some changes to resolve the correct item.

After applying this patch you will see that the page name is pointing to the news item instead of the wildcard page. The only thing which you have to implement is the ResolveWildCard method where the correct item can be resolved based on the URL.

When this solution is implemented correctly, you will have:

Correct items in the Experience Profile visits
Correct paths in the Path Analyser

It is easy to update an existing Sitecore processor with a custom one where a specific implementation is done. Please take notice of the fact that this processor runs on every tracked site and that your implementation must be multisite proof. For a good solution you should implement a custom pipeline to resolve the specific item.

Onze technische blogs zijn in het Engels. Dit doen wij omdat wij menen dat technische kennis van Sitecore en Sitefinity grensoverschrijdend moet zijn. Wij leren veel van buitenlandse developers, wij delen onze kennis ook graag met hen. Mochten er in de code fouten zitten of punten ter verbetering, dan gaan we graag het gesprek aan.