How to Track Word and PDF Downloads in Google Analytics

By Josh | March 14, 2013 | How To | Online Marketing


Tracing Downloads with Google Analytics

Note: The method outlined below is for use with ga.js tracking code and not for use with the analytics.js tracking code. For details regarding Event Tracking with analytics.js see Google's Documentation.

Straight out of the box, Google Analytics does a great job of tracking your web pages.

Unfortunately, Google Analytics doesn't automatically track file downloads (such as PDFs, Excel spreadsheets, PowerPoint files and Word docs).

The great news is that getting Google Analytics to track downloads doesn't take a whole lot of effort on your end.

To track file downloads we recommend using Google Analytic's Event Tracking.  Let's look at how you can use Event Tracking to begin tracking your own website's downloads today.

The download link

Prerequisites

  1. Basic HTML knowledge: you should understand the basic anatomy of a standard HTML link.
  2. You must be able to edit the HTML of the web page containing the link to your file download.

Let's jump right into an example.

Let's assume we have a PDF I'd like to offer as a free download on our site, and let's say the filename of the offer is RecipesForDogs.pdf.  I want to track how many people download this PDF from our website.

So, to start off, I first create a simple link to my file on one of our web pages.  The link would look something like this:

<a href="/RecipesForDogs.pdf">Download My Great Recipe Book for Dogs</a>

This is just a basic HTML link to the PDF file that's been uploaded to our server. Nothing fancy here.

To start tracking downloads, I'll  need to add what's called an event handler to the link — like so:

<a href="/RecipesForDogs.pdf" onClick="_gaq.push(['_trackEvent', 'Offers', 'Download', 'Dog Recipe Book Offer']);">Download My Great Recipe Book for Dogs</a>

In the above link, I've added an onClick event handler (in bold). This event handler is where I'm asking Google Analytics to track clicks on this link as an Event. 

Don't worry if this seems complicated to you; all you'll need to do is copy the code above and modify a few parts to match your needs.  

Let's look at how you'd do this.

Customizing this code for your own website

First, you'll need to modify the href attribute in the code I've provided so it points to the specific file on your server that you wish to track. (I'm going to take a wild guess and assume you're not trying to track a PDF on your server named RecipesForDogs.pdf.)

Modify the Event Category

After you've got the link pointed at the file you'd like to track downloads for, you'll want to tweak the Category.Category for Event Tracking

In the example above, I categorized the  Recipes for Dogs PDF in an "Offers" category. Especially helpful when you offer many different types downloads on your website (like Ebooks, free reports, questionnaires, etc.), the Categories you choose are what will allow you to logically and intuitively sort through all your downloads data when you review it in Google Analytics.

You can create as many Categories as you'd like and give the Categories any names you like; it's completely custom and based on how you'd like to organize and think about your data.  

Once you figure out what Category you'd like to use for your download, swap that out with my "Offers" Category in my example.

Modify the Event Action

After specifying the Category of your download, you'll next want to configure the ActionAction for Event Tracking

In my example (above), the Action is "Download".  The Action is simply your description of what the user is doing when she clicks this link.

(When tracking downloads, the obvious Action to specify would be "Download", but keep in mind Event Tracking can actually be used to track all types of interactions, including form submissions, videos played, pop-ups clicked, etc.)

Modify the Event Label

Finally, give your download a LabelLabel for Event Tracking

In our example the Label is "Dog Recipe Book Offer". This is just the name that Google Analytics will use when displaying this specific download in its reports. Just as with the Category and Action, it can be whatever works for you.

That's it.Event Menu in Google Analytics

Once this code is live on your site, Google Analytics will automatically track your file downloads. 

