How To Track File Downloads in Google’s Universal Analytics using Google Tag Manager

Sometimes you want to track file downloads and 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=”www.mywebsite.com/pdf/deposit-form.pdf” onclick=”ga(‘send’, ‘event’, ‘PDF’, ‘Download’, ‘Deposit Form – PDF Download’);“>Deposit Form</a>
  • Push an event using the data layer, so it can be accessed by Google Tag Manager
    <a href=” www.mywebsite.com/pdf/deposit-form.pdf ” 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 file downloads of PDF files across the website. We need to:

  • Create a Trigger that listens for all clicks that lead to a file ending with “.pdf”
  • Fire our Event when someone clicks on 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 require the Text of the button the user clicks on, so we know which download has been clicked. This is called: Click Text (the old user-defined variable method is: element text)
  2. We also want the download URL, so we only track PDFs not all clicks
    This is called: Click URL (the 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.

Create the Event Tag to be fired

  • Choose Product: Google Analytics
  • 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

Fire On: Create the Trigger

  • Select Click and new. Call it PDF Download, Configure to trigger on all elements, but we want to restrict it to only PDF so select Some Clicks
  • 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:
    \.pdf$|\.docx$
    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 set-up

Viewing the results in Google Analytics

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

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

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

Conclusion

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 many downloads, this is a quick way to set up 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.

Need help with your SEO?

We’ve been providing award-winning SEO services for over a decade. Contact us to see how we can help you grow online.