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:
- Detects affiliate parameters like
?ref=xyz
or?via=abc
- Creates a unique tracking ID (not the raw parameter value)
- Stores it as
affonso_referral
cookie - 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:
- Visit your site with our test affiliate parameter:
yoursite.com?atp=test
- Check your Affonso dashboard - you should see a new click registered
- In your browser DevTools → Application → Cookies → look for
affonso_referral
- 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