Gravatar for simon.byrne@ifsworld.com

Question by simonbyrne, Apr 20, 2015 1:06 PM

URL for search queries not compatible with Google Analytics Search Terms

Coveo's non-standard way of rendering search terms in the URL is causing us some difficulty in tracking search terms in Google Analytics. The only way to set up Google Analytics is to tell it what the argument string for search queries is. It's looking for something like:

www.mysite.com/search/?q=searchTerm

However, Coveo uses a different anchor-based approach with a hash instead:

www.mysite.com/search/#q=searchTerm

This is really quite unusual. The majority of systems out there append an argument string to the URL. Do you have a recommendation for how we could resolve this? Is it possible to switch Coveo to use argument strings? Or would we need to manually inject a faked page URL with Google Analytic's _trackPageview method?

We're using Coveo for Sitecore, FYI.

1 Reply
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, Apr 21, 2015 3:46 AM

I think the trackPageview method is the right one. For one thing, queries performed in the search page after the initial load aren't seen as page loads by Google Analytics (since it's only JavaScript updating the page).

We're using arguments after the # to be able to update their values in JavaScript. It's not possible to do so for "normal" query arguments without causing a full page reload --- or at least not in all browsers we support.

So, you should attach an handler to the querySuccess event and notify Google Analytics from there.

Gravatar for simon.byrne@ifsworld.com

Comment by simonbyrne, Apr 21, 2015 12:52 PM

Thanks, @mlaporte. We will take a look at our Coveo rendering and implement that. Thanks for the pointers.

Ask a question