-
-
Save andrewheins/2990318 to your computer and use it in GitHub Desktop.
Track PDF files in Google Analytics with jQuery
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
/** | |
* Place this code after your Google Analytics scripts | |
*/ | |
$(function() { | |
/* any links to PDFs are tracked with GA */ | |
$('a[href$="pdf"]').click(function(e){ | |
/* grab only the file name without the full path */ | |
var fullpath = $(this).attr('href'); | |
var filename = fullpath.substr(fullpath.lastIndexOf("/")+1, fullpath.length); | |
_gaq.push(['_trackPageview', '/'+filename]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment