home portfolioblog academic work about contact

Having issues with event tracking in Google Analytics? Read on…

Posted by Sarah on July 29, 2009 at 10:40 pm.

Note: feel free to ping me or leave a comment if you are having major issues!

Yesterday the event tracking on a site was not working, and someone thought it might be that I had missed a call to the ga.js file or some extra Javascript. My first thought was “This is why I hate Javascript.” That thought recurred throughout my investigation process, but I decided to save some people time and effort by posting a few things you could check before giving up and crying. My particular example was an onClick event, but the same things could apply to other situations.

  1. Check the JavaScript call. So you must understand that Javascript (which I shall now write as JS) can be the best and worst scripting language. Very powerful and can do cool things like animation (and your analytics tracking), but also a pain in that you must be very careful with syntax and punctuation. One easy way to see if your JS is creating errors is by installing the Web Developer’s Toolbar in Firefox, it will show you when there are JS errors and a myriad of other useful things.

    Example: onclick=”pageTracker._trackEvent(”Foo”,”Bar”,”JS”);” This will be wrong because you have double quotation marks instead of apostrophes within the parentheses. So the page will read it as “pageTracker.trackEvent(” which will not do anything. Fix it like this: onclick=”pageTracker._trackEvent(’Foo’,'Bar’,'JS’);”.

  2. Is the variable actually pageTracker? In most cases, if you’re not changing the Google Analytics code that is on every page, it should be pageTracker. If the variable is named anything else, like movieTracker or pageCounter, then you need to fix the call in the onClick and change it to: onclick=”movieTracker._trackEvent(…);” This is the part of the code you want to pay attention to:

    try {
    var pageTracker = _gat._getTracker(”UA-xxxxxx-x”);
    pageTracker._trackPageview();
    } catch(err) {}

  3. Where your code at? This ended up being my problem. People recommend that the GA code should be inserted at the footer of the page to not slow down the loading time of a page. The catch is, the JS file/definition of the variable pageTracker may need to be at the top of the page for _trackEvent to do its thing. If you try moving the code with the ga.js file to the head of the page, it should help. Or it helped me anyway.

As much as I hate debugging JS, I think it has really helped me to have knowledge of how it works, so if this is all kinds of confusing, try working through the W3C tutorials.

Misc.

The Grok delivers!! I was tweeting with @TheGrok and I asked if there was any way he could post about web analytics for non-profits. Brendan Regan wrote an awesomely helpful post about it. I will probably comment more about it later, but still, very cool.

And for those who use Twitter, #wa is being deprecated in favor of #measure. See Web Analytics Demystified for an explanation.

Share:
  • email
  • Twitter
  • Digg
  • del.icio.us
  • Facebook
  • FriendFeed
  • LinkedIn
  • Netvibes
  • Reddit
  • StumbleUpon
  • Yahoo! Buzz

Related Posts

2 Comments

Trackbacks / Pingbacks

Leave a Reply