All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Google Analytics compatibility

AboutWout 8 Jul 2011 17:50 idea, complete

Hi Low,

For a client I need to set up search tracking in Google Analytics, where one of the requirements is that it tracks the search terms used. It is possible to track a 'virtual page' with the code, but it needs a properly formatted URI. So the URI will have to look like this: http://domain.com/search?q=Search+ter....

I accomplished this by adding a small snippet of code to the keywords method. Right before the keywords are returned, I added this:

$style = $this->EE->TMPL->fetch_param('style'); 

if ($style AND $style == 'ga')
{
$keywords = urlencode($keywords);
}


If the 'style' parameter is 'ga' (Google Analytics) then it will format it for use in an URL.

For the people who are wonder how to tie this into the tracking code:

 _gaq.push(['_trackPageview', '{site_url}search?q={exp:low_search:keywords query="{segment_3}" style="ga"}']); 


Regards,
Wouter

Replies

  1. Low 9 Jul 2011 10:57

    That's a nice idea, Wouter. I'll add something like this to the core. :)

  2. Low 31 Aug 2011 20:02

    This feature (format="" parameter) has been implemented in Low Search v1.0.5.

  3. JohanHedin 29 Oct 2012 13:37

    Hey, I need to add key words analytics compabilty to my Low search. I'm a bit confused about this however...

    I googled and found a javascript at: https://gist.github.com/2881680

    It looks simliar to this solution but I need some explanation..

    Wouldn't I get duplicate page views as I allready have an analytics code, or should this code snippet only be in the results template and that I remove my general tracking code? Or should the javascript be on the search page?

    In the javascript code it says the following: '/zoeken/?zoekwaarde=.. Is zooeken the template group or is that some kind of default value? And zoekwarde. Could I set that to anything I want or is that also a default Low Search value (or a value I need to set somewhere)?

    Thanks,
    Johan

  4. Low 29 Oct 2012 14:52

    I'm not all too familiar with customizing GA code for this, but here's my take:

    I think you can use any URL you want. Something like '/search?q=' seems to be most common. In your GA settings, you have to enter the parameter for the keywords somewhere. In this example, that would be 'q'. Only add that line on the search results page.

    Not sure about duplicates, but my guess is that GA handles that just fine.