Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created September 21, 2011 09:35
Show Gist options
  • Save maxcal/1231659 to your computer and use it in GitHub Desktop.
Save maxcal/1231659 to your computer and use it in GitHub Desktop.
PDF test regex
jQuery.ready(function($){
// Check for PDF links
$('a').each(function(){
var pdfExt = /\.pdf$/i;
var href = $(this).attr('href');
if ( pdfExt.test(href)) {
$(this).addClass('pdf');
}
});
// Google track PDFs
$('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 abs
absolute_url = (function(url, base_url){
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]);
});
});
@maxcal
Copy link
Author

maxcal commented Sep 22, 2011

Updated with hook to auto register urls ending with PDF

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