所以这将有效:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-65432-1']);
_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);
})();
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
Run Code Online (Sandbox Code Playgroud)
但是,如果访问者可以通过类似的链接来http://example.com?autoPlay=Wind怎么办?那么视频已被请求,并开始播放,生成:
var _gaq = _gaq || [];
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
Run Code Online (Sandbox Code Playgroud)
事件.但是常规跟踪代码仍然在页面底部运行,这就是为什么我们有异步:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-65432-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); …Run Code Online (Sandbox Code Playgroud)