How Attribution Works
Attribution is the process of connecting a sale to the affiliate who referred the customer. Understanding how attribution works helps you configure your program and set fair expectations with affiliates.
The Attribution Flow
1. Visitor clicks affiliate link
↓
2. Tracking script captures referral
↓
3. Cookie stored in browser
↓
4. Visitor browses, maybe leaves
↓
5. Visitor returns, makes purchase
↓
6. Referral ID passed to Stripe
↓
7. Conversion attributed to affiliate
How Referrals Are Captured
Step 1: Affiliate Link Click
When someone clicks an affiliate link like:
https://yoursite.com?via=affiliate-token
The tracking script:
- Detects the
viaparameter - Validates the affiliate token
- Creates a referral record
- Stores data in cookies
Step 2: Cookie Storage
Three cookies are set:
| Cookie | Purpose | Accessible |
|---|---|---|
visitor_id | Unique visitor tracking | Server only |
aff_{campaign} | Campaign-specific tracking | Server only |
ab_referral | Referral data for checkout | JavaScript |
Step 3: Conversion Capture
When the visitor purchases:
- Your checkout reads
window.affiliatebase_referral - Passes it to Stripe as
client_reference_id - Stripe webhook notifies AffiliateBase
- Conversion matched to original referral
- Commission created for affiliate
Attribution Models
Last-Click Attribution (Default)
The last affiliate link clicked gets credit:
Day 1: Click Affiliate A's link
Day 3: Click Affiliate B's link
Day 5: Purchase
Result: Affiliate B gets credit
First-Click Attribution
Configure to credit the first affiliate instead:
Day 1: Click Affiliate A's link
Day 3: Click Affiliate B's link
Day 5: Purchase
Result: Affiliate A gets credit
Attribution Priority
When multiple attribution methods exist, priority order:
- Promo code (highest) - Customer entered affiliate’s code
- Referral cookie - Active referral from link click
- None - No attribution
This means if a customer clicks one affiliate’s link but uses another’s promo code, the promo code affiliate gets credit.
Attribution Window
The attribution window (cookie duration) determines how long after a click an affiliate can get credit:
| Window | Use Case |
|---|---|
| 7 days | Short sales cycles |
| 30 days | Standard (default) |
| 60 days | Longer consideration |
| 90 days | High-ticket items |
After the window expires, new clicks reset attribution. Existing referrals are frozen (no new conversions attributed).
Cross-Session Tracking
Same Device, Same Browser
Tracking works seamlessly:
- Cookies persist across sessions
- Referral maintained on return visits
- No action needed
Different Browsers or Devices
Tracking has limitations:
- Cookies are browser-specific
- Phone → Desktop loses attribution
- Incognito mode loses attribution
Workarounds
For better cross-device tracking:
- Encourage customers to use same device
- Use promo codes as backup
- Capture email early for manual attribution
Referral States
Referrals progress through states:
| State | Description |
|---|---|
| Visitor | Clicked link, hasn’t converted |
| Lead | Took qualifying action |
| Conversion | Made a purchase |
| Frozen | Attribution window expired |
What Gets Tracked
Visitor Data
When a referral is created:
- IP address (for fraud detection)
- User agent (browser/device)
- Referrer URL
- Landing page
- Timestamp
Conversion Data
When purchase completes:
- Order amount
- Product purchased
- Customer email
- Payment status
Attribution Troubleshooting
Conversion Not Attributed
Common causes:
- Cookie expired (outside attribution window)
- Different browser/device used
client_reference_idnot passed to Stripe- Tracking script not on checkout pages
Wrong Affiliate Credited
Check:
- Which affiliate’s link was clicked last
- Was a promo code used?
- Cookie value at time of purchase
- Attribution window timing
Best Practices
For Accurate Attribution
- Install script on all pages - Not just landing pages
- Pass referral to checkout - Always include
client_reference_id - Use promo codes as backup - For offline/cross-device
- Set appropriate window - Match your sales cycle
For Fair Attribution
- Communicate clearly - Explain how attribution works
- Set reasonable windows - Not too short, not too long
- Be consistent - Same rules for all affiliates
- Handle disputes fairly - Have a clear process
Technical Details
How Cookies Work
// Reading the referral cookie
const referralId = window.affiliatebase_referral;
// The cookie contains:
{
referral_id: "abc123",
affiliate_id: "def456",
campaign_id: "ghi789",
expires: "2024-02-15T00:00:00Z"
}
How Stripe Integration Works
// Checkout session with attribution
const session = await stripe.checkout.sessions.create({
// ... other options
client_reference_id: referralId, // This connects the sale to the referral
});
Next Steps
- Configure attribution windows
- Learn about tracking parameters
- Set up conversion tracking