页面加载"_gat未定义“错误
曾尝试过来自:gaq is not defined (Google Analytics)的建议,但没有提供帮助。
下面是我的初始代码片段:
(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);
})();
var pageTracker pageTracker = _gat._createTracker('UA-xxxxxxxx-1');
<button onclick="pageTracker._setCustomVar(1,'customvar1', 'value', 3);
pageTracker._trackPageview();">Fire</button> 发布于 2014-05-19 07:18:06
下面是解决方案(添加延迟):
(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);
})();
var pageTracker;
setTimeout(function(){
pageTracker = _gat._createTracker('UA-xxxxxxxx-1');
pageTracker._initData();
}, 1000);
<button onclick="pageTracker._setCustomVar(1,'customvar1', 'value', 3);
pageTracker._trackPageview();">Fire</button> 在我的测试中,我发现1秒是一个很好的延迟期,任何小于1秒的内容都会产生更高的_gat未定义错误的可能性。
发布于 2015-05-05 13:31:54
老问题,我知道,但我能够修复我的"_gat是没有定义的“错误,包括第一个片段内的<head>标签。然后,在我想要跟踪的页面中的任何位置包括第二个片段。
因此,这是在<head:
(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);
})(); 在你想要追踪的任何一页上
pageTracker = _gat._createTracker('UA-xxxxxxxx-1');
pageTracker._trackPageview();https://stackoverflow.com/questions/23731864
复制相似问题