Created
May 12, 2010 11:58
-
-
Save dmolsen/398492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
$('#jqt').ajaxComplete(function(){ | |
add_ga(); // add google analytics on each page load | |
}); | |
$(document).ready(function() { | |
add_ga(); // add google analytics to the first page | |
}); | |
function add_ga() { | |
$('a').each(function(){ | |
if (!$(this).hasClass('ga')) { | |
if ($(this).attr('data-ga')) { | |
//$(this).click(function(){console.log('had data ga click 2');}); | |
$(this).click(function(){pageTracker._trackPageview($(this).attr('data-ga'))}); | |
$(this).addClass('ga'); | |
} else { | |
if ($(this).attr('href') == '#') { | |
//$(this).click(function(){console.log('back button 2');}); | |
$(this).click(function(){pageTracker._trackPageview('/'+$(this).attr('href')/+'/')}); | |
$(this).addClass('ga'); | |
} else { | |
//$(this).click(function(){console.log('internal link 2');}); | |
$(this).click(function(){pageTracker._trackPageview($(this).attr('href'))}); | |
$(this).addClass('ga'); | |
} | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adds an onclick handler to all links without a class of ga in a jQTouch project. Will also add to any new regions added by AJAX. There is a bug somewhere as I have a NaN in Google Analytics results but mainly it appears to work.