task Tracking File Downloads and External Links with Google Analytics
Google Analytics is pretty robust. Out of the box, it provides most of the stats that website owners and administrators need to understand how much their site is being used, how it's being, by who, when, and from where. The one thing it doesn't do automatically though, is track file downloads -- downloads of files such as PDFs, PowerPoints, Word Docs, MP3s etc. It only tracks the loading of webpages by default.
We work with nonprofit clients that provide a lot of content via PDFs, such as reports, policy briefs, fact sheets, infographics and more. Getting a complete understanding of how much their resources are being used for the sake of ROI analysis and more, requires that we capture data about usage of these files too. Our current approach to satisfy this need is to use Google Analytics event tracking, which allows us to record specific actions users take on our websites -- such as clicking buttons, playing videos etc. And for this specific need, what we track are clicks on links that lead to specific files (e.g, links that go to PDF files).
One of our implementations uses the code below. It's a revised version of code presented on blastam.com from 2013 that required revision in order to work with the lastest Google Analytics tracking code (i.e., analytics.js instead of the legacy ga.js). Our revised version tracks file downloads for any of the specified file types, as well as links to external websites. Note that it requires jQuery and assumes that you have the Google Analytics tracking code installed on your site.
It's important to note that tracking clicks on links to PDF documents and other files is, at best, a proxy for actual file downloads. The technique will miss downloads that don't occur on the website. For example, the solution we present below won't capture the following:
- Users that find a direct link to the PDF/file from a third-party website (including Google)
- Users that click on a direct link to the PDF/file within an email
- Users that download the file via a direct bookmark to the file.
In order to capture those direct downloads as well, you would need to consider doing something like server log analysis.