Google analytics event tracking not working

半腔热情 提交于 2019-12-11 06:10:01

问题


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?


回答1:


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




回答2:


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



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/2329566/google-analytics-event-tracking-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!