codeflood logo

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.

dashboard-search

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.

Comments

Lieven

Nice to know about the config XML file. Thanks!

Ivan Huang

Thanks Al, that saves lots of my time, the method in the Sitecore document looks too complex.

Please excuse my ignorance as I'm finishing up my first Sitecore implementation. But I had two questions about the code snippet:
1) Does it go in the search results page sublayout codebehind? 2) Where do the 'query' variable come from?
Many thanks

Alistair Deneys

Hi Joe, Yes, the code would go in your search results codebehind or wheverever you're executing the search logic. The "query" variable in my example was parsed from the keywords entered by the user. If you were using a textbox you could populate from it from the "Text" property or if you're using a query string parameter read the variable from the HttpContext.Current.Request.QueryString object.

[…] Tracking Local Search with DMS by Coffee=>Coder=>Code […]

mahendra

hi Alistair, i just tried to tracking the local search using sitecore DMS according to this blog. i create a RegisterSearchPageEvent and use it in my search page sublayout cobe behind. now when running the page it add the search keyword into database but when go to exclusive dashboard in sitecore it doesn't show any thing. i also change the MinimumVisitsFilter value

Alistair Deneys

Hi Mehandra, You may have to wait for a period before the executive dashboard shows the events. There is likely a background task that needs to run before the dashboard will show the event. I'll dig into it a little further.

The reports are cached for performance reasons at various levels, if you want to force an update you can clear your data/dashboard reports folder and then load up sql management studio and run some stored procedures on the analytics database, I explain this in a bit more detail here: http://andytsitecore.blogspot.co.uk/2013/10/sitecore-dms-and-analytics.html

Abhishek

Hi,
I have performed all the steps mentioned in the blog, I have checked that Analytics database is tracking the search keywords but reports doesn't show any records. Any one have idea for how much time it will take to reflect search keywords in reports? In my case, reports not showing any records,

Alistair Deneys

Hi Abhishek, Did you check the advice I gave at the bottom of the post about the Configuration.xml file?

Leave a comment

All fields are required.