Background
⌘K

How Affiliate Tracking Works

Learn how Affonso's tracking script captures and remembers affiliate referrals to ensure accurate commission attribution.

Silvestro
Written by Silvestro
Updated more than a month ago

How Affiliate Tracking Works

The tracking script is the foundation of Affonso's affiliate system. It captures referral data when visitors arrive from affiliate links and ensures accurate commission attribution when they make purchases.

Why the Script Is Essential

When someone clicks an affiliate link, we need to remember where they came from. The tracking script:

  • Detects affiliate parameters in URLs
  • Generates a unique tracking identifier
  • Stores it securely in a cookie (affonso_referral)
  • Maintains attribution through the entire customer journey

Installation

Add this script to the <head> section of every page where users might land, sign up, or make purchases:

<!-- Place in <head> tag -->
<script
  async
  defer
  src="https://affonso.io/js/pixel.min.js"
  data-affonso="YOUR_PUBLIC_PROGRAM_ID"
  data-cookie_duration="YOUR_COOKIE_DURATION"
></script>

Configuration:

  • Replace YOUR_PUBLIC_PROGRAM_ID with your program ID from the Affonso dashboard
  • Set YOUR_COOKIE_DURATION to how many days the tracking should persist

Where to Install

The script should be added to:

  • Your main website / marketing pages (yourdomain.com)
  • Your application (app.yourdomain.com)
  • Any subdomains users visit during their journey

The script automatically syncs tracking data across all subdomains.

How It Works

Once installed, the script:

  1. Detects affiliate parameters like ?ref=xyz or ?via=abc
  2. Creates a unique tracking ID (not the raw parameter value)
  3. Stores it as affonso_referral cookie
  4. Exposes it via window.affonso_referral

This unique ID is what you'll pass to payment providers for commission tracking.

Critical Implementation Note

Never use URL parameters directly. Always use the cookie value we generate.

Correct approach:

const referralId = window.affonso_referral;

Incorrect approach:

const referralId = getUrlParam('via'); // Unreliable and inaccurate

We generate unique internal IDs for security and accurate attribution. URL parameters can be manipulated or lost during navigation.

Testing Your Integration

To verify the script is working:

  1. Visit your site with our test affiliate parameter: yoursite.com?atp=test
  2. Check your Affonso dashboard - you should see a new click registered
  3. In your browser DevTools → ApplicationCookies → look for affonso_referral
  4. The cookie value should be a unique ID like cmdhq6ayf05013mlrezo8yud9

If you see both a click in your Affonso dashboard and the cookie, your tracking is working correctly.

Next Steps

After installing the tracking script:

Need help? Contact us at support@affonso.io

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.