Using MooTools to Instruct Google Analytics to Track Outbound Links

Google Analytics provides a wealth of information about who's coming to your website. One of the most important statistics the service provides is the referrer statistic -- you've gotta know who's sending people to your website, right? What about where you send others though? Using MooTools 1.2, you can direct Google Analytics' pageTracker to track outbound link clicks.

The MooTools 1.2 JavaScript

//google analytics code var pageTracker = _gat._getTracker("UA-#######-#"); pageTracker._trackPageview(); //moo code window.addEvent('load', function() { if(pageTracker) { $$('a[href^=http]').each(function(el) { el.addEvent('click',function() { var dd = '/outgoing/' + el.get('href').replace('http://',''); pageTracker._trackPageview(dd); }.bind(this)); }); } });

Here's what you would see on your "Top Exit Pages" within Google Analytics:

Excellent! Who knew it would be so easy?