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

Support archive

Google Site Search tracking within Low Googlesearch

Chad Crowell 13 Sep 2011 00:20 question, complete

Hey Low - on Googlesearch, I implemented it with a site I just launched, and upon launch, we stopped being able to track our google site search within analytics. Is there anyway this add on can include support for that? Here is the article about it on Google: http://www.google.com/support/customs...

Replies

  1. Low 13 Sep 2011 10:48

    Hey Chad,

    Here's a thread about GA compatibility with Low Search. Would a similar solution work for Low GoogleSearch, you think?

  2. Chad Crowell 13 Sep 2011 15:56

    I did see that one. I don't think it will work. When I am looking at the code for the search forum with Google Site Search, and I check the box for analytics and put in my GA ID, here is the search form code it wants me to put on my site:

    <///div id="cse" style="width: 100%;">Loading<////div>
    <///script src="http://www.google.com/jsapi" type="text/javascript"><////script>
    <///script type="text/javascript">
    google.load('search', '1', {language : 'en'});
    var _gaq = _gaq || [];
    _gaq.push(["_setAccount", "UA-2984284-2"]);
    function _trackQuery(control, searcher, query) {
    var gaQueryParamName = "q";
    var loc = document.location;
    var url = [
    loc.pathname,
    loc.search,
    loc.search ? '&' : '?',
    gaQueryParamName == '' ? 'q' : encodeURIComponent(gaQueryParamName),
    '=',
    encodeURIComponent(query)
    ].join('');
    _gaq.push(["_trackPageview", url]);
    }
    google.setOnLoadCallback(function() {
    var customSearchControl = new google.search.CustomSearchControl('013039565104906942550:f98abdpj9bk');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.setSearchStartingCallback(null, _trackQuery);
    customSearchControl.draw('cse');
    }, true);
    <////script>

    (CSS removed)

    Looks pretty nasty, frankly.

  3. Low 13 Sep 2011 16:41

    Actually, I think it might work. If you look at the _trackQuery function in that JavaScript, all it eventually does, is call _gaq.push() with a url variable. That url variable is composed of the current URI plus search query string.

    So, you could, in your search results template, hard code the search url and force the _gaq.push() like that. I reckon it will get added to GA...

  4. Chad Crowell 14 Sep 2011 03:19

    Makes sense, I'll give it a whirl.

  5. Chad Crowell 14 Sep 2011 03:21

    Well, before I do- just checking- the search results URL for the site in question doesn't have a querystring. Go to www.gcx.com and search for, say, VHRC, and you'll see. If I use the segment hash I guess it might work.

  6. Low 14 Sep 2011 08:09

    I think you could use something like this to add tracking:

    _gaq.push(['_trackPageview', '{site_url}search?q=' + encodeURIComponent('{exp:low_googlesearch:keywords keywords="{segment_2}"}')]);

  7. Chad Crowell 15 Sep 2011 16:57

    Thanks Low - I'll give it a try. Since my GA code is in my global footer embed, do you think something like this will parse correctly?

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', '{lv_analytics_id{nsm_lang}}']);
    {if segment_1 == 'search'}
    _gaq.push(['_trackPageview', '{site_url}search?q=' + encodeURIComponent('{exp:low_googlesearch:keywords keywords="{segment_2}"}')]);
    {/if}
    _gaq.push(['_trackPageview']);

  8. Low 15 Sep 2011 20:47

    I reckon it will, Chad.