Friday, 06 February 2015 19:58

Tracking PDF Downloads with Google Tag Manager

Written by

Use Google Tag Manager's new user interface to track PDF Downloads

The new version of Google Tag Manager is a lot easier to work with no more triggers, listeners and rules.  They are all combined into triggers.  Two of our favorite Tags we setup in the old version of Google Tag Manager were tags to track PDF downloads and tags to track outbound links.  We will step through how to setup each of these in the new user interface for Google Tag Manager.

Setup Variables

First out of the gate we want to setup a tag in Google Tag Manager (GTM) that fires Google Analytics Event when a user on our website clicks on a PDF link.  To begin this setup we will login to GTM and within your container open up the Variables tab. Now turn on the Click Variable ""Click URL"" and ""Click Text"".  The ""Click URL"" is the Variable we will be using to identify a click on a PDF link in our trigger.  And we will use the ""Click Text"" variable for building our Google Analytics Event Tag.  (The ""Click Element"" could be used instead of ""Click URL"" my preference is for ""Click URL"", let me know your thoughts on this.)

GoogleTagManager PDFDownload SelectVariables 480x360

Create a PDF Link Click Trigger

Next we need to set up our Link Click Trigger this way to track PDF downloads.  First select Create a Trigger Select the 'Click' trigger from the type and then specify a 'Link Click'.  This creates code that will listen for when users click on a link, next we will tell the trigger to fire when the link is to a PDF file.  We do this by setting up a rule: Click URL matches RegEx (ignore case) \.pdf$ Let's break this trigger down, we want it to fire when our click URL ends with the characters "".pdf"".  We do this by selecting the ""click URL"" variable.  Next we choose to match using a regular expression and be cause we want to track files names regardless of whether or not there are capitals we select ""matches RegEx (ignore case)"".  Finally we create our regular expression - "\.pdf$" is the text we want to match in our Click URL - because "." is a special character in regular expressions we have to escape it with the "\" character.  And then to wrap it up we use the ""$"" character to indicate that the match should come at the end of the URL.  

To learn more about regular expressions check out this tutorial website -

GoogleTagManager PDFTrigger 480x300

Build a PDF Universal Analytics Event Tag

OK now we have a trigger for the PDF download, now we need a GA event tag to complete our task.  So we create a new tag - select GA, then Universal Analytics , insert our UA code and then select event.  For the event we set the category to PDF, action to download and the value to the {{Click Text}}.  Select our PDF Download Trigger and we are ready to test!  It will look like this: You can do this by turning on the Preview/Debug mode in GTM and then click on a PDF on your website.  When it works you will see this in the debug area on your browser: Publish your new version of the container and congratulations you are tracking PDF downloads on your website.  (If this is not working check for typos in the regular expressions or links that do not end in "".pdf"" to start.)

GoogleTagManager PDFDownload EventTag 480x590

Read 42938 times Last modified on Monday, 25 November 2019 14:15
Jay Murphy

Jay Murphy is a digital analytics expert and founder of Trionia, where he specializes in transforming data into actionable insights for large and mid-sized businesses. With over thirty years of experience and a passion for Google Analytics since its inception, Jay has honed his skills to bridge the gap between technical data analysis and strategic business planning. An educator at heart, he has developed and taught comprehensive digital marketing courses at both the undergraduate level and within organizations, enriching minds with his deep understanding of the digital analytics landscape.

His career, which began in systems analysis for spacecraft guidance, has evolved through roles that blend technical acumen with strategic vision across various sectors, including Fortune 500, Higher Education and Non-Profits. Certified in Google Analytics since 2011, Jay's leadership at Trionia has spearheaded successful online campaigns and innovative marketing strategies, underlining his commitment to leveraging data for growth. Jay's approach goes beyond the numbers; he's a storyteller who uses data to drive business success, making him a pivotal figure in the digital marketing world.

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.