Background
⌘K

How Affiliate Tracking Works

Learn what the Affonso tracking script stores, where to install it, and when to switch to first-party delivery.

Silvestro
Written by Silvestro
Last updated on June 12, 2026

How Affiliate Tracking Works

When a visitor arrives through an affiliate link, Affonso needs a reliable way to remember that referral until the user signs up or buys.

The tracking script handles that attribution step.

What the Script Does

When the script runs, it:

  1. detects affiliate parameters in the URL
  2. creates an internal referral ID
  3. stores that ID in the affonso_referral cookie
  4. makes the same ID available as window.affonso_referral

That referral ID is what you should pass into your signup or checkout flow for attribution.

Standard Installation

For most setups, use the hosted script:

<script
  async
  defer
  src="https://cdn.affonso.io/js/pixel.min.js"
  data-affonso="YOUR_PUBLIC_PROGRAM_ID"
  data-cookie_duration="30"
></script>

Replace:

  • YOUR_PUBLIC_PROGRAM_ID with your program ID from the Affonso dashboard
  • 30 with your preferred cookie duration in days

When to Switch to First-Party Delivery

Stay on the hosted script unless you have a real problem with blockers, privacy tools, or browser restrictions.

If the hosted script is blocked, switch to the first-party delivery guide and proxy the script and tracking requests through your own domain.

The prefix is configurable. /affonso is not required.

Where to Install the Script

Install the script on every page or subdomain where a referred visitor can move before signup or purchase.

That usually means:

  • your marketing site
  • your app
  • any checkout, onboarding, or pricing pages involved in the conversion path

If users cross domains or subdomains during the journey, make sure the script is present wherever attribution needs to survive.

Important: Use the Referral ID, Not the Raw URL Parameter

Do not read the raw affiliate parameter from the URL.

Use this instead:

const referralId = window.affonso_referral;

That value is the stable internal referral ID created by Affonso. It is safer and more reliable than reading the original query parameter directly.

If you need cookie consent before storing the referral cookie, enable consent mode and follow the GDPR guide.

That changes how the cookie is stored, but not the overall attribution flow.

Quick Test

  1. Visit your site with ?atp=test
  2. Check that a click appears in your Affonso dashboard
  3. In DevTools, confirm the affonso_referral cookie exists
  4. Confirm window.affonso_referral is available on the page

If all four checks pass, your tracking setup is working.

Next Steps

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.