Clycyo
How-to4 min read

How to Track File Downloads in Web Analytics

PDFs, whitepapers, and installers leave no pageview. Track downloads as events, attribute them to channels, and count real content ROI.

A PDF download leaves no pageview, no referrer trail, no trace — your whitepaper could be your best-performing asset or completely ignored, and default analytics cannot tell you which. One listener fixes it, and the resulting report regularly reorders content roadmaps.

The listener

const FILE_RE = /\.(pdf|zip|csv|xlsx?|docx?|pptx?|dmg|exe|tar\.gz|epub)$/i;

document.addEventListener('click', (e) => {
  const a = e.target.closest('a');
  if (!a) return;
  const href = a.getAttribute('href') || '';
  if (FILE_RE.test(href.split('?')[0])) {
    window.webanalytics?.track('file_download', {
      file: href.split('/').pop(),
      type: href.split('.').pop().toLowerCase(),
      page: location.pathname,
    });
  }
});

Splitting off the query string first keeps signed URLs from defeating the extension check. For downloads served via redirect endpoints (/download/report-2026), match on the path prefix instead.

The three reports that matter

  1. Downloads per asset: the raw ranking. Expect surprises — the quick checklist PDF routinely beats the 40-page flagship report.
  2. Download rate per hosting page: downloads ÷ pageviews. A page with 2% download rate has a presentation problem, not a content problem; scroll data tells you whether anyone even reached the link.
  3. Downloads per acquisition source: first-touch UTM is already on the visitor record, so 'which channel sends people who actually want the material' is a filter — the difference between traffic and audience.

Gated vs ungated, measured honestly

If you gate downloads behind an email form, the download event pairs naturally with the form event — and form tracking will show you the abandonment price of the gate. Many teams discover the ungated PDF plus a soft CTA inside it converts better than the form wall. Now you can test that with numbers instead of opinions.

Combined with outbound link tracking, this listener pair covers the two big blind spots of pageview-only analytics in under twenty lines — no tag manager, no plugin, cookieless throughout.