Frequently Search Keywords using Sitecore DMS

This blog post will show you how to display frequently search keywords of any Search box within your website for Sitecore < 7.5.

So … we wanted to display under the Search box a list of few words that have been searched by users. Our website is multilingual, so our search keywords will depend on the current language of the website.

FrequentlySearchedKeywords

Create the Page Events

There is an article from Brian Pendersen talking about the use of the Search Page Events and how to register the search keywords when someone make a search on your website (You can read the article here). The problem with our website is that we are multilingual, so we have to create a page events for each language.

To create a page events go to : sitecore/system/Settings/Analytics/Page Events and add a page events per language finishing with the language name. if you have a lot of language, and you do not want to create multiple events, I’m sure that a little script with powershell module will do all the works for you easily.

SearchKeywordFR

 

Code to register the Event

This is a copy of the Brian Pendersen code adapted to register an event depending on the current language. You have to register the event on your « OnClick » event of your search button.

 

Code to retrieve the Frequently Search Keywords

Ok now that we have those events stored, we have to retrieve them.

So the events are stored in the Analytics Database in multiples tables and sitecore created a view « VisitEvents » which regroup all the information that we need. But what do we need ?

  • The event id to filter on it.
  • The value of the search keywords.

Instead of returning all the events and then filtering with C# code, i create a stored procedure which will try to make most of the work for me.

So the stored procedure will return « ResultNumber » of search keywords that match a specific event id (In this case, the page event of your current language) which has been searched more than « FromNumber » times.

I used LinqToSQL to bind my Stored Procedure to a C# method (If you never used LinqToSQL, you must read this article)

AnalyticsDb is my DataContext and I can call my stored procedure by his name.

Personally, I used the renderings parameters to set stuff like FromNumber / ResultNumber but you can use a Settings Item of course, it’s your choice (if your content editor need to show 10 words in English; and only 5 words in Dutch, the renderings parameters won’t allow you that because it’s not versioned right now (Sitecore 8 ? )).

Some improvement which can be done

– StopWords to avoid insult and stuff like that.

– if you see some improvement, of stuff which can be done differently, I’m open 😉

 During this blog post I also found …

If you look a little bit the VisitEvents view, you’ll see a language field. This language come from the Visits Table.

I was like Oh why I didn’t use that ! When I register the event, just change the CurrentVisit Language so I’ll only need one event.

The problem is the following scenario :

  • Your visitor come to your website in English and make a search.
  • We register the event as English.
  • Then he changed his mind and change the current language of the website and make another search in Dutch.
  • We register the event as Dutch.

That would be great 😉 but in fact we are not registering the event as Dutch or English, but we are changing the current visit language and so … the first search which was done in English will be now set as Dutch.

To bypass that, you can end the visit when your user change the language. That will create two rows in your view one in English and one in Dutch.

On your language switcher, you can do the following code:

Of course it will count as two visit in your reports.

You can then only register one event and adapt the stored procedure like this:

and then when you call the methods to retrieve the search keywords :

 

 

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *