Monday, April 11, 2011

Google Analytics stats for pdf download

Did you ever wondered how to track the number of times a pdf file is downloaded from your web site using Google Analytics?

This javasript code snippet will do it for you.

This javascript code snippet will allow you to follow up the number of downloads for a pdf file.
It is JQuery based, so you must have the JQuery library included to call up this function.
The function is triggered each time some one clicks on your link to donwload the pdf file.

How to do it

1. In your link tag insert the class="pdf" attribute
<a href="" class="pdf">

2. Copy/Paste this function in your HTML or javascript source code file

// alert("Yu've clicked on a pdf file");
var documentName = $(this).attr("href");

3. It will track on the event 'Download' automatically.

The class="pdf" attribute in the href tag is very important as it makes the function work

That's it!


Post a Comment

Your opinion is very appreciated, thank you!