为什么Google Analytics不跟踪任何事件? [英] Why is Google Analytics not tracking any events?
问题描述
我已经实现了几乎所有的标准示例:
< script>
var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-mycode']);
_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);
})();
< / script>
< script>
函数recordOutboundLink(link,category,action){
try {
var myTracker = _gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent',category,action]);
setTimeout('document.location =''+ link.href +'',100)
} catch(err){}
}
< /脚本>
并且链接有这个onclick事件:
< a id =latestDownloadhref =https://example.comonClick =recordOutboundLink(this,'newDownloads','latest'); return false; >下载最新版本< / a>
过去3天没有任何事件被追踪,这对我来说听起来是错误的。我已经使用GA调试插件为chrome测试了页面,该插件显示事件已发送。
我在这里犯了些什么错误?
编辑:
页面:
refreshless.com/nouislider/download/
编辑2:
Google GA调试插件显示(字面意思,没有模糊处理):
帐户ID:UA-XXXXX-X
& utmac = UA-XXXXX-X
我需要推送'_setAccount'再次?
tl; dr ...省略 _getTrackerByName()
调用,只需使用
_gaq.push(['myTracker._trackEvent',category,action]);
更长的解释:异步跟踪允许将命令推送到多个跟踪器(请参阅 Tracking Basics ),使用类似于
的语法 _gaq.push(['_ setAccount','UA-XXXXX-1']);
_gaq.push(['_ trackPageview']);
_gaq.push(['b._setAccount','UA-XXXXX-2']);
_gaq.push(['b._trackPageview']);
_gaq.push(['myTracker._trackEvent',category,action ]);
代码假定您已经像上面的 b
跟踪器一样初始化了 myTracker
。
由于 myTracker
从来没有设置accountId,它显示 UA-XXXXX-在调试时X
accountId。
专用追踪/出站链接是错误的,或者只有在名为 myTracker
。
I've implemented pretty much the standard examples:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-mycode']);
_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);
})();
</script>
<script>
function recordOutboundLink(link, category, action) {
try {
var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', category , action ]);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
</script>
and the links have this onclick event:
<a id="latestDownload" href="https://example.com" onClick="recordOutboundLink(this, 'newDownloads', 'latest');return false;">Download latest version</a>
No events have been tracked for the past 3 days, which just sound wrong to me. I've tested the page with the GA debug plugin for chrome, which shows events are send.
Have I made some mistake here?
Edit:
Page is: refreshless.com/nouislider/download/
Edit 2:
The Google GA debug addon shows (literally, not obfuscated):
Account ID : UA-XXXXX-X
&utmac=UA-XXXXX-X
Do I need to push the '_setAccount' again?
tl;dr... leave out the _getTrackerByName()
call, just use
_gaq.push(['myTracker._trackEvent', category , action ]);
Longer explanation: Async tracking allows pushing commands to multiple trackers (see Tracking Basics) using a syntax like
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['b._setAccount', 'UA-XXXXX-2']);
_gaq.push(['b._trackPageview']);
The _gaq.push(['myTracker._trackEvent', category , action ]);
code assumes you've already initialized myTracker
like the b
tracker above.
Since myTracker
has never had an accountId set, it shows the UA-XXXXX-X
accountId while debugging.
The analytics code on Specialized Tracking/Outbound Links is wrong, or would only work if the setup code named myTracker
.
这篇关于为什么Google Analytics不跟踪任何事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!