To view your results and see if/how your website visitors are downloading your files, just go to Content > Events within Google Analytics. (Make sure to give Google Analytics at least 24 hours to begin tracking and displaying the data after you've tagged your download links).

To learn more about Event Tracking, visit Google's Event Tracking Documentation.

Happy tracking!

Note: The method outlined above is for use with ga.js tracking code and not for use with the analytics.js tracking code. If you're not sure which one you're using, chances are it's the ga.js. For details regarding Event Tracking with analytics.js see Google's Documentation.

 

Want to know when the next blog post comes out?
Get email updates whenever we add fresh content to our blog! Just sign up to receive our blog updates via email now.

Signing up is EASY and FAST (takes 9 seconds).

Sign up to receive our blog updates via email

Comments

Comment from Tom on 05/27/2013
Tom

This is great.  But I am unclear about one thing - can I use event tracking to track downloads of a pdf from an email.  In other words, if i send an email to 400 people, and that email has a link to a pdf download, will the method you suggested in this article work to track how many people download the pdf from the email?  Thanks in advance for any assistance you can provide.

Comment from Josh on 05/29/2013
Josh

@Tom Because Google Analytics needs a web page with the tracking script, this method is not suited to email.

There are a lot of potential solutions, but the simplest thing to do would be send them first to your site and then offer the download using the method outlined here.

You may also want to spend some time looking into Campaign Tags http://analytics.blogspot.com/2009/03/tips-for-tracking-email-marketing.html

Comment from Erin on 06/14/2013
Erin

Hello Eythor,
We’re happy to help troubleshoot if you’d like to setup a consulting call. Please reach out via our contact form and we can take a look for you.
Best,
Erin

Comment from Melanie Rimmer on 06/14/2013
Melanie Rimmer

This was really helpful. I looked on the Google Analytics help pages and several other websites and was still unclear about exactly how to do this, especially how to tailor it to my needs. Your article made everything simple. Thank you.

Comment from Camilla on 07/04/2013
Camilla

Hello and thank you for your pedagogical explanation! But I’m wondering if I have to do the same for every specific pdf I want to measure? Isn’t there a solution for measuring all pdf:s in a library at once? But it’s important that I still can see the statistics for each pdf? Thank you!

Comment from Josh on 07/05/2013
Josh

@Camilla If you’d like to automatically track downloads, you can do so with some jQuery. If that’s too advanced, you can check out a service like Analytics Engine http://www.analyticsengine.net/  They offer a free plan.

Comment from Carver on 07/11/2013
Carver

Hey I’m trying to get PDF tracking on analytics but am having difficulty and can’t see why. Here’s an example of what I have been using, this is exactly how it looks:

<li><a href=”/pdfs/CANS-Trauma-Comprehensive-Manual-3-22-13.pdf”  target=“_blank”> CANS-Trauma Comprehensive Manual and Scoring Sheet</a></li>

Under in event conditions in goal setup, I have Category set to regular expression and typed in Download, Action set to regular expression and typed in PDF and lastly Label set to regular expression and typed in this.href.

Am I filling in the wrong information there?

Comment from Josh on 07/11/2013
Josh

@Carver Be sure to review the examples.  Your link is missing the onClick, and you definitely need that.

Comment from Hutt on 07/11/2013
Hutt

Hey, thanks for the tutorial! I put the code in my link, but do I have to add anything manually to the google analytics page? Or does the link automatically push the category and description (looked like it did)? Thanks!

Comment from Josh on 07/11/2013
Josh

@Hutt The event handler tells Analytics everything. There’s nothing that you need to do in Analytics.

Comment from Carver on 07/17/2013
Carver

Whoops, I pasted the wrong text here earlier.

THIS is exactly how it looks (what I meant to post earlier):

<li> CANS-Trauma Comprehensive Manual and Scoring Sheet</li>

Based off your last response to Hutt, you’re saying the ONLY thing we have to do to track PDF’s in Analytics is add this code to the link? Nothing else?

Either way the code I’ve posted correctly here is what I’ve had on the <a> tags since I last posted the incorrect code here and it still has not been tracking anything.

Comment from Erin on 07/19/2013
Erin

Hi Carver,
I’m sorry, we don’t see the onClick event in your code?

Comment from Rob on 07/31/2013
Rob

PDF download tracking is showing in the Events, but it’s not showing on the In-Page Analytics.

Does anyone else have this problem?

Comment from Louis on 09/13/2013
Louis

Thank you for this tip!

Unfortunately, it does not work for me… In GA I don’t see anything in the events… And I’m waiting for since a couple of days now…

This is the kind of link I use:
<font color=“green”>Click here</font>

Comment from Erin on 09/13/2013
Erin

@Louis - You’ve not included the event handler in your code as displayed in the example above. It looks like you’ve just written a normal link.  If you duplicate and tweak the code we’ve provided, it should work for you.

Comment from Darren Patrick on 09/19/2013
Darren Patrick

Thanks very much Josh!

I followed your example to the T and then when I clicked update on my page, the HTML changed to…

http://THE LOCATION OF MY IMAGE...

I can no longer see the CATEGORY, ACTION and LABEL items you’ve indicated above.  Did it get truncated and that’s OK?

Comment from Erin on 09/24/2013
Erin

@Darren - we can’t know for sure without knowing a lot of details about your situation. It’s might have something to do with the web/wysiwyg editor you’re using. Just remember that when you view your code, it should look *exactly* like Josh’s code, otherwise it will not work.

Comment from Meg on 09/30/2013
Meg

I put in the event tracking code for multiple PDFs last week and I am still showing no information under events in Google Analytics. Here is my code:

<textarea><a href=“pdfs/Adoption/Bios/aaron&ritabio;.pdf” target=“_blank”>Aaron & Rita</a></textarea>

Can you tell me if I am doing something wrong? Thanks!

Comment from Jeff on 10/07/2013
Jeff

If i hypothetically wanted to track pdf downloads from my site but the link to the pdf was from an image would that work? example as best as my limited html knowledge allows:

<textarea><a href=”/RecipesForDogs.pdf”>images/DogRecipeCover.jpg</a></textarea>

also, two possible rookie questions:
1. If a viewer right clicks and downloads the PDF, or the viewer clicks and opens the pdf in a browser window, is that both considered the same event according to Google Analytics?

2. I was lead to believe that the links to the PDF should be universal links not relative links:
1. a href=”/RecipesForDogs.pdf”
vs.
a href=“www.website.com/PDFs/RecipesForDogs.pdf”
does that not matter?

I really appreciate any help. thanks
(working for small non-profit helping foster kids!!!!!)

Comment from Sama on 10/11/2013
Sama

This was very clear and helpful. Thank you!

Comment from Erin on 10/11/2013
Erin

@Meg - It looks like you wrote a standard link and didn’t use our code.

Comment from Erin on 10/11/2013
Erin

@jeff - 1) links from text and links from images are no different.  2) yes 3) no   Hope that helps!

Comment from Anto on 10/24/2013
Anto

_gaq is undefined with the new Google analytics code.

This is what Google tells me to insert, are you deliberately using the old style code to embed tracking? and what advantages do you get (apart from this quick _gaq way to tracking)?

Thanks
Anto

Comment from Josh on 10/24/2013
Josh

@Anto This post was written prior to the release of analytics.js.  So the new method wasn’t something that was available at the time.  The method you use is determined by which tracking code you have installed.

Event tracking documentation for analytics.js can be found here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Hope that helps.

Comment from Gerd on 10/30/2013
Gerd

I included the code as follows but still don’t get any results:

Auftragsforschung

or are there changes with release of analytics.js, so this code isn’t valid anymore?

Cheers,
Gerd

Comment from Donald on 11/07/2013
Donald

Hi Josh,
really cool and straight to the point guide about tracking the downloads. Thanks for writing. I set up now the link, I will see what happens tomorow when analytic will start to display the results. Ciao!

Comment from Josh on 11/08/2013
Josh

@Gerd methods for tracking downloads have changed since the introduction of analytics.js.  I suggest you review Google’s documentation https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Comments are for this post are closed.

|

< RETURN TO BLOG MAIN PAGE