admin管理员组文章数量:1394086
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/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="" 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?
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?
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./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." 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?
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?
Share Improve this question edited Nov 2, 2019 at 9:36 Lg102 asked Apr 18, 2012 at 6:15 Lg102Lg102 4,9183 gold badges40 silver badges63 bronze badges 1- could you give us a link to your site - this problem is really hard to debug only looking at your code. implementation seems correct. – Łukasz Rysiak Commented Apr 18, 2012 at 6:34
3 Answers
Reset to default 4tl;dr... leave out the _getTrackerByName()
call, just use
_gaq.push(['myTracker._trackEvent', category , action ]);
Longer explanation: Async tracking allows pushing mands 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
.
myTracker
is a variable, so you cannot really refer to it inside a string. Following should work:
_gaq.push(['_trackEvent', category , action ]);
The setTimeout thing seems a bit risky to me - it assumes that the Google Analytics call has been made within 100 ms.
I prefer this:
function trackOutboundLink(url) {
_gaq.push(['_trackEvent', 'outbound', 'click']);
_gaq.push(function() {
window.location = url;
});
}
This queues up the redirect until after the Google Analytics async call has pleted.
To hook up:
<a href="#" onclick="trackOutboundLink('your-url');return false;">Link</a>
本文标签: javascriptWhy is Google Analytics not tracking any eventsStack Overflow
版权声明:本文标题:javascript - Why is Google Analytics not tracking any events? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744775375a2624591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论