File downloads tracking in Google Analytics 4 and Universal Analytics

Introduction

Google has produced several versions of Analytics over the years. The most common and stable version of the platform in current use is Universal Analytics. Many users are now also using the latest version of the product; Google Analytics 4, or GA4 for short.

Many websites that currently use Universal Analytics are likely to upgrade to GA4 soon. Some websites may be able to use both versions at the same time. Regardless of the version you are using, tracking Google Analytics file downloads can be useful.

In this guide, we’ll explain how to track file downloads in Google Analytics. We’ll explain how to do this using both Universal Analytics and Google Analytics 4.

Why do you need file downloads tracking in Google Analytics?

Many websites provide files that they encourage visitors to download, which can sometimes be one of your conversion targets. Using Google Analytics to track file downloads helps on that.

For instance, this might be a PDF-brochure, or Word-document, or Excel-spreadsheet, or CSV-dataset.

You can track downloads of these files in Google Analytics 4(and Universal Analytics – the “old” version of GA) and measure how users download files.

As well as tracking the number of times a file is downloaded, Google Analytics can also help track the file name, file extension, and which page URL corresponds to where visitors are downloading the file from.

File downloads tracking in Google Analytics 4

There are several differences in terms of the tools available between Universal Analytics and GA4.

In Google Analytics 4, file downloads tracking is automatic. In Universal Analytics, file downloads can only be tracked once you have programmed it to track them.

Once configured to do so, Google Analytics 4 automatically tracks several pieces of data related to a file download. If you want to track file downloads in Google Analytics 4, this must be activated using the “Enhanced Measurement” feature, which can be accessed from the GA4 interface(GA4 Admin → Data Streams → Web → Enhanced Measurement ).

This doesn’t require any code changes to the website. The categories contained in “Enhanced Measurement” can also be customized if you need to record some actions but not others. To appear on your Google Analytics report, these categories must be defined as “Custom Definitions”.

The information collected by GA4 when a file is downloaded consists of these fields;

  • file_download – the action of the file being downloaded
  • file_name – the name that has been given to the downloadable file. This will also show in the URL.
  • file_extension – this indicates the type of file being downloaded, such as .docx or .pdf.
  • link_url – the URL link attached to the file, usually indicating which page the file was downloaded from
  • link_text – the text of the file’s download link as it is shown on the corresponding page (eg: “Sustainability Report Whitepaper”)
  • link_classes – HTML-classes of the link;
  • link_id – HTML-classes of the link;

When it comes to supported file extensions that can be tracked automatically, Google Analytics supports a wide variety of file types ranging from documents such as .doc, .docx, and .txt to audio and video formats like .avi, .mov, .mp3, and .mpeg.

These file extensions will trigger the “file_download” event in Google Analytics 4:

.pdf, .xlsx, .docx, .txt, .rtf, .csv, .exe, .key, .pps, .ppt, .pptx, .7z, .pkg, .rar, .gz, .zip, .avi, .mov, .mp4, .mpeg, .wmv, .midi, .mp3, .wav, .wma

It is possible to configure GA4 to support and track additional types of file extensions. To do this, you’ll need to use Google Tag Manager to configure triggers for these other extensions.

File downloads tracking in Universal Analytics and Google Tag Manager

Unlike in GA4, Google Analytics file downloads tracking is not automatic in Universal Analytics. To set up the tracking, you need to pair Google Tag Manager with your Universal Analytics account. This allows us to manually configure certain variables, triggers, and tags that govern the process of tracking our file downloads.

Configuring variables for file downloads tracking in Google Tag Manager

First, we need to configure our variables. We need to use variables as information that helps Google Tag Manager understand our triggers and tags. Here’s how to set up variables for file downloads:

Step 1: Open Google Tag Manager and click on the “Variables” menu

Step 2: In the section for “Built-In Variables”, check to see if the options for “Click URL” and “Click Text” are shown in the drop-down list. Click to check these boxes and select them as options. You’ll also probably need the other options on the list as well, so leave them selected

Step 3: If “Click URL” and “Click Text” are selected, you can then create triggers for them (see below). If the URL and text for the downloadable file aren’t shown, click “Configure” and then enable them as variables

Create a File Downloads Trigger in Google Tag Manager

Next, we need to create our triggers. These are certain instructions that we program into GTM to tell it when we want it to start tracking something. Follow these steps to set up triggers for tracking file downloads:

Step 1: Open Google Tag Manager and select the “Triggers” menu. Click “New” in the top right corner

Step 2: Enter a name for your trigger so you can easily know what that it relates to tracking file downloads. In this example, we’ll call the trigger “T – file downloads tracking”

Step 3: Click on the option “Choose a trigger type to begin setup”

Step 4*: Choose the option “All Elements” as the trigger type

Step 6: Set “This trigger fires on” as “Some Clicks” rather than “All Link Clicks”

Step 7: In the “Fire this trigger when an Event occurs and all of these conditions are true” section, Choose “Click URL” for the first box. The choose the “matches RegEx (ignore case)” option for the second box. In the third box, copy and paste one of the following file extensions that relate to your downloadable file;
\.pdf|\.xlsx|\.docx|\.txt|\.rtf|\.csv|\.exe|\.key|\.pp(s|t|tx)|\.7z|\.pkg|\.rar|\.gz|\.zip|\.avi|\.mov|\.mp4|\.mpeg|\.wmv|\.midi|\.mp3|\.wav|\.wma

Step 8: Save the completed trigger

Note that you can also use this created trigger with other tags such as Bing, Facebook Pixel, and Google Ads.

*Please, note, that this trigger configuration is very simplified. In some cases, you need to use the “Just Links” trigger instead.

Create a Universal Analytics Tag for file downloads in GTM

The last thing we need to do is set up the tags for our file downloads. Tags are pieces of code that help interface your website with third-party tools like Google Analytics. In Google Analytics event tracking for file downloads requires tags to be recognized as a trackable event.

These events require three parameters that tell Universal Analytics what you want to track. This information can then be used to create the tags, triggers, and variables used in Google Tag Manager to track the action.

The three parameters needed are;

  • Event Category – this is a static field that provides context for what you want Universal Analytics to track. “File downloaded” would be a relevant category for what we are discussing.
  • Event Action – this is a dynamic field that contains the text attributed to the link of the downloadable file. This is taken from the webpage that contains the file. In our example, let’s call this “Annual Salary Report – 2021”.
  • Event Label – another dynamic field, this holds the URL link of the downloadable file. For example, ours might be “https://site.com/annual-salary-2021.pdf”.

We can now use these values to create a tag related to the file download. The following steps explain how to set up a tag for tracking file downloads:

Step 1: Open Google Tag Manager and click on the “Tags” menu. Click “New” in the top right corner

Step 2: In the “Tag Type” field, choose “Google Analytics: Universal Analytics”. This lets the tag know which version of Google Analytics you are using

Step 3: In the “Track Type” field, choose “Event”

Step 4: In the “Category” section, define what you want the tag to be called. For our example, we’ll call it “File Download”

Step 5: For the “Action” section, select “{{Click Text}}”. Alternatively, if you click the “+” symbol to the right-hand side, you can choose “{{Click Text}}” from the list

Step 6: In the “Label” section, select “{{Click URL}}”. As above, you can also select this option from the list by clicking on the “+” symbol

Step 7: You can leave the “Value” section blank. If you want and if it relates to your download file, you can also enter a monetary value here

Step 8: Leave the “Non-Interaction Hit” option as “False”

Step 9: In the “Google Analytics Settings” field, choose the GA variable we set up earlier

Step 10: In the “Triggering” section, select the tag we created earlier; “T – file downloads tracking”

Step 11: Save the completed tag

Step 12: Publish the GTM container

These are the basic steps needed to set up file downloads tracking for Universal Analytics. However, it is possible to send the file extension of your downloadable file to Google Analytics. You may want to do this if you need to keep the extension visible in your Universal Analytics reports.

If you do want to do this with the file extension, you’ll need to perform some customizations in Google Tag Manager such as creating an additional GTM variable.

Conclusion

So that’s how to track downloads in Google Analytics 4 and Universal Analytics. Tracking file downloads is much simpler in GA4 as it works automatically without any additional setup.

In Universal Analytics, file downloads tracking must be manually configured using Google Tag Manager to be recorded. However, this method does have some benefits as it allows for more customization than the automatic-tracking in GA4

Regardless of which version you have, use this handy guide to start tracking file downloads on your website today.


Comments

5 responses to “File downloads tracking in Google Analytics 4 and Universal Analytics”

  1. Simon Logan Avatar
    Simon Logan

    “Step 9: In the “Google Analytics Settings” field, choose the GA variable we set up earlier”

    What GA variable we set up earlier?

  2. I am using GA4 and I want to track pdf downloads but it’s not happening even when Enhanced Measurement is On. What could be the reasons for that?

  3. Steve Avatar
    Steve

    Great article Ruslan! One thing I’m missing, with GA4 not sure why I’m not seeing items such as “file_name” and “link_url” in the reports section. I see the URLs of web pages hit, but that info doesn’t exist for PDFs, videos, etc downloaded. Do we still need to configure that somehow, and if so how/where?

  4. Alessandro Avatar
    Alessandro

    I have installed GA4 yet it does not track downloads of pdf files. It’s a proprietary CMS, is it possible that the way GA4 tracks it is not compatibile with the CMS?

  5. jenny kurian Avatar
    jenny kurian

    GA4 automatic download not working for a pdf file download in a website. Could you tell me the possible scenarios in this case.

Leave a Reply

Your email address will not be published. Required fields are marked *