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:
- detects affiliate parameters in the URL
- creates an internal referral ID
- stores that ID in the
affonso_referralcookie - 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_IDwith your program ID from the Affonso dashboard30with 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.
Consent Mode
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
- Visit your site with
?atp=test - Check that a click appears in your Affonso dashboard
- In DevTools, confirm the
affonso_referralcookie exists - Confirm
window.affonso_referralis available on the page
If all four checks pass, your tracking setup is working.


