How to track file downloads in Google Tag Manager V2

google tag manager

Setting up tracking of file downloads in GTM V2 is much easier thanks to the new configuration wizard. It is more intuitive and takes you through the set up step-by-step.

Let’s have a look at the basic configuration for sending tracking of file downloads from Google Tag Manager to Google Analytics as events.

To set up this events tag you need to firstly create a trigger.

Create a trigger

This trigger will recognise every time someone clicks to download the file you want to track.

trigger for tracking file downloads

In the given example I am using a simple regular expression to capture a number of file types I want to track -.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$

Here the * means it will capture any repetitions of the file types it is next to, ie it will include file types doc and docx for Word documents, xls and xlsx for Excel spreadsheets, ppt and pptx for PowerPoint presentations.

Save the trigger and create a new tag.

Create a new tag

file downloads tag

Give your tag a meaningful name so you can easily recognise what the tag is for.

configure file download tag in gtm

We have previously created a variable (formerly known as macro) that stores our GA tracking code, which I use in the configuration settings.

This way I do not have to re-enter the GA property ID every time I need it. This variable does all the work.

Select your track type as ‘Event’ and insert your tracking parameters.

Here I use the following but modify the fields based on what works for your business:

  • Category is Download
  • Action is Click
  • Label is {{element url}

Element url in the label field will store the URL of the file that was downloaded.

Advanced tracking

For advanced tracking, you can create a custom javascript variable with a code that will strip out the title of the downloaded file and store it in your GA. Have a look at Simo’s example of returning file name.

Set your tag to fire

Last step is to add a firing rule, ie select a trigger that will fire your tag.

Select the previously created trigger ‘Click to Download’ and you’re all set.


For extra care, test the tag both in GTM debug mode and GA real time.


Now publish the container with your newly created tag.

If you need any further help, do leave a comment below.


Further reading:

Comments 2

Comments are closed.

5 myths of Google Analytics Spam
Google Analytics audit

5 myths of Google Analytics Spam

Google Analytics referral spam is a growing problem, and since Littledata has

How to remove referral spam from Google Analytics
Tracking code

How to remove referral spam from Google Analytics

The issue with the referral spam in Google Analytics exploded in May when we saw

You May Also Like