当前位置: 动力学知识库 > 问答 > 编程问答 >

event tracking - Google analytics _trackEvent not functioning

问题描述:

I have used _trackEvent for several links. But in google analytics it shows as 0 events and no tracking data are displayed.

Below is the code I used. Do I have to wait 24 hours to view the tracking data? or anything wrong with this?

<a href="https://sites.google.com/site/example/"

onClick="_gaq.push(['_trackEvent', 'Links', 'Bags', 'Mainlinkbags']);"

target="_parent">

tracking code

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-xxxxxx-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)

();

网友答案:

Sometimes it is good practice to use "onmousedown" event instead of "onclick" because "onmousedown" is fired sooner, so GA script has more time to execute event tracking (it's only a few milliseconds difference, but can help). Try it.

http://www.w3schools.com/jsref/event_onmousedown.asp

分享给朋友:
您可能感兴趣的文章:
随机阅读: