Skip to content

Instantly share code, notes, and snippets.

@sivagao
Created July 18, 2013 22:57
Show Gist options
  • Save sivagao/6033822 to your computer and use it in GitHub Desktop.
Save sivagao/6033822 to your computer and use it in GitHub Desktop.
using google analytics to track|log your page action|event. http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/ todo: understand what ga do in default..
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'type='text/javascript'%3E%3C/script%3E"));
var pageTracker = _gat._getTracker("YOUR ACCOUNT NUMBER HERE"); pageTracker._trackPageview();
$(document).ready(function(){
$('a[data*="track"]').click(function(){
pageTracker._trackPageview('click_link/'+$(this).attr('href'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment