Tracking Local Search with DMS
Sitecore’s Digital Marketing Suite (DMS) comes with some handy reports out of the box for analysing searches your users are performing on your Sitecore site. There’s both a high level report in the executive dashboard for site wide searches and also item reports for checking search terms leading to an item and searches performed on an item.
All these reports assist in helping you work out what people are looking for on your site and also when they can’t quite find the information they’re after when the arrive at an item.
But Sitecore doesn’t magically know what actions on your site constitute a user search. So we have to register that action ourselves. The way we do this is by registering a page event for the search
page event which ships with DMS and the search reports are written to report on.
I remember from the Online Marketing Suite (OMS) days there used to be a helper method for doing this. OMS contains an extension method for the AnalyticsPage
class in the Sitecore.Analytics.Extensions.AnalyticsPageExtensions
namespace called Search
. We can call it by using the following code:
if(AnalyticsTracker.IsActive)
AnalyticsTracker.Current.PreviousPage.Search(query, m_totalResultCount);
The above code would be called from the search results page. Note however that we register the search page event against the previous page where the search would have been entered by the user.
But with DMS I had a hard time finding the equivalent method. The above extension method is actually just a convenience method which registers the proper OMS page event. So with DMS, we just have to register the page event ourselves.
The following code registers the search
page event by name.
if (Tracker.IsActive &&
Tracker.Visitor != null &&
Tracker.Visitor.CurrentVisit != null)
{
var page = Tracker.Visitor.CurrentVisit.CurrentPage;
if (Tracker.Visitor.CurrentVisit.PreviousPage != null)
page = Tracker.Visitor.CurrentVisit.PreviousPage;
page.Register(new PageEventData("Search")
{
Data = query,
DataKey = query,
Text = query
});
}
Again, note how the page event is registered against the previous page, not the current one which would be the search results page (though I’m defaulting to the current page in the event the previous page is null).
I mentioned that the event is registered by name. DMS loads the page events defined in Sitecore and will find the event by name when the PagesRow.Register()
method is called.
With the above code in place, we’ll now be capturing analytics data for search actions on the website.
Here’s a handy tip, if after you’ve implemented the above code you still don’t see any data showing up in the search reports, trying changing the MinimumVisitsFilter
value in the sitecore/shell/Applications/Reports/Dashboard/Configuration.xml
file. With the default value of 50
in this setting you’ll need 50 different visits before any data shows in the report.
Nice to know about the config XML file. Thanks!