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

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

问题描述

在 Chrome 调试日志中查看站点页面时会出现以下消息.

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

未捕获的引用错误:_gaq 未定义

Uncaught ReferenceError: _gaq is not defined

页面本身应该使用 onload 事件处理程序跟踪对象,并为 Google Analytics 触发 _trackEvent.

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

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

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>.

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

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

非常感谢任何帮助.

推荐答案

来自 https://developers.google.com/analytics/devguides/collection/gajs/ 此代码将您现有的传统代码段"替换为最新的异步版本,您应该先删除现有的跟踪代码段".

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.

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

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