Google Analytics中未跟踪自定义事件

时间:2012-07-03 14:47:50

标签: javascript events google-analytics event-tracking

以下是我正在使用的脚本,直接从Google复制:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-CODE']);
  _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);
  })();

    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.website.com/" target="_blank" class="ad" onClick="recordOutboundLink(this, 'Outbound Links', 'Visited website.com');return false;"></a>

但过去3天我的活动报告中没有显示任何内容。我的代码有问题吗?

1 个答案:

答案 0 :(得分:1)

Google's Outbound links tracking example

存在问题

假设您只使用一个跟踪器(在您的代码中看起来像这样),以下内容将起作用:

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