How to track file downloads other than PDFs with Google Tag Manager

Author:

Tracking file downloads (other than PDFs) in Google Tag Manager (GTM) involves setting up triggers to capture interactions with links that lead to downloadable files, such as .docx, .xlsx, .zip, .jpg, and others. This process helps you track when users download files from your website and is useful for measuring engagement with downloadable content.

Step-by-Step Guide to Track Non-PDF File Downloads in GTM

Step 1: Set Up Google Tag Manager

Before you begin, make sure Google Tag Manager is properly set up on your website.

  1. Create a GTM Account and Container: If you haven’t already, sign up for GTM and create a container for your website.
  2. Install the GTM Snippets: After creating the container, GTM provides you with two snippets of code that you need to install on your website to enable GTM functionality.

Step 2: Create a New Trigger to Track File Downloads

To track file downloads, we’ll create a trigger that captures link clicks with specific file extensions.

  1. Access Google Tag Manager: Log into your GTM account and open the container for your website.
  2. Create a New Trigger:
    • On the left-hand side, click Triggers and then click New.
    • Name your trigger something descriptive, such as “File Download – Non-PDF Files”.
  3. Choose Trigger Type:
    • Click Trigger Configuration, and select Just Links under Click triggers.
    • This trigger will capture clicks on any link (anchor tags) on your website.
  4. Set Conditions for the Trigger:
    • Under This trigger fires on, select Some Link Clicks.
    • In the dropdown, choose the variable Click URL (this variable holds the URL of the clicked link).
    • Next, set the condition to use matches regex to target non-PDF file downloads.

    Here’s the regular expression you can use for non-PDF file extensions:

    • Regex: \.(docx|xlsx|zip|jpg|png|mp4|pptx|exe|csv)$
    • Explanation: This regex pattern will match any URL ending with .docx, .xlsx, .zip, .jpg, .png, .mp4, .pptx, .exe, or .csv. You can adjust this pattern to include or exclude other file types as needed.
  5. Save the Trigger: Once you’ve set the condition to match file extensions, click Save.

Step 3: Create a Tag to Fire When the Trigger is Activated

Next, you need to create a tag that fires when the download trigger is activated. This tag can be used to send data to Google Analytics, track conversions, or log the event in another system.

  1. Create a New Tag:
    • Go to the Tags section in GTM and click New to create a new tag.
    • Name your tag, such as “File Download – Track Non-PDF”.
  2. Choose Tag Type:
    • If you are using Google Analytics, select Google Analytics: Universal Analytics or Google Analytics 4 Event depending on which version you are using.
    • For Universal Analytics, choose Event for the Track Type.
    • For Google Analytics 4 (GA4), choose Event under the GA4 configuration.
  3. Configure the Tag:
    • For Universal Analytics, set the event parameters as follows:
      • Category: File Download
      • Action: {{Click URL}} (this will capture the file URL)
      • Label: You could also use {{Page URL}} to capture the page the link was clicked on.
    • For GA4, set the event parameters similarly:
      • Event Name: file_download
      • Event Parameters:
        • file_name: {{Click URL}}
        • page_url: {{Page URL}}
  4. Set the Trigger:
    • Under Triggering, select the trigger you created earlier (e.g., “File Download – Non-PDF Files”).
    • This ensures that the tag will fire only when a non-PDF file download is detected.
  5. Save the Tag: Once you’ve configured the tag, click Save.

Step 4: Test the Implementation

Before going live, you should test your setup to ensure the file download tracking is working correctly.

  1. Preview Mode in GTM:
    • In GTM, click Preview in the top-right corner to enter debug mode.
    • On your website, navigate to a page with a file download link, and click on a file that matches the trigger conditions (such as a .docx, .zip, etc.).
    • In the GTM preview window, check that the File Download – Non-PDF Files trigger fires when the file is clicked.
  2. Check Google Analytics Real-Time Reports:
    • If you are using Google Analytics, go to the Real-Time section to check if the event is being recorded as expected.
    • In Universal Analytics, navigate to Real-Time > Events to see if the “File Download” event is triggered.
    • In GA4, go to Real-Time and look for the file_download event.
  3. Test Different File Types:
    • Try clicking on different file types to verify that only the non-PDF files trigger the event.

Step 5: Publish the Changes

Once you’ve tested the tracking setup and confirmed that it’s working correctly:

  1. Publish the Container: In GTM, click on Submit to publish the changes.
  2. Monitor Results: Over time, check Google Analytics or your preferred tracking system to ensure file downloads are being tracked accurately.

Optional: Track Download Details with Variables

If you want to capture additional details about the file download (e.g., file name, file size), you can create custom variables in GTM. Here are a couple of examples:

  • File Name: You can extract the file name from the download URL using a JavaScript variable. For example, create a variable that uses a regular expression to extract the file name from the Click URL.
  • File Size: You can track file size by using a custom JavaScript variable that makes an API request to get the file size before the download begins. However, this can be more complicated and may require additional server-side tracking.

Conclusion

Tracking non-PDF file downloads with Google Tag Manager is straightforward once you set up a trigger using regular expressions to match the desired file extensions. By following the steps above, you can easily track interactions with downloadable content on your website, helping you measure engagement and gain insights into how users interact with your digital assets. Whether you’re tracking .docx, .zip, or .mp4 files, GTM gives you the flexibility to capture a wide range of file downloads and send the data to your analytics platform.