tracking site searches in google analytics

12

2

In google analytics, you can track site searches by setting the query parameter. EE does not have search result URLs with a query parameter in them though i.e. search result URLs look like http://mysite.com/search/270ab420bad324607c6286bf28767910/ instead of http://mysite.com/search?q=keyword

So is there an easy way to track site searches using the native EE search module in google analytics - either natively (ideally) or using an add-on? I want to keep using the native EE search module if at all possible.

From searching I've seen various code snippets altering the _gaq.push(['_trackPageview' line in the analytics code, but I'm not sure exactly how to implement this and would rather not mess up the main site tracking, so I was hoping someone may have some working code for this.

Many thanks for your time.

Tidy

Posted 2012-11-26T16:11:51.967

Reputation: 560

Answers

19

I have a comment in the Search module docs on this. Inside your Analytics tracking code block, you can do something like this (change the segment conditionals to match your specific case)

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_trackPageview']{if segment_1 == 'search' && segment_2 == 'results'}, ['/search/results/?q={exp:search:keywords}']{/if}); 

Derek Hogue

Posted 2012-11-26T16:11:51.967

Reputation: 17 344

2brilliant derek many thanks - my googling had not thrown that up, don't know why i hadn't thought of checking the docs for this! – Tidy – 2012-11-26T20:32:59.093

4

"Super search" supports human-readable ( and therefor analytics-friendly ) queries: http://www.solspace.com/docs/addon/c/Super_Search

janvl

Posted 2012-11-26T16:11:51.967

Reputation: 1 154

Thanks Janvl - I should have said that I need to stick with the standard EE search module here - I've updated my question with that info. – Tidy – 2012-11-26T16:46:10.577

3

This is possible, but you need to modify the GA tracking code on EE's search results template.

There is a wiki article on how to do this, but with the launch of the new Ellis Lab site you'll have have to take a look at Google's cached version.

read the cached wiki article

UPDATE: Here's a link to a Gist of the same article in case the wiki doesn't make it back online

mjr

Posted 2012-11-26T16:11:51.967

Reputation: 575

thanks for this mjr and for going to the trouble of digging up the cached link. – Tidy – 2012-11-26T20:34:04.963

good call on the gist – mjr – 2012-11-29T14:44:18.413

1

EE does have native search keyword logging. Here's a link to the info in the docs.

Anna_MediaGirl

Posted 2012-11-26T16:11:51.967

Reputation: 12 118

No worries. I had a hunch that wasn't the URL you were aiming for. :) – Dom Stubbs – 2012-11-26T23:12:21.747