Blog

Is your main conversion point is a white paper or file download, or you just want to know if your website visitors are downloading documentation files?
Then you’d want to setup your GTM container to track downloads in Google Analytics. The tools within Google Tag Manager allows you to set this up without having to alter the code of your website.

Below we’ll discuss some easy tips and tricks, in a step-by-step approach to set up your own download tracking.

Step 1: list your file extensions

The first thing you will want to do is to list out all of the different file extensions for your downloadable files. In case of a PDF-file this would be .pdf, in case of an excel file this would be .xls and .xlsx, etc.

The reason we want to have a list of these is because we want to look for links containing these extensions, and add a click listener in GTM so that whenever someone clicks on your file we can track the download in GTM and subsequently Google Analytics.

We then build a regex to match for these file types. You can add any file by just adding another line symbol – the OR symbol in regex – and adding your extension.

\.(pdf|xlsx|docx)$

Step 2: create a trigger in GTM to track downloads

Go to triggers, and click create new. As for the trigger type, we want to select Click – Just Links (since all of these downloads are usually contained within an <a>-tag).
Finally, you’d want to select Some Link Clicks and configure like below.

Download trigger in GTM
Download trigger in GTM

Make sure the second drop-down is set to matches RegEx, by default it’s’ set to contains and this won’t work.

Select built-in variable in GTM

If you don’t see the option for Click URL, this means this variable is not configured for your property yet. You can quickly configure this by scrolling to the bottom of the drop-down and selecting choose built-in variable. In the menu that pops-out you can simply search for Click URL and select it.

Step 3: create a Google Analytics tag to track downloads

Finally we want to set up our Google Analytics event tag which will notify GA that a visitor has downloaded a file. Go to tags and click on New.

Select Universal Google Analytics and set the track type to Event. You can set the category, action and label dimension to whatever value you prefer; this information will be stored as such in Google Analytics so make sure it reflects that a user has downloaded a file. You can use the built-in variables (for example Click URL) in GTM to store the download link as well, or you can even use custom dimensions if these 3 won’t suffice.

Track downloads in Google Analytics with GTM