Google Analytics Moo-ized

by keif on October 14, 2008

As both David Walsh and I wrote about Google Analytics Tracking utilizing Mootools to make your outbound link tracking easier, and David did setup a variable for the Google Tracking code *before* we run the code to tag our outbound links.

Upon second review, it’s a little different than the modified code I presented yesterday, but I dig using the href replacement on your outgoing string.

Here’s the updated code:
[sourcecode language=’javascript’]
// Double-checking in case your drop this site wide
// Do anchors exist on the page?
if ($$(‘a’)){
var href = anchor.get(‘href’);
// if it matches my site or is an absolute path it’s outgoing
if(href.indexOf(‘’) == -1 && href.indexOf(‘/’) !== 0) {
anchor.addEvent(‘click’, function(e){
var track = “pageTracker._trackPageview(‘/outgoing/'” + href.replace(‘http://’,”);

  • Lim Chee Aun

    I’m seeing lots of HTML ampersand codes in the code example :) And uh, I think var anchors = $$('a[href]'); would be better.

Previous post:

Next post: