如何跟踪出站链接的点击次数 [英] How to track clicks on outbound links

查看:27
本文介绍了如何跟踪出站链接的点击次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[cross-posted on Google Products Forum http://productforums.google.com/d/topic/analytics/ZrB14a-6gqI/discussion ]

我在 http://www.cs.bris 使用以下代码.ac.uk/Research/算法/

<script type="text/javascript">

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

我直接从 http://support.google.com/analytics/bin/answer.py?hl=zh-CN&answer=1136920 .

但是,它实际上似乎并没有报告我添加的链接的任何点击onClick="recordOutboundLink(this, 'Outbound Links', 'Postdoc advert');return false;" 例如.我在网上看到了许多关于此问题的投诉,但我还没有找到有效的解决方案.

However, it doesn't actually seem to report any clicks on the links where I have added onClick="recordOutboundLink(this, 'Outbound Links', 'Postdoc advert');return false;", for example. I have seen a number of complaints about this online but I haven't found a solution that works.

我做错了什么?

附言最相关的在线投诉似乎是 http://productforums.google.com/forum/#!topic/analytics/4oPBJEoZ8s4 只是声称代码已损坏.

P.S. The closest related online complaint seems to be http://productforums.google.com/forum/#!topic/analytics/4oPBJEoZ8s4 which just claims the code is broken.

推荐答案

这是我正在使用的,对我有用.我正在使用 jQuery 将 onclick 处理程序添加到具有引用"类的任何链接,但我希望将它直接添加到 HTML 中也能正常工作.

Here's what I'm using, which has been working for me. I'm using jQuery to add the onclick handler to any link with a class of "referral", but I'd expect adding it directly in the HTML to work as well.

  $(function() {
    $('.referral').click(function() {
      _gaq.push(['_trackEvent', 'Referral', 'Click', this.href]);
      setTimeout('document.location = "' + this.href + '"', 100);
      return false;
    });
  });

<小时>

我相信您按名称调用跟踪器的语法是错误的.由于您在页面加载时设置跟踪时没有使用命名跟踪器,因此您也不应该稍后尝试命名它.请参阅_gaq.push.

更准确地说:

  1. var myTracker 声明未使用,因此您可以删除该行.在 recordOutboundLink 范围内声明的变量在其他函数(例如 _gaq.push)运行时不可见,因此不能相关.
  2. 您应该简单地使用 '_trackEvent' 而不是 'myTracker._trackEvent'.
  1. The var myTracker declaration is unused, so you can just delete that line. Variables declared within the scope of recordOutboundLink aren't visible when other functions, such as _gaq.push, are running, so it can't be relevant.
  2. You should simply use '_trackEvent' instead of 'myTracker._trackEvent'.

这篇关于如何跟踪出站链接的点击次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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