Created
September 20, 2011 23:20
-
-
Save maxcal/1230720 to your computer and use it in GitHub Desktop.
Hacktastic Google Analyticts PDF tracking
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
// Catch present and future links | |
jQuery('a.pdf').live('click', function($){ | |
var base_url, absolute_url; | |
// test for P3 env variable resources.baseurl | |
base_url = resources.baseurl || "http://www.greenpeace.org/international/"; | |
// Self-Invoking Function - returns url with path | |
absolute_url = (function(url, base_url){ | |
// If href starts with slash we assume it is relative to resources.baseurl | |
if (url.charAt(0) === '/') { | |
url = base_url + url.substr(1); | |
} | |
return url; | |
}( $(this).attr('href'), base_url)); | |
// Push it too ye old google | |
_gaq.push(['_trackPageview', absolute_url]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment