Blog

Tracking Downloads Using URI Redirects with Snowplow: A Robust Tutorial for Engineers

By
Snowplow Team
&
August 7, 2024
Share this post

Tracking asset downloads—PDFs, software installers, ZIP archives—is a common yet critical challenge for data teams focused on understanding user behavior. While JavaScript-based click tracking provides a baseline solution, it’s often unreliable due to modern browser behaviors and user navigation patterns.

In this guide, we walk through two approaches to tracking downloads with Snowplow:

  • Using JavaScript event listeners (standard but fragile)

  • Using Snowplow’s collector URI redirects (robust and reliable)

TL;DR: Use URI redirects for mission-critical download tracking where reliability is key.

Approach 1: Tracking Downloads with JavaScript Event Listeners

This is the most commonly used approach, especially when tracking downloads that originate from a click on a link or button.

Example

If you're using the Snowplow JavaScript Tracker, enabling link click tracking is straightforward:

window.snowplow('enableLinkClickTracking');

Make sure the link or button has a unique id or a distinguishable href so you can identify it in your downstream events:

<a id="whitepaper-download" href="/downloads/whitepaper.pdf">Download Whitepaper</a>

Limitations

This method is inherently fragile:

  • If clicking the link triggers a file download or redirects the user to another page (e.g., opening a PDF), the event might not be fired in time.

  • Mobile devices and browsers like Safari aggressively terminate scripts during navigation, causing tracking to fail silently.

Approach 2: Tracking Downloads with Snowplow Collector URI Redirects

To achieve high-reliability tracking, we recommend using collector-based URI redirects—a feature available in the Scala and Clojure Snowplow collectors.

How It Works

  1. Replace the direct download link with a Snowplow collector link that includes the /r/tp2 redirect path.

  2. Add the final destination (actual asset URL) as the value of the u query parameter.

  3. Optionally append tracking parameters from the Tracker Protocol to enrich the event.

Example

Let’s say you want to track a download for:

http://mydomain.com/assets/my-excellent-guide.pdf

Step 1: URL-encode the destination URL

Using a tool like urlencoder.io:

http%3A%2F%2Fmydomain.com%2Fassets%2Fmy-excellent-guide.pdf

Step 2: Build the tracking URL

<a href="http://collector.mydomain.com/r/tp2?u=http%3A%2F%2Fmydomain.com%2Fassets%2Fmy-excellent-guide.pdf&e=se&se_ca=download&se_ac=downloaded-my-excellent-guide">Download here</a>

This link will:

  • Fire a Snowplow structured_event (e=se)

  • Include a category (se_ca=download)

  • Include a specific action (se_ac=downloaded-my-excellent-guide)

  • Redirect the user to the final asset

Benefits

  • 100% reliability: The collector captures the event before the redirect.

  • Zero JavaScript dependency: Works even for users with JavaScript disabled.

  • Simple implementation: Minimal HTML changes required.

Dealing with Missing domain_userid in Redirect Events

One limitation of collector redirects is that they typically don’t populate the domain_userid, especially when third-party cookies are blocked by browsers like Safari or Firefox.

Solutions

1. Use a first-party collector domain

Host your collector on a subdomain of your main site (e.g. collector.mysite.com). This ensures the network_userid cookie is set as a first-party cookie, maximizing reliability.

2. Pass domain_userid manually

You can extract the domain_userid value from the JavaScript tracker using:

window.snowplow('getDomainUserId', function(userId) {
  // append to redirect link
});
Then append this as a duid parameter to the redirect URL:
...&duid=YOUR_DOMAIN_USERID

Cross-Domain Tracking and Cookie Lifespans

For organizations tracking users across multiple domains, using a single first-party cookie becomes challenging due to modern browser restrictions:

  • Safari (ITP) restricts even first-party cookies to a 7-day lifespan.

  • Chrome/Edge still allow up to 2 years, but this is changing fast.

To stitch sessions across domains, we recommend:

  • Implementing cross-domain tracking

  • Avoiding reliance on third-party cookies entirely

For a full breakdown of browser cookie policies, refer to CookieStatus.com.

Summary: When to Use Which Approach

Scenario / Recommended Method

Basic link clicks (e.g. CTA button) / JavaScript click tracking

Critical downloads (e.g. whitepapers, software) / Collector URI redirect

No JavaScript support / Collector URI redirect

Tracking across multiple domains / First-party collector + cross-domain tracking

Additional Reads

Final Thoughts

Snowplow’s collector redirect functionality offers a production-grade solution for download tracking. Combined with first-party cookie strategy and Tracker Protocol flexibility, Snowplow empowers engineering teams to capture behavioral data with precision—even in a post-cookie world.

Subscribe to our newsletter

Get the latest content to your inbox monthly.

Get Started

Whether you’re modernizing your customer data infrastructure or building AI-powered applications, Snowplow helps eliminate engineering complexity so you can focus on delivering smarter customer experiences.