By default, Google Analytics doesn’t track PDF documents on a website. This is due to JavaScript not being loaded when viewing a PDF document in a browser or downloading it to your device. So to get around this, we’ll put an action listener on the hyperlink that connects to the PDF document. 

What you’ll need:

  • Access to your websites Google Tag Manager.
  • Google Tag Manager already installed on your website.
  • Google Tag Manager connected to your Google Analytics Account

If you’re are not using Google Tag Manager but are still looking to track PDF files with Google Analytics, check out my other post that uses JavaScript.

Step 1 – Enabling Click URL

First thing we need to do is enable Click URL in Google Tag Manager. Many variables are not enabled by default in GTM such as this one. There is a possibility that it is already enabled in your account. 

Log into GTM and click on variables in the left hand navigation. Under “Built-In Variables”, look at the list and see if you have “Click URL”. If so then you can skip to Step 2. If not then click on the “Configure” button, and find “Click URL” under the Clicks sub-heading. Enable it.

Step 2 – Create the Tag

Start by click on the “Tag” in the navigation and click on “New”. For the “Tag Type” click on “Google Analytics – Universal Analytics”.  The rest of the options will go as:

  • Track Type: Event
  • Category: “Resource Download” (you can actually put whatever you would like as a category)
  • Action: “PDF Download” (again you can actually put whatever you would like as an action)
  • Label: {{Click Text}}
  • Non-Interaction Hit: True
  • Google Analytics Settings: {{variable you already setup}} (you should already have Google Analytics setup and in a variable, choose the variable)

Step 3 – Continuing Setup

Click on the triggering section to add a new trigger. Choose a new trigger and the type should be “Just Links”. The trigger should fire on “Some Link Clicks” and the settings should be set to “Click URL” “contains” “.pdf”

Step 4 – Publish

You all set to save everything and Publish your new tag. 

When your in Google Analytics, you’ll see the new items under “Behavior” – “Events”. The category will be whatever you setup, this example used “Resource Download”. The action will also be whatever you setup, this example used “PDF Download”. And the labels will be whatever the text is in the hyperlink. 

Authors Note: Although we setup to track PDF documents, you can also setup other extensions to track such as .doc, .mp3 or any other file types you might be hosting on your website.


Blog Author Jonathan Volks

About Jonathan Volks

Jon has over 10 years of both front-end and back-end web programming and development. Currently he is a Senior Web Programmer at Skidmore College maintaing the marketing website. In his free time he enjoys hiking in the Adirondacks, hockey games with the Adirondack Thunder, and creating outragious fan theories about Westworld. Calling it right now, Stubbs is a host with Teddy's memories.

By default, Google Analytics is unable to track PDF documents. This is due to PDF’s not being able to run JavaScript code when viewed in a browser (or downloaded).  So to get around this, we can add a little bit of code to the website in order for PDFs to show up in Google Analytics.

What you’ll need:

  • Access to your JavaScript file.
  • Familiarity with JavaScript and adding code to it.
  • jQuery

In your JavaScript code, add the following:

So what’s going on here? Essentially this code loops through all the <a> tags that contain “pdf”. Then adds a Google Custom Event code to that link tag. When a user clicks on the link, an event push is sent to Google Analytics to track.


Blog Author Jonathan Volks

About Jonathan Volks

Jon has over 10 years of both front-end and back-end web programming and development. Currently he is a Senior Web Programmer at Skidmore College maintaing the marketing website. In his free time he enjoys hiking in the Adirondacks, hockey games with the Adirondack Thunder, and creating outragious fan theories about Westworld. Calling it right now, Stubbs is a host with Teddy's memories.