About cookies on this site

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. Learn more

Cookie settings

About cookies on this site

Cookies used on the site are categorized and below you can read about each category and allow or deny some or all of them. Learn more

Necessary

Some cookies are required to provide core functionality. The website won't function properly without these cookies and they are enabled by default and cannot be disabled.

Preferences

Preference cookies enables the web site to remember information to customize how the web site looks or behaves for each user. This may include storing selected currency, region, language or color theme.

Analytical cookies

Analytical cookies help us improve our website by collecting and reporting information on its usage.

Marketing cookies

Marketing cookies are used to track visitors across websites to allow publishers to display relevant and engaging advertisements. By enabling marketing cookies, you grant permission for personalized advertising across various platforms.

  • Courses
    • Paid courses
    • Course bundles
    • Free courses
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login
  • Courses
    • Paid courses
    • Course bundles
    • Free courses
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login

February 25, 2025

Track PDF Downloads with Google Tag Manager

Updated: February 28th, 2025

Tracking file downloads on your website is essential for understanding user engagement and ensuring that the content you create resonates with visitors. By tracking downloads, you can gauge the value of your efforts and save time by focusing on content that generates the most interest.

You can follow two methods to track PDF downloads: (1) use the built-in GA4 enhanced measurement events, or (2) create a custom setup using GTM and GA4.

In this article, we will focus on the second method, how to do it, and the reasons why (for some people) tracking PDF downloads with GTM makes more sense than using the enhanced measurement event.

I presume you already know at least the basics of Google Tag Manager and have installed it on your website. If you still need to, read this tutorial.

Subscribe and Get the Ebook - Real Book Img - GTM for Beginners

Table of Contents

Here’s what you will learn in this article

  • Enhanced measurement
  • Reasons why it makes sense to track PDF downloads with GTM
    • Cannot customize the list of supported file extensions
    • Limitations in custom parameters/dimensions
    • The max length of link_url is 100 characters
  • Tracking PDF downloads with GTM
    • Step 1: Create a variable for the file name
    • Step 2: Create a Link Click trigger
    • Step 3: Create a GA4 event tag
    • Step 4: Test the setup
    • Step 5: Publish
  • Where can you find PDF download data in GA4?
    • Standard GA4 reports
    • Free form exploration
  • Can I track if a visitor opens a PDF directly?
  • Final Words

 

Video tutorial

If you prefer video content, here’s a tutorial from my YouTube channel.

 

Tracking file downloads with enhanced measurement

Google Analytics 4 has a feature called enhanced measurement that automatically tracks multiple actions, like file downloads. These events allow you to get more out-of-the-box tracking without configuring GTM or editing your website’s code.

The file_download event is triggered when a link is clicked, and the file extension of the link matches the following regular expression: pdf|xlsx?|docx?|txt|rtf|csv|exe|key|pp(s|t|tx)|
7z|pkg|rar|gz|zip|avi|mov|mp4|mpe?g|wmv|midi?|mp3|wav|wma

When enhanced measurement is enabled, and the file_download event is triggered, the following dimensions will automatically populate: file_extension, file_name, link_classes, link_id, link_text, and link_URL.

Google Analytics 4 automatically tracks these dimensions, which you can learn more about here, and you don’t need to add them as custom dimensions in the interface (which is not true for all automatically tracked dimensions and metrics, so check the list).

You can learn more about implementing enhanced measurement here and here (specifically for file downloads).

However, there are limitations to using enhanced measurement. You probably noticed that the event is triggered on many file extensions, which might cause issues if you just want to track PDF downloads. Let’s get into a few more reasons.

Subscribe and Get the Ebook - working with reports in ga4

Reasons why it makes sense to track PDF downloads with GTM

Sometimes, you just need to enable tracking quickly, and enhanced measurement events are great for this purpose. However, you might eventually find limitations in the data obtained from these events. In the case of file downloads, a few things might make you consider implementing a custom setup for tracking.

 

Cannot customize the list of supported file extensions

Automated tracking runs on certain assumptions, so if there are ways to download files from your site that aren’t standard, as defined by Google, those file downloads will not get tracked. For example, a file on your site could exist with an extension that doesn’t match any file extensions in the list that triggers the event.

Google Analytics 4 file download tracking supports only the following file extensions: .pdf, .xls, .xlsx, .doc, .docx, .txt, .rtf, .csv, .exe, .key, .pps, .ppt, .pptx, .7z, .pkg, .rar, .gz, .zip, .avi, .mov, .mp4, .mpe, .mpeg, .wmv, .mid, .midi, .mp3, .wav, .wma.

Even though these are the most popular ones, there is a slight chance that your business uses a different extension. At the time of writing this blog post, you cannot customize the list of extensions, so there is no way to mitigate against inaccuracies in the data when there are unique file extensions on your site.

This also means you can’t just track PDF downloads; you will track all file downloads on your site in the same event.

Solution? A custom setup (which is coming up).

 

Limitations in custom parameters/dimensions

You can’t add any additional information, e.g., if you want to capture another parameter, like content_group, with the event.

By adding the parameter into the Event settings variable and integrating it into the Google tag, you can ensure that the enhanced measurement events collect this information. But if you want to send a parameter with just the file downloads event, this is only possible with a custom setup.

 

The max length of link_url is 100 characters

When GA4 tracks the file links, it captures the entire URL. So, if the URL is too long, GA4 will cut off the end of the value. Usually, the end of the URL contains the actual file name and file extension (pdf, xls, etc.), which can be problematic.

Instead, I prefer tracking the file name (e.g., some-ebook.pdf) or the Path, e.g., “/download/something/some-ebook.pdf”. This would reduce the impact of the character limit.

If these limitations impact you and you need to track file downloads (in general, not just PDFs), check out this article on how to implement file download tracking with Google Analytics 4.

Now, let’s get into the custom setup for PDF downloads!

 

Tracking PDF downloads with GTM

If you have reached this point, then using enhanced measurement has not met your needs for tracking PDF downloads. Luckily, you’re only five steps away from a custom setup that avoids all the abovementioned issues!

 

Step 1: Create a variable for the file name

Go to your Google Tag Manager container, click “Variables”, and ensure the Click URL variable is enabled. If you don’t see it in the list, click “Configure” and find the Click URL under Clicks.

Then click New (in the same Variables section) > Variable Configuration > Custom JavaScript. Paste the following code:

function() {
  var filepath = {{Click URL}}.split("/");
  var filename = filepath.pop();
  var decodedFilename = decodeURI(filename);
  return decodedFilename.indexOf(".") > -1?decodedFilename:'n/a';
}

Name the variable “cjs – filename” and save.

 

Step 2: Create a Link Click trigger

Now, go to Triggers > New > Trigger Configuration > Just links. Enter the following configuration:

Name this trigger “Link click – pdf download” and save.

 

Step 3: Create a GA4 event tag

Go to Tags > New > Tag Configuration > Google Analytics > Google Analytics: GA4 Event. Enter the following settings:

Ensure that the event parameter names are exactly as I show in the screenshot: file_name, link_text and link_url. You can also add these parameters to the Event settings variable and add it to the tag.

Ensure that two built-in variables in GTM are enabled: Click Text and Click URL. If you don’t see them, click Variables > Configure and enable them.

Then click the Triggering and add the Link click trigger we created in the previous chapter.

Name the tag “GA4 event – pdf_download” and save.

Subscribe and Get the Ebook - Mastering GA4 event tracking

Step 4: Test the setup

We’re almost at the end! Now that the setup has been implemented, you must check that everything works as expected using Preview and Debugview.

Click Preview in the top-right corner of the GTM interface and enter the page URL where you want to test your new event.

Once the Preview mode has launched and your site opens, click the downloadable PDF file. Back in GTM, select the Link Click event in the left-hand tab. You should see your tag here.

Did the tag fire? If yes, go to Google Analytics > Admin > Data display > Debugview. Here, the pdf_download event will be visible (if everything was set up correctly). If you don’t see the event, check out these common mistakes.

Note: if you haven’t disabled the GA4 enhanced measurement file download tracking, you will see two events. No worries, we will fix this next!

 

Step 5: Publish GTM and (optionally) disable file download tracking in GA4

Final step. There are two things you need to do:

  1. Publish the GTM container by clicking the “Submit” button in the top-right of the GTM interface. Now, the event will be live, and start collecting data on your website.
  2. [Optional] You may be fine with having the file_download event run in parallel to the pdf_download event to capture the download of other file types, in which case, ignore this step. If you want to disable it, go to Google Analytics > Admin > Data Streams > Select your web data stream. Click the gear icon, disable File download tracking, and save. This way, you will avoid duplicate data for PDF downloads.

 

Where can you find PDF download data in GA4?

You must wait at least 24-48 hours after publishing your GTM container before seeing data in Google Analytics 4. To see the data, you can use the built-in standard Events report or create a free form exploration.

 

Find PDF download data in standard GA4 reports

To find the built-in standard report for Events in GA4, go to Reports > Engagement > Events.

Since GA4 is customizable, your property may not look the same as mine, so the location of this report may be elsewhere. You can also add this report collection to your reports tab if you don’t have it by going to the Library and publishing the “Life cycle” collection.

Search the name of the event pdf_download.

This may not show you the granularity of data that you are looking for, so there are three options:

  • Customize the report to use the Link URL as a primary dimension and then add a filter to include only pdf_download events. A similar principle is explained here.
  • Add a custom dimension (like explained here)
  • Build a Free Form exploration report, which we will do now!

 

Find PDF download data in the GA4 free form exploration

To create your own report, go to Explore > Blank exploration. Learn more about free-form reports here.

In the report, you want to add:

  • Dimensions: Event name, File name or Link URL (I find File Name easier to read)
  • Metrics: Active users, Event count
  • Filter: Event name exactly matches pdf_download

Double-click on each dimension and metric to add them to the report (you don’t need to add the Event name parameter since it will be the same for every row).

 

Can I track if a visitor opens a PDF directly?

“Is there a way to check when a user accesses a PDF file in their browser directly through a link?” Unfortunately, there is no convenient way to do this since you cannot embed JavaSript in PDF files, preventing the installation of GA4 and GTM.

However, you can still work with a developer to see if they can check the server logs and tell you how many times users are opening a particular PDF. They should have this data, but GA4 cannot collect it.

 

Tracking PDF Downloads with Google Tag Manager: Final Words

Enhanced measurement is a quick way to set up your Google Analytics 4 tracking and capture how users interact with your site without needing extra configuration in GTM or adding to your website’s code.

However, you will quickly find that there is a better way to do things than this, especially when tracking actions that can dictate where you dedicate time and resources, like the creation of downloadable content.

The best practice would be to implement file download tracking with a custom setup, which you can do in five steps using GTM without needing a developer. Give it a go!

Subscribe and Get the Ebook - conversion tracking handbook
Julius Fedorovicius
In Google Analytics Tips Google Tag Manager Tips
13 COMMENTS
Kathy
  • Jul 10 2020
  • Reply

This is so helpful, thank you!! I really appreciate how you walked through the very very basic beginner steps as well.

    Julius
    • Jul 10 2020
    • Reply

    You're welcome!

Rick
  • Jul 27 2020
  • Reply

Any idea how to track direct links to a PDF file? Everything above makes sense from a link click perspective, but how would you handle someone taking your PDF link and posting it online and then as a website owner, knowing how many people not only see the PDF from link clicks, but also from direct traffic?

    Julius Fedorovicius
    • Jul 27 2020
    • Reply

    Hi, what you have described is impossible to track with GTM, GA or any other similar tool.

      Rick
      • Jul 27 2020
      • Reply

      I was afraid of that. Thank you for confirming Julius.

Rob B
  • Dec 8 2020
  • Reply

Great set of instructions really clear, unfortunately...
I just cannot get either a simple ahref link, or button link to a pdf doc download to trigger at all. Can you think why this may be the case?
Other tracking tags work ok.

    Julius
    • Dec 8 2020
    • Reply

    It can be anything. More information is needed.

Vess
  • Feb 7 2021
  • Reply

Very helpful, thank you sir!

melanie
  • Oct 12 2021
  • Reply

hello,
I would like to know if the person went to the bottom of the document for example. How i do?
How do i do to track a specific page on my website or landing page ? Click, scroll etc

    Julius Fedorovicius
    • Oct 12 2021
    • Reply

    1. You cannot track how people use your PDF files (e.g. scrolls to the bottom).

    2. You use a variable Page URL in the trigger (e.g. Page URL contains xxxxx)

Ainhoa
  • May 24 2022
  • Reply

Hi,
I am in the position where I need to know when the invoice is actually downloaded, can this be done? Not when clicking on the URL or cliking on the text "X", this can only be done with data layers?
How would it be?
Thanks and regards,
Ainoa

    Julius Fedorovicius
    • May 24 2022
    • Reply

    You need to talk to the developer about this. Placing Javascript (including datalayer) directly in the PDF file is impossible.

Atli Bjarnason
  • Jul 18 2024
  • Reply

Great article!

But how would you track "pdf_download" (and NOT use the "enhanced measurements") when you have sGTM server set up?

Leave a comment Cancel reply

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


 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Google Tag Gateway: What is it, and How to Configure it
  • Google Analytics 4 User ID for cross-device tracking: how to configure it
  • How to Track Clicks with Google Analytics 4 (2 Options)
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings