Created
March 4, 2014 21:36
-
-
Save NathanQ/9356297 to your computer and use it in GitHub Desktop.
Javascript to track file downloads on Google analytics. This example takes a pdf link click and pushes the event to analytics with it's url. The setTimeout is there to give it a bit of time for the event tracking to occur before beginning the file download.
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
$(document).ready(function() { | |
$("a[href$='pdf']").click(function(event){ | |
var href = $(this).attr('href'); | |
_gaq.push(['_trackEvent', 'Downloads', 'File Downloaded', href]); | |
setTimeout(function() { window.location.href = href; }, 500 ); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment