Analytics and Search Marketing Tips
Out of the box, Google Analytics will not track how many times people download PDFs or other file types, simply because those files do not have the ability to request a tracking pixel. In this blog post, we’ll be covering the ways to properly track file downloads in Google Analytics.
Throughout this blog post, I’ll be assuming that you are wanting to track a PDF download, but keep in mind that you could use this same technique to track the download of a .mp3, .mp4, .xlsx, etc — it really does not matter. Additionally, I recommend tracking file downloads as events (so that you are not inflating pageviews on your site), but you could very well track them as pageviews. In the new Google Analytics v5, you can now setup events as goals!
The code you will want to use is different depending on if you are opening the PDF in a new window via target=”_blank” or if you are opening the PDF in the current window.
If you are linking to a PDF that opens in a new window (by using target=”_blank” for example), then the tracking code is fairly simple to implement.
Your link will look something like: <a href=”pdfs/my-file.pdf” target=”_blank”>Download my file</a>
To properly track this in GA, add the following code to link tag:
When a user clicks to download your file, a tracking pixel is requested and recorded in GA’s database. Problem solved!
If you do not use the link tag’s target attribute to open the PDF in a new window and instead you have it opening in the same window, some browsers will interrupt the tracking request and send the visitor straight to the download. When this happens, you won’t see the event recorded in GA.
Your link will look something like: <a href=”pdfs/my-file.pdf”>Download my file</a>
To properly track this in GA, add the following code to the link tag:
If you have a lot of file links on your site or you just don’t want to have to worry about adding this code each time you add a new link, then you can certainly automate the tagging for download tracking.
There are a number of solutions that help you do this and that also provide additional automated tracking functionality. One of our favorites is Analytics Engine, which is developed by our friends at Analytics Pros (a fellow Google Analytics Certified Partner). Definitely check out their product to learn more.
Feel free to customize this code. It can be placed in its own .js file and should be placed in the <head> on each of your pages. This script automates the following:
The script detects to see if you are opening the file in a new window or not and automatically uses setTimeout() for 200ms if you are not. If you have multiple tracking objects on a page or have a named tracker, then you’ll want to customize this script. This script uses the asynchronous ga.js tagging syntax.
When you fire event tracking or a virtual pageview, this will impact your bounce metric in a positive direction. Events and pageviews count as an interaction. If you have more than one interaction (pageview or event), then that visit is not counted as a bounce. Since the visitor took some action on the site, they should not be counted as a bounce anyways, so by coding your file download links, you are actually increasing the accuracy of your metrics.
Share this Post
Digital Analytics Blog
We're here to help with tips and insight on the following topics:
Optimize your website and marketing campaigns