Search code examples
javascriptgoogle-analyticsgoogle-analytics-api

How can I make sure _gaq.push() works good?


Our client asked us to implement the following Google Analytic code:

_gaq.push(['SX0._setCustomVar', 4, 'xxxx', "yyyy", 2]);

So I've made this, and now I'm looking for a way - how can I check that everything is correct (without actually building GA report)? I haven't did this before - so please sorry if the answer is obvious.

Thanks.


Solution

  • You'll need to define the _gaq variable and load in the analytics script from googles server. After that, you should be able to call the 'push' method.

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
    _gaq.push(['_trackPageview']);
    
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
    
    
    // tracks hit for /some/page/
    _gaq.push(['_trackPageview', '/some/page']);
    

    After that's done, load up the page in your browser, open up the console, and look in the network tab. Try loading a few pages, and verify that it's asynchronously pushing data to googles servers.

    Google uses a .gif image for tracking, so you might try filtering by image and to find request for a file called __utm.gif

    enter image description here

    If you're still having trouble finding it, you might try the tag debugger plugin by ObservePoint for Chrome or the Official Tag assistant plugin by Google