Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created September 20, 2011 23:20
Show Gist options
  • Save maxcal/1230720 to your computer and use it in GitHub Desktop.
Save maxcal/1230720 to your computer and use it in GitHub Desktop.
Hacktastic Google Analyticts PDF tracking
// 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