Uncaught ReferenceError:_gaq未定义(Google Analytics) [英] Uncaught ReferenceError: _gaq is not defined (Google Analytics)

查看:254
本文介绍了Uncaught ReferenceError:_gaq未定义(Google Analytics)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


未捕获的ReferenceError:_gaq未定义

在chrome调试日志中查看站点页面时显示以下消息。 >

页面本身应该使用 onload 事件处理程序来跟踪一个对象, _trackEvent for Google Analytics。



我最好的猜测是,也许 ga.js 文件没有及时加载,因此触发的 onload _trackEvent 未被捕获。在< / body> 关闭之前使用异步片段,并且该对象位于中间< body>



(其他一些帖子也引用了jQuery的位置,但这可能是一个红鲱鱼)

非常感谢。

解决方案

From https://developers.google.com/analytics/devguides/collection/gajs/ 此代码会将您现有的传统片段替换为最新的异步版本,您应该移除现有的跟踪代码片段第一。

 < script type =text / javascript> 

var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-XXXXX-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);
})();

< / script>

要查看您的活动进入(要知道这是否正常),请在活动 报告页面左侧的实时菜单选项。


The following message appears when viewing a site page in the chrome debug log.

Uncaught ReferenceError: _gaq is not defined

The page itself is supposed to track an object using the onload event handler and fire a _trackEvent for Google Analytics.

My best guess is that perhaps the ga.js file doesn't load in time and therefore the onload _trackEvent triggered is not caught. the async snippet is being used before the </body> close and the object is positioned in the middle <body>.

(some other posts have referenced jQuery position too but, this might be a red herring)

any assistance greatly appreciated.

解决方案

From https://developers.google.com/analytics/devguides/collection/gajs/ this code replaces your existing "traditional snippet" with the "latest, asynchronous version, you should remove the existing tracking snippet first."

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-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);
  })();

</script>

To see your events come in (to know if this is working) look for "Events" under the "Real-Time" menu option on the left side of the "Reporting" page.

这篇关于Uncaught ReferenceError:_gaq未定义(Google Analytics)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