So I’ve taken the code and modified it a little to make it just for
file downloads, and to cover more file extensions that the original.
This will track the following file types:

  • PDF (.pdf)
  • Microsoft Word (.doc)
  • Microsoft Excel (.xls)
  • Microsoft PowerPoint (.ppt)
  • Microsoft Visio (.vsd)
  • Microsoft Visio XML (.vxd)
  • ZIP Archive(.zip)
  • RAR Archive (.rar)
  • Text file (.txt)
  • Downloadable Javascript file (.js)
  • Downloadable CSS file (.css)
  • Executable (.exe)
  • NEW Windows Media Audio (.wma)
  • NEW Quicktime (.mov)
  • NEW Audio Video Interleave (.avi)
  • NEW Windows Media Video (.wmv)
  • NEW Mpeg Layer-3 (.mp3)

The result – some unobtrusive javascript, to use simply download the js file,
place it somewhere on your webserver and paste the following code
directly above your standard Google Analytics tracking code (which by
the way, should be as near the end of the <body> tag as possible).

<script src=”/js/taglinks.js” type=”text/javascript”></script>

(Don’t forget to replace the ‘/js/taglinks.js’ with the correct path to the javascript file)

Hey presto you’ve now got tracking for all downloadable files!

UPDATE: I’ve update the Javascript so it won’t
throw a wobbly if there are anchor links on the page, also some new
file types have been added (see above).

UPDATE: The script now tracks external links as well as document downloads.