How do I set up Google Analytics to track outbound

2019-09-06 05:38发布

问题:

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>