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

问题描述

有点困惑...我试图跟踪被点击的 mailto 链接,但不断显示pageTracker 未定义".我在结束正文标记之前有以下代码 ()

Little bit confused... I am trying to track mailto links being clicked, but constantly 'pageTracker is not defined' is shown. I have the following code just before my end body tag ()

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-000000']); // This is my account number, I have added the zeros in this editor
  _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>

然后我在我的mailto链接中使用它

Then I am using this in my mailto links

<a href="mailto:[email protected]" onClick="javascript:pageTracker._trackPageview('/mailto/hello');">[email protected]</a>

我不明白为什么它不起作用?任何帮助将不胜感激

I cannot see why its not working? Any help would be appreciated

推荐答案

新的 Async Google Analytics 代码(您正在使用)与非 Async 代码的工作方式略有不同.任何时候您想调用 pageTracker 上的方法时,您只需将消息"推送到_gaq"队列即可.

The new Async Google Analytics code (that you're using) works a bit differently than the non-Async. Any time that you want to call a method on pageTracker you simply push a "message" onto the "_gaq" queue.

<a href="mailto:[email protected]" onClick="_gaq.push(['_trackPageview', '/mailto/hello'])">[email protected]</a>

虽然,跟踪 mailto 链接可能更适合作为事件:

Although, tracking a mailto link may work better as an event:

<a href="mailto:[email protected]" onClick="_gaq.push(['_trackEvent', 'mailto', 'home'])">[email protected]</a>

有关详细信息,请查看异步跟踪用户指南.

For more info take a look at the Async Tracking Users Guide.

这篇关于未定义 Google Analytics pageTracker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!