Created
September 12, 2011 15:45
-
-
Save neopunisher/1211594 to your computer and use it in GitHub Desktop.
Google analytics event tracking w/ jQuery
This file contains hidden or 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
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]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.