views:

737

answers:

3

I have this code setup to track image downloads throught Google Analytics.

<a href="/media/37768/CC20100117m001_thumb_2000.jpg"
    onclick="pageTracker._trackEvent('Image', 'Download', 'file.jpg');" 
    class="hi-res track">
Hi-Res</a>

But the events don't ever show up in the GA reports.

I thought maybe the the browser was following the link before the javascript was being run but setting href="#" doesn't work either.

Any ideas?

A: 

I don't know what your error is but to find out what it is you can:

  • Install firefox
  • Click on the link
  • Go to Tools | Error Console
  • Look at the error
Brian R. Bondy
There are no errors. When I run the code from Firebug it returns true
Cato Johnston
+2  A: 

This doesn't look correct to me--for one thing, you're using 'pageTracker' to call _trackEvent. In fact, _trackEvent is called by an 'event tracker' object, which is instantiated with _createEventTracker.

There are a couple more steps you haven't mentioned so et's go through them all. (There could be more than one correct way to do this--i'm not sure. So what i can do is compare your code with the steps i follow every time i set up Event Tracking, and which so far, have worked every time.)

  1. Enable 'Event Tracking'. (Do this in your profile.)

  2. Create the 'event tracker' instance and insert it just after the last line of the pageTracker script. This is usually a single line of code that in your case would look something like this:

    var ImageTracker = pageTracker._createEventTracker("Image")
    
  3. Set up the call to the _trackEvent() method in your html. I think all you need to do here is replace 'pageTracker' in your code with 'ImageTracker' (the event tracker instance you created in step 2 above).

doug
+1  A: 

Your browser may be following the link before Analytics can make the call logging the event. Check out this page for Google's solution:
http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&amp;answer=55527

nstory