简体   繁体   中英

Google analytics event tracking not working

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?

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&answer=55527

I faced a lot of problem then I realize it's easy steps and want to share with everyone. First change your script code, link is https://developers.google.com/analytics/devguides/collection/gajs/#quickstart

Second add a button like this.
<>button onclick="_gaq.push(['_trackEvent', 'button3', 'clicked'])">Press<>/button>

Enjoy :)

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM