How to Track File Downloads in Google Tag Manager
TL;DR: GA4 tracks file downloads automatically via enhanced measurement, but it misses custom file types, gives you no control over event parameters, and doesn't fire Google Ads conversion tags. For full control, create a Click — Just Links trigger in GTM with a regex condition on Click URL, attach a GA4 Event tag with file_name, file_extension, and link_url parameters, and optionally add a Google Ads Conversion tag. GTM Event Helper can set this up in seconds — click the download link, review the config, and create everything via the GTM API.
File downloads are high-intent actions. When someone downloads your pricing PDF, product spec sheet, or software installer, they're signaling serious interest. Tracking these downloads accurately lets you measure content engagement, attribute leads to specific assets, and optimize ad spend toward the files that actually drive pipeline.
Google Tag Manager gives you two paths: rely on GA4's built-in enhanced measurement, or build a custom setup with full control. This guide covers both approaches, explains the trade-offs, and walks through the complete custom implementation.
Does GA4 track file downloads automatically?
Yes. GA4's enhanced measurement includes automatic file download tracking. When a user clicks a link whose URL ends with a common file extension, GA4 fires a file_download event without any GTM configuration.
The extensions tracked by default are:
.pdf.xlsx/.xls.docx/.doc.csv.txt.rtf.pptx/.ppt.zip.exe/.dmg- Audio and video files:
.mp3,.wav,.mp4,.avi,.mov
To verify enhanced measurement is enabled, go to Admin → Data Streams → (your stream) → Enhanced measurement. The "File downloads" toggle should be on.
The automatic file_download event includes these parameters: file_extension, file_name, link_classes, link_domain, link_id, link_text, and link_url. For many sites, this is sufficient. But there are real limitations.
What are the limitations of GA4's built-in file download tracking?
Enhanced measurement works well for basic tracking, but it falls short in several scenarios that matter for serious analytics.
1. No custom file types. If your site serves .sketch, .fig, .ai, .dwg, or other domain-specific file types, GA4 won't track them. The extension list is hardcoded and cannot be modified.
2. No custom event parameters. You can't add business context like document_category, content_group, or download_source to the automatic event. The parameters are fixed.
3. No Google Ads conversion firing. The automatic file_download event doesn't trigger a Google Ads Conversion Tracking tag. If PDF downloads are a conversion action for your ad campaigns, you need a GTM trigger.
4. No conditional logic. You can't restrict tracking to specific directories (e.g., only /resources/ downloads) or exclude certain files. It's all or nothing.
5. Double counting risk. If you create a custom file_download event in GTM while enhanced measurement is also tracking downloads, you'll count every download twice. You need to either disable the enhanced measurement toggle or use a different event name in your custom setup.
If you build custom file download tracking in GTM, disable the "File downloads" toggle in GA4 enhanced measurement to avoid duplicate events.
How do I create a custom file download trigger in GTM?
A file download is essentially a link click where the URL points to a file instead of a web page. GTM's Click — Just Links trigger is the right choice here because download links are always <a> elements with an href attribute.
Step 1: Enable Built-In Click Variables
Go to Variables → Configure and enable these under "Clicks":
- Click URL — the
hrefof the link (this is what you'll match against) - Click Text — the visible text of the link
- Click Element — the DOM element
Step 2: Create the Trigger
- Go to Triggers → New → Click — Just Links
- Set "This trigger fires on" to Some Link Clicks
- Condition: Click URL → matches RegEx (ignore case) → enter the pattern:
\.(pdf|zip|docx|xlsx|csv|pptx|doc|xls|ppt|dmg|exe)($|\?)
This regex matches any link URL ending with these file extensions, including URLs with query parameters after the extension (e.g., report.pdf?v=2). The ($|\?) at the end ensures the match works whether the extension is at the end of the URL or followed by query parameters.
Step 3: Name It Clearly
Name your trigger something descriptive like "Click — File Downloads (PDF, ZIP, DOCX)". Future-you reviewing the GTM container will appreciate the specificity.
GTM Event Helper detects download links during element selection and suggests the appropriate Click — Just Links trigger with a pre-built regex for file extensions.
How do I create a GA4 Event tag for file downloads?
With your trigger ready, create the GA4 event tag to send download data to your analytics property.
- Go to Tags → New → Google Analytics: GA4 Event
- Select your GA4 Configuration tag (or enter your Measurement ID directly, e.g.,
G-XXXXXXXXXX) - Event Name:
file_download(matches GA4's recommended event name for compatibility with built-in reports) - Add event parameters (see the next section for how to create the extraction variables):
file_name→{{DLV - File Name}}file_extension→{{DLV - File Extension}}link_url→{{Click URL}}link_text→{{Click Text}}
- Set the trigger to the file download trigger you created above
If you're using the same event name as enhanced measurement (file_download), remember to disable the enhanced measurement toggle for file downloads in GA4. Otherwise, use a custom name like custom_file_download.
How do I capture the file name, type, and URL?
The {{Click URL}} variable gives you the full URL like https://example.com/docs/pricing-guide.pdf?v=3. To extract the file name and extension separately, create two Custom JavaScript variables in GTM.
Variable 1: File Name
Go to Variables → New → Custom JavaScript and name it "CJS - File Name":
function() {
var url = {{Click URL}};
if (!url) return '';
// Remove query string and hash
var clean = url.split('?')[0].split('#')[0];
// Get the last segment of the path
var parts = clean.split('/');
return parts[parts.length - 1] || '';
}
This returns pricing-guide.pdf from the full URL.
Variable 2: File Extension
Create another Custom JavaScript variable named "CJS - File Extension":
function() {
var url = {{Click URL}};
if (!url) return '';
var clean = url.split('?')[0].split('#')[0];
var filename = clean.split('/').pop();
var parts = filename.split('.');
return parts.length > 1 ? parts.pop().toLowerCase() : '';
}
This returns pdf from the URL.
Alternative: Lookup Table for File Categories
If you want to group downloads by category in your reports, create a Lookup Table variable that maps extensions to categories:
Input Variable: {{CJS - File Extension}}
pdf → document
docx → document
doc → document
xlsx → spreadsheet
xls → spreadsheet
csv → spreadsheet
pptx → presentation
zip → archive
dmg → installer
exe → installer
Pass this as a file_category event parameter in your GA4 tag for cleaner reporting.
How do I track downloads of specific file types only?
Sometimes you don't want to track every file download — just PDFs from your resources section, or only ZIP files from your downloads page. There are two approaches.
Approach 1: Narrow the Regex
Modify the trigger regex to match only the extensions you care about:
// Only PDFs and spreadsheets:
\.(pdf|xlsx|csv)($|\?)
// Only software installers:
\.(exe|dmg|msi|deb|rpm)($|\?)
// Only PDFs in a specific directory:
\/resources\/.*\.pdf($|\?)
Approach 2: Add a Page Path Condition
Keep the broad file extension regex but add a second trigger condition:
- Condition 1: Click URL matches RegEx
\.(pdf|zip|docx)($|\?) - Condition 2: Page Path starts with
/resources
Both conditions must be true for the trigger to fire. This limits tracking to downloads initiated from your resources section.
Approach 3: Exclude Specific Files
If you want to track all downloads except certain files (like internal team documents), add an exclusion trigger. Create a second trigger with the same conditions plus a match for the excluded file name, set it as an exception on your GA4 tag.
Exception trigger:
Click URL contains "internal-handbook"
Click URL matches RegEx \.(pdf|docx)($|\?)
How do I track file downloads as Google Ads conversions?
If file downloads represent meaningful conversions for your business — like downloading a pricing sheet, product catalog, or free trial installer — you should send them to Google Ads for campaign optimization.
Option A: Direct Google Ads Conversion Tag
- In Google Ads, go to Goals → Conversions → New conversion action → Website
- Choose "Manual setup" and copy the Conversion ID and Conversion Label
- In GTM, create a new tag: Google Ads Conversion Tracking
- Paste the Conversion ID and Label
- Set a conversion value if applicable (e.g., $5 for each PDF download based on your average lead value)
- Attach the same file download trigger you use for GA4
Option B: Import GA4 Key Events
- In GA4, go to Admin → Events and toggle
file_downloadas a key event - Link GA4 to Google Ads (Admin → Google Ads Links)
- In Google Ads, go to Goals → Conversions → Import and select the GA4 key event
Which approach works better? Use the direct Google Ads tag when you need precise conversion counting and want the conversion to fire only for specific file types (e.g., only pricing PDF, not every PDF). Use GA4 import when you want consistent attribution across GA4 and Google Ads reports. For most B2B sites where downloads are a primary conversion, the direct tag gives you more control.
How do I analyze download data in GA4?
Once your tags are firing, you need to register the custom parameters and build useful reports.
Step 1: Register Custom Dimensions
GA4 doesn't automatically make event parameters available in reports. Go to Admin → Custom definitions → Create custom dimension for each parameter:
- file_name — Dimension name: "File Name", Scope: Event
- file_extension — Dimension name: "File Extension", Scope: Event
- file_category — Dimension name: "File Category", Scope: Event (if you created the lookup table)
Custom dimensions take up to 24 hours to start populating in reports after registration.
Step 2: Build an Explore Report
Create a Free Form exploration in GA4:
- Rows: File Name, Page path
- Values: Event count, Total users
- Filter: Event name exactly matches
file_download
This shows you which files get downloaded most and from which pages. Add Session source / medium as a row to see which traffic sources drive the most downloads.
Step 3: Create a Funnel
Use GA4's Funnel exploration to understand the path to download:
- Step 1:
page_view(on the resources page) - Step 2:
file_download - Step 3:
generate_leadorsign_up(if gated content)
This reveals drop-off between viewing the page and actually downloading — useful for optimizing your download page layout and CTAs.
What are common file download tracking mistakes?
These are the issues that cause the most debugging headaches. Avoid them upfront.
1. Double counting with enhanced measurement. This is the most common mistake. If you create a custom file_download event in GTM while GA4's enhanced measurement is also tracking downloads, every download counts twice. Either disable the enhanced measurement toggle for file downloads or use a different event name in GTM (like custom_file_download). Check GA4 Realtime to spot duplicates immediately.
2. Missing query parameter handling. URLs like report.pdf?token=abc123 won't match a regex that only checks for the extension at the end of the string. Always include ($|\?) in your regex pattern to handle query strings.
3. Forgetting CDN and external domains. If your files are hosted on a CDN (e.g., cdn.example.com) or a cloud storage service (e.g., storage.googleapis.com), the Click URL will point to a different domain. Your trigger's regex matches the file extension regardless of domain, but if you've added a Page URL condition, make sure it's on the page URL, not the click URL domain.
4. Not registering custom dimensions. You create the GA4 tag with file_name and file_extension parameters, the events show up in Realtime, and you think you're done. But when you try to use those parameters in Explore reports, they're blank. You need to explicitly register each parameter as a custom dimension in GA4 Admin before the data becomes reportable. And the registration only applies to data collected after the dimension is created — it's not retroactive.
5. Using Click — All Elements instead of Just Links. Download links are <a> elements, so the Click — Just Links trigger is more appropriate. All Elements would also capture clicks on elements inside the link (icons, spans), which can cause the Click URL variable to be empty if the clicked child isn't the anchor itself.
6. Tracking blob: and data: URLs. Some sites generate files dynamically using JavaScript and serve them via blob: or data: URLs. Standard click triggers won't capture these because the URL doesn't contain a file extension. For dynamic file generation, use a Custom HTML tag that listens for the download creation event and pushes to the dataLayer.
Is there a faster way to track file downloads?
The manual setup involves multiple steps: enabling variables, writing regex patterns, creating Custom JavaScript variables, building the trigger, creating the GA4 tag, testing in Tag Assistant, and publishing. It works, but it's time-consuming and error-prone.
GTM Event Helper streamlines this entire workflow:
- Click any download link on your page
- The extension detects it's a file download link and suggests the right trigger configuration
- Review the auto-generated trigger conditions and event parameters
- Click "Create in GTM" — the trigger, GA4 Event tag, and all variables are created via the GTM API
No regex writing. No Custom JavaScript variable setup. No switching between tabs. The entire flow happens on your live site with a direct API connection to your GTM workspace.
Track PDF, ZIP, and document downloads — without manual GTM setup.
Install GTM Event HelperExternal Resources
- GA4: Enhanced measurement events
- Google: Set up click triggers in GTM
- GA4: Custom dimensions and metrics
- Google Ads: Set up conversion tracking