Track File Downloads in Google Analytics using Google Tag Manager

Sometimes you want to track how many times users download particular files like newsletters and application forms as these act as micro conversions or steps along the path to your major conversions and business goals.

In this article we will look at how to track downloads as Events in Google Universal Analytics (UA) by using Google Tag Manager (GTM) to monitor for clicks on downloads and then fire the event tag.

If you are an SEO Company looking to set this up for a client, this is particularly helpful because you can avoid having to wait for developers and get this setup fairly quickly.

Different ways to fire events

There are a number of different ways you can fire or trigger an event in Google Analytics.

  • You can hard code events into a page so they fire on a button click using a javascript onclick:
    <a href=”” onclick=”ga(‘send’, ‘event’, ‘PDF’, ‘Download’, ‘Deposit Form – PDF Download’);“>Deposit Form</a>
  • Push an event using the dataLayer so it can be accessed by Google Tag Manager
    <a href=” ” onclick=”dataLayer.push({‘event’: ‘deposit-form-download’});” > Deposit Form </a>
  • Use GTM’s Auto Event Tracking to listen for clicks on a link or button, and then fire the event on the button click and return the button label as the event label.

Advantages of using GTM to fire the events

  • Options 1 and 2 require a developer to edit the code on the website, which can sometimes be slow, or just not possible.
  • Using GTM, you can do all this without touching the code on the page and still get the information from the page and the action the user performed.

Setup GTM Auto Event Tracking

Let’s say we want to track all downloads of PDF files across the website. We need to:

  • Create a Trigger that listens for all clicks that leads to a file ending with “.pdf”
  • Fire our Event when someone clicks on a the button or link
  • Send the Category, Action, and Label to Analytics so they appear in reports and we can count the number of each type of download

Enable the Variables we need

In the past, you had to create Auto Event Variables to capture the information we need from the page as User Defined Variables. The new version of Google Tag Manager, GTM V2 now has these built in:

  1. We need the Text of the button the user clicks on, so we know which download has been clicked. This is called: Click Text (old User defined variable method is: element text)
  2. We also want the download URL so we only track PDF’s not all clicks
    This is called: Click URL (old User defined variable method is: element url)

We just need to tick the new inbuilt variables under the Clicks box to make them available.

GTM Variables

GTM Built in Variables


Create the Event Tag to be fired

  • Choose Product: Google Analytics

Add GTM Event Tag

Create GTM event tag

  • Select Universal Analytics
    1. Enter your UA Property ID (UA-XXXXX-XX ) or the Variable constant that you have previously setup with the property ID in it. In this case {{gaPropertyID}}.
    2. Enter the Category and Action
    3. Lastly enter the {{Click Text}} variable in the Label. This will pull in the test from the clicked button or URL
Fill out event tag

Fill out the event tag

Fire On: Create the Trigger

Create the GTM Trigger

Create the GTM Trigger

  • Select Click and new. Call it PDF Download, Configure to trigger on all elements but we want to restrict it to only PDF’s so select Some Clicks
GTM Click Trigger: click URL

GTM Click Trigger: click URL

  • You could also use the + button to add additional conditions like only restricting it to fire on your downloads page. In this case we are happy to track pdf downloads on any page.
  • If you wanted to track multiple file types, you could change this from “ends with” to “matches Regex” and use a regex to match multiple file extensions. Something like:
    Don’t forget to change the name of the trigger to reflect multiple file extensions though E.g. File Downloads
  • Save the trigger and your tag. Your Download Event Tracking is now setup

Viewing the results in Google Analytics

You can check everything is working correctly by viewing Real Time Events in Analytics.

Check Real Time Analytics

Check Real Time Analytics

By selecting your category, in this case Downloads & Forms, you will drill down to see the Click Text that has been pulled in to the Label of the event, and be able to count how many of each pdf has been downloaded.

Real Time Event Labels

Real Time Event Labels

Within a few hours, you should see these in your regular events report under Behaviour -> Events.



In this post we have shown you how to track file downloads in Google Analytics from anywhere on the site, and dynamically capture the name of the document using GTM V2 and Auto Event Tracking.

Hopefully you can see that if you have a large number of downloads, this is a quick way to setup tracking for them.

From here you can create a Google Analytics Dashboard for easy comparison of MoM and YoY downloads.

Google Tag Managers Variables, previously called Macros, are a powerful feature that can capture all sorts of events and information from a page. The new GTM V2 interface has made the most common ones built in and even easier to use.

I hope you enjoy exploring the other possibilities with Variables and Auto Event Tracking.

This entry was posted in How To, Latest News & Tips. Bookmark the permalink.

san francisco

101 California Street
Suite 2710
San Francisco, CA 94111

P: +1 (415) 670-9799

Local time:

new york

375 Park Avenue
Suite 2607
New York City, NY 10152

P: +1 (646) 583-0455

Local time:


101 Avenue des Champs Élysées
Level 5
75008 Paris

P: +33 (0)9 77 21 52 11

Local time:


36/1 Macquarie Place
Sydney NSW 2000

P: +61 (0)2 9954 6100

Local time:


27/101 Collins Street
Melbourne VIC 3000

P: +61 (0)3 9020 7055

Local time:


36/71 Eagle Street
Brisbane QLD 4000

P: +61 (0)7 3733 1422

Local time: