How do I set up Google Analytics to track outbound links? The official example doesn't work [duplicate]

橙三吉。 提交于 2020-01-06 19:42:18

问题


Possible Duplicate:
How to track clicks on outbound links

As described in the official documentation I have included this piece of code in my <head> section:

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

And have changed the link to this:

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

However still no events are shown up in the reports.

What am I doing wrong?


回答1:


The code in the Google Analytics documentation is incorrect. The code in the <head> section should be

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


来源:https://stackoverflow.com/questions/13339736/how-do-i-set-up-google-analytics-to-track-outbound-links-the-official-example-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!