如何设置Google Analytics以跟踪出站链接?官方的例子不起作用

时间:2012-11-12 07:27:14

标签: javascript google-analytics

  

可能重复:
  How to track clicks on outbound links

the official documentation中所述,我在<head>部分中包含了这段代码:

<script type="text/javascript">
  function recordOutboundLink(link, category, action) {
    try {
      var myTracker=_gat._getTrackerByName();
      _gaq.push(['myTracker._trackEvent', category , action ]);
      setTimeout('document.location = "' + link.href + '"', 100)
    }catch(err){}
  }
</script>

并改变了与此相关的链接:

<a href="http://www.example.com" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;">

但报告中仍未显示任何事件。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

Google Analytics文档中的代码不正确。 <head>部分中的代码应为

<script type="text/javascript">
  function recordOutboundLink(link, category, action) {
    try {
      _gaq.push(['_trackEvent', category , action ]);
      setTimeout('document.location = "' + link.href + '"', 100)
    }catch(err){}
  }
</script>