Sub topic 8
File downloads and recognized file extensions
This chapter covers the file_download event. It explains when GA4 fires the event, which parameters it carries, which links it misses, and how to cover those gaps. It assumes you have a web data stream with the Google tag installed (gtag.js or Google Tag Manager). It also assumes you know how GA4 events and parameters work, and that you can open the data stream's enhanced measurement settings in Admin.
What the event records
When File downloads is on, the Google tag listens for clicks on links. If the link's destination ends in a recognized file extension, the tag sends a file_download event. No custom code or tag configuration is needed.
The event carries these parameters:
| Parameter | What it contains | Example |
|---|---|---|
| `file_name` | The file name taken from the link's path | `pricing-2026.pdf` |
| `file_extension` | The extension without the dot | `pdf` |
| `link_url` | The full destination URL of the link | `https://example.com/files/pricing-2026.pdf` |
| `link_text` | The visible text of the link | `Download the price list` |
| `link_id` | The `id` attribute of the link, if any | `price-list-link` |
| `link_classes` | The `class` attribute of the link, if any | `btn btn-primary` |
| `link_domain` | The host of the destination | `example.com` |
Like other events, file_download also carries the standard page and device parameters, such as page_location. That lets you tie a download to the page that offered it.
Which extensions are recognized
GA4 matches the link's destination against a fixed list of extensions:
| Group | Extensions |
|---|---|
| Documents | `pdf`, `doc`, `docx`, `txt`, `rtf`, `csv`, `xls`, `xlsx`, `key`, `ppt`, `pptx`, `pps`, `ppsx` |
| Archives and installers | `zip`, `rar`, `7z`, `gz`, `exe`, `pkg` |
| Audio | `mp3`, `wav`, `wma`, `mid`, `midi` |
| Video | `avi`, `mov`, `mp4`, `mpg`, `mpeg`, `wmv` |
Google can change this list. Check the current Analytics Help page for enhanced measurement before you rely on a specific extension.
The list is fixed in the product. The data stream settings give you an on/off switch for downloads, and the settings screen has no field for adding extensions such as epub, dmg or apk. Links to those files do not produce file_download. If you need them, use a custom event, shown later in this chapter.
How the decision is made
The diagram shows two points. The decision is based only on the link's destination URL, not on what the server sends back. A file on another domain can also trigger the outbound click event, which causes the duplicate described below.
Turning the setting on or off
- In Google Analytics, open Admin.
- Under Data collection and modification, choose Data streams, then select your web stream.
- In the Enhanced measurement section, make sure the master toggle is on, then click the gear icon.
- Switch File downloads on or off. The label may read "File downloads" with the description "Link click that leads to a file with an extension such as pdf, doc or zip."
- Click Save.
The change applies to new data only. It does not alter events already collected. Allow a short delay before the setting takes effect, then confirm it in DebugView as described below.
Example: a link that works
This link is recognized because its path ends in .pdf:
<a id="spec-link" class="btn" href="/files/product-spec.pdf">Download the spec</a>A click sends a file_download event with these values:
file_name:product-spec.pdffile_extension:pdflink_url: the absolute URL of the filelink_text:Download the speclink_id:spec-linklink_classes:btn
Links that do not produce the event
The file extension has to appear in the link's destination. These situations are the usual reasons a download goes unmeasured:
- Extensionless download URLs. A link such as
/download?id=42that makes the server return a PDF does not match. The tag never sees the file type. - Redirects through a tracking or short URL. The link points at
https://go.example.com/abc, which redirects to a file. The tag sees only the first URL. - Downloads started by JavaScript. A button that calls
window.location = ..., creates a blob URL, or submits a form never produces a link click on a file URL. - Unlisted extensions.
epub,dmg,apk,isoandjsonare examples. - Clicks the tag cannot see. This includes links inside an iframe from another origin, and clicks where script on the page stops the event from reaching the tag.
- Direct visits. Someone who opens a file URL from a bookmark or an email client is not clicking a link on your site. No click happens on a page that carries your tag.
You may also see a download counted as something other than a download. If your site rewrites links on click, the tag may evaluate the link after the rewrite. Test the exact link behavior in DebugView and do not assume.
Duplicates and overlap with other events
Two overlaps are common.
Outbound links. If the file lives on another domain, such as a CDN or a document host, the click can be both an outbound click and a file download. You get click (with outbound=true) and file_download from one action. Treat them as two views of the same click, and do not add the counts together.
Your own tagging. If you added a GTM trigger or a custom script that sends a file_download event, you now send it twice: once from enhanced measurement and once from your tag. The same applies if you send a differently named event for the same click and then compare totals. Pick one source of truth. Either turn off File downloads in the stream and keep your own event, or keep the built-in event and remove your tag.
Also keep in mind that one person clicking a link three times creates three events. GA4 does not de-duplicate clicks, so event counts measure clicks and not unique people. Use users or sessions with the event to count people.
Adding coverage for unlisted extensions
When you need extensions that are not on the list, send a custom event. Use a different event name from the built-in one. Reusing file_download would mix your data with the automatic events. Match on the URL path so a query string does not hide the extension.
const extraExtensions = /\.(epub|dmg|apk|iso)$/i;
document.addEventListener('click', (event) => {
const link = event.target.closest('a[href]');
if (!link) return;
let url;
try {
url = new URL(link.href, window.location.href);
} catch (err) {
return;
}
const match = url.pathname.match(extraExtensions);
if (!match) return;
gtag('event', 'file_download_extra', {
file_extension: match[1].toLowerCase(),
file_name: url.pathname.split('/').pop(),
link_url: link.href,
link_text: link.textContent.trim()
});
});This code assumes the Google tag is already on the page, so gtag exists. It reuses the same parameter names as the built-in event. That keeps a custom dimension you register for file_extension working for both events.
For downloads started by a button, send the event at the moment your code starts the download:
document.querySelector('#export-report').addEventListener('click', () => {
gtag('event', 'file_download_extra', {
file_extension: 'csv',
file_name: 'report.csv',
link_text: 'Export report'
});
});Checking the event in DebugView
Turn on debug mode, then click a file link in a browser where the tag is active. The simplest way is the debug_mode option in the config call:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', { debug_mode: true });Open Admin > DebugView. After a click you should see file_download appear in the timeline. Select it and confirm that file_extension, file_name and link_url hold the values you expect. Test one link for each extension you care about, one link to a file on another domain, and one extensionless link you expect to be missed. Remove debug_mode when you finish testing.
Using downloads in reports
file_download appears in the Events report by name once it has data. To break it down by file, you need the parameters as dimensions.
- In Explorations, the dimension picker may already list
File name,File extension,Link URLandLink textfor enhanced measurement events. Check there first. - In standard reports, and wherever the parameter does not show up, register it. In Admin > Custom definitions, create an event-scoped custom dimension. Use a name like
File nameand set the event parameter tofile_name. Repeat forfile_extension. - A custom dimension collects data only from the time you create it. Past events are not filled in.
- GA4 limits how many custom dimensions a property can hold, so register only the parameters you will report on.
file_download is not a key event by default. If a download is a goal, such as a brochure request, open Admin > Events and mark the event as a key event. If only some downloads matter, create a new event from the existing one with a condition, for example file_name contains brochure, and mark that new event instead. Marking all downloads as key events inflates your conversion counts.
Common errors
- Expecting every download to be tracked. Server-generated downloads and JavaScript downloads need custom events.
- Adding the outbound and download counts together. One click can produce both events.
- Shipping a custom
file_downloadevent while enhanced measurement is on. Each click is then recorded twice. - Forgetting to register the parameters. The event is in GA4 and the file names are not in the reports.
- Treating
link_textas stable. Editors change link text, so group byfile_nameorfile_extensionwhen you want a steady report.
Exercise
Your site offers a report through the link <a href="/download?id=42">Get the report</a>. The server responds with a PDF. You have File downloads switched on in enhanced measurement, yet DebugView shows no file_download event after you click. Why, and what are two ways to fix it?
Show answer
The destination URL has no recognized file extension (it ends in "/download?id=42"), and enhanced measurement decides from the URL alone, not from the file the server returns. Fix it by changing the link or server so the URL path ends in the real file name, such as /files/report-42.pdf. Alternatively, send a custom event from a click handler, for example gtag('event', 'filedownloadextra', { fileextension: 'pdf', filename: 'report-42.pdf' }), and register its parameters as custom dimensions if you want to report on them.
Exercise
A PDF hosted on a separate document-hosting domain is linked from your pages. In DebugView, one click produces two events. Which two are they, and how should you treat them in reporting?
Show answer
The click produces a filedownload event and an outbound click event (click with outbound=true). They describe the same user action from two angles, so do not add their counts together. Use filedownload to measure downloads and the click event to measure outbound traffic.