Using Google Analytics to track file downloads

4 April 2009

I have been using Google Analytics on my websites for a long time now, but only a couple of days ago did  find out that it can track file downloads as well as page views.

The Google Analytics code can be obtained from

You will need to create an account if you don't already have one, and then install the analytics code by the instructions given.

The analytics will only work if JavaScript is turned on by the website visitor's web browser. If it is turned off then you will get no analytical data.

Page view analytics data is installed by placing the JavaScript code at the bottom of every page on your website. This can be done quickly if you are using a footer include or a common file on every page.

If you want to track a certain file, however, you must give the link to the file an "onclick" event.

The "onclick" event is "javascript: pageTracker._trackPageview('/file_path/file_name')" and the analytics will show whatever you chose to call the file (it may not even be the same name as the file - although that is advised so you don't get confused later).

Another thing to note is that the file download analytics can only be recorded if you're using the newer version of the Google Analytics code on your website.

See Google for full instructions -

Please leave a comment using the form provided.