Skip to content

Instantly share code, notes, and snippets.

@neopunisher
Created September 12, 2011 15:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neopunisher/1211594 to your computer and use it in GitHub Desktop.
Save neopunisher/1211594 to your computer and use it in GitHub Desktop.
Google analytics event tracking w/ jQuery
jQuery(function(){
jQuery('a[href$=".pdf"]').click(function(){
_gat._getTrackerByName()._trackEvent('Download', 'Pdf', this.href);
setTimeout('document.location = "' + this.href + '"', 100);
return false
});
jQuery('a[href$=".exe"]').click(function(){
_gat._getTrackerByName()._trackEvent('Download', 'Exe', this.href);
setTimeout('document.location = "' + this.href + '"', 100);
return false
});
jQuery('a[href^="mailto:"]').click(function(){
_gat._getTrackerByName()._trackEvent('Contact', 'Email', this.href);
setTimeout('document.location = "' + this.href + '"', 100);
return false
});
});
//https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
_gaq.push(['_trackSocial', network, socialAction, opt_target, opt_pagePath]);
@dtex
Copy link

dtex commented Sep 15, 2011

Noticed that if there are files with uppercase in the extensions they will be missed (string comparison is case sensitive). Shouldn't happen too often, but it could.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment