Analytics - Tag Manager

How To: Track PDF Downloads in Analytics Using Google Tag Manager

By Dave Ashworth on 12th August 2019

Reading Time: 4 minutes

  • LinkedIn
  • Twitter
Source Code

Most websites have resources which can be downloaded, and in most cases, website owners and/or marketing teams want to know which are being downloaded and how often – particularly if these are part of a marketing campaign or similar.   However, by default, most websites don’t allow you track downloads by default.

Plugins may be available to assist with this, or you can ask your developers to add this functionality, or you can do it yourself if Google Tag Manager is installed on your site.  

This guide assumes that it is, and if it’s not then you ought to get it installed because once you do it gives you control over a whole range of advanced website tracking and extended site functionality configurations.

When you’re ready, follow these steps:

1) Configure built-in variables for Clicks

Built-in variables are available for many of the most commonly used tag and trigger configurations which allow you to interrogate the data layer based on user activity.   In this case, you can elicit data based on what a user clicks on a page as follows:

Click Variables

This allows you to create triggers based on anything the user clicks on, beyond just links, and then use the data from that element to track the activity via a tag.

By default, these variables are not available, so click on “Variables” on the left hand GTM menu, then scroll through and tick the required variables you may as well click all of them whilst your here).         

2) Create Custom Variable For Account ID

This step is optional but would always recommend you create a custom variable to store your Google Analytics Account ID – so basically you don’t have to remember what it is each time you want to track something into analytics. 

To do this, click “Variables” and scroll down to “User-Defined Variables”.  Select the “Variable Type” of “Google Analytics Settings” and paste in your unique tracking ID:

Variable Configuration

3) Create A Tag To Track An Event

Now the variables are available, we can use them to track and collect data when a PDF link is clicked.   Create the tag by clicking “Tags” then “New” then choose the tag type “Google Analytics: Universal Analytics” and configure as follows:

Tag Coniguration

Use naming conventions that best suit your requirements – the above will allow you to track all downloads in one category, that can be further split via the action – in this case PDF – but for other file types can be set to DOC or XLS etc.  

By setting the Label to the build in variable {{Click Text}} the label will automatically by set to the anchor text used to link to the download.  

It may be that you have files with different names use the same anchor text across multiple pages such as “Product User Guide” or “Click Here To Download”, so it may be preferable to set the label to {{Click URL}} so that this value is unique and therefore easier to determine which resource was downloaded.

Set “Google Analytics Settings” to your tracking ID variable.

4) Create A Trigger Based On Link Clicks

You then need to configure a trigger that will fire when a user clicks on a relevant link on your site.  To do this, add a new trigger and select the type “Just Links” under “Clicks”.

Set this to fire on “Some Link Clicks” then set the conditions to “Click URL” – “Contains” – “.pdf”.  Replace .pdf with the relevant file extension you wish to track.

Trigger Configuration

Then associate the trigger with the tag, save, then you’re ready to test.

5) Test in Preview Mode

No matter how many times in the past you have successfully created a working tag / trigger combination, you should always go into preview mode and test.   If the above has been configured correctly, you should be able to see your downloads track in real time events within your GA account:

6) Publish

Once you’re happy that everything is tracking correctly, publish your changes to make them live and impress your marketing team with their new found ability to quickly and easily track user activity on your website.

I hope the above steps are clear / helpful, but if get stuck or have any questions on how to implement this sort of thing (or similar) then feel free to get in touch, am always happy to help and answer any questions you may have.

Get In Touch

Fill in the form below if you want to enhance your website's organic visibility