Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Track PDF files in Google Analytics with jQuery
* Place this code after your Google Analytics scripts
$(function() {
/* any links to PDFs are tracked with GA */
/* grab only the file name without the extension */
var fullpath = $(this).attr('href');
var filename = fullpath.substr(fullpath.lastIndexOf("/")+1, fullpath.length);
_gaq.push(['_trackPageview', '/'+filename]);
Copy link

Some quick-and-dirty jQuery code that tracks clicks on PDF files using Google Analytics. —BD

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