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. Referral state stored in the 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: Browser Storage
The tracking script stores the active referral in browser state:
| Value | Purpose |
|---|---|
ab_referral cookie | Current referral ID, visitor ID, affiliate, campaign, coupon, and expiration data |
ab_attribution local storage fallback | Backup referral state when cookie reads are limited |
window.AffiliateBase.referral / window.affiliatebase_referral | Generated referral ID available to browser checkout code |
Step 3: Conversion Capture
When the visitor purchases:
- AffiliateBase sends the generated referral ID to Stripe automatically for Payment Links, Buy Buttons, and Pricing Tables on the same page.
- For backend-created Checkout Sessions, your browser submits
referral_idto your server. - Your server passes that value to Stripe as
client_reference_idand mirroredaffiliatebase_referral_idmetadata. - Stripe webhook notifies AffiliateBase.
- Conversion is matched to the original referral and a commission is created when eligible.
Attribution Model
Last-click attribution
Campaigns default to last-click attribution. The last eligible 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
Campaigns can also use first-click attribution. In that mode, the first eligible click in the campaign keeps ownership until the referral expires or is deactivated.
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 | Shorter SaaS or ecommerce evaluation |
| 60 days | Standard default and longer consideration |
| 90 days | High-ticket items |
After the window expires, that referral can no longer receive new conversions. A new eligible click can create a new referral window.
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 to 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 |
Referrals can also be frozen or deactivated by policy; frozen or deactivated referrals cannot advance to lead or conversion.
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 attribution model the campaign uses
- Which affiliate’s eligible click owns the referral
- 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 - Make sure Stripe receives the generated referral ID as
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
const referralId = window.AffiliateBase?.referral || window.affiliatebase_referral;
How Stripe Integration Works
For Stripe-hosted links and components, keep the Stripe link, Buy Button, or Pricing Table on the same page as the AffiliateBase script. AffiliateBase sets client_reference_id automatically after a valid referred visit. Standard buy.stripe.com and link.payment links are detected automatically; add data-affiliatebase to custom Payment Link anchors when AffiliateBase should own client_reference_id.
For custom Checkout Sessions, submit the generated referral ID from the browser to your server before creating the Stripe Session.
Next steps
- Configure attribution windows
- Learn about tracking parameters
- Set up Stripe conversion mapping