Attribution connects a Stripe sale to the affiliate who referred the customer. This article is for merchants and explains how AffiliateBase captures a referral, which referral wins when several apply, how long a referral lasts, and how a referral moves from visitor to lead to conversion.
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 affiliateHow 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 and sends the token to AffiliateBase. - AffiliateBase validates the token and creates a referral record, or updates the visitor’s existing referral.
- The tracking script stores the referral in the browser.
For the parameters the script reads and the rules a token must meet, see Affiliate Tracking URL Parameters.
Step 2: Browser storage
The tracking script stores the active referral in browser state:
| Value | Purpose |
|---|---|
ab_referral_<account_id> cookie | Current referral ID, visitor ID, affiliate, campaign, coupon, and approved hosts; the cookie expires when the referral does |
ab_attribution:<account_id> local storage | 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 code submits
referral_idto your server. - Your server passes that value to Stripe as
client_reference_idand mirroredaffiliatebase_referral_idmetadata. - A Stripe webhook notifies AffiliateBase.
- AffiliateBase matches the conversion to the original referral and creates a commission when eligible.
Attribution model
Last-click attribution
Campaigns default to last-click attribution (Attribution model on the campaign form). The last eligible affiliate link the visitor clicked gets credit:
Day 1: Click Affiliate A's link
Day 3: Click Affiliate B's link
Day 5: Purchase
Result: Affiliate B gets creditA campaign can instead use first-click attribution. In that mode, the first eligible click in the campaign keeps ownership until the referral expires or is deactivated. Later clicks on other affiliates’ links in the same campaign do not change the owner.
Attribution priority
When a Stripe payment arrives, AffiliateBase picks the referral for the sale in this order:
- Promo code: if the payment used an affiliate’s promo code, that code’s affiliate gets credit. The exception is when the referral ID on the payment already belongs to the same affiliate.
- Referral ID on the payment: the generated referral ID that your checkout passed to Stripe as
client_reference_id. - Existing customer: a referral already linked to the same Stripe customer.
- None: no attribution, and no commission.
If a customer clicks one affiliate’s link but uses another affiliate’s promo code, the promo code’s affiliate gets credit.
Attribution window
The attribution window (cookie duration) sets how long after a click a visitor can sign up or buy and still credit the affiliate. Set it per campaign in Days before referrals expire (Referral window during Setup). Any whole number of days from 1 up is accepted; common choices are 30, 60, and 90 days.
A visitor who has not signed up or bought by the end of the window can no longer credit the affiliate through that referral. A new eligible click starts a new window. A visitor who signs up inside the window keeps crediting the affiliate when they pay later. See Affiliate Attribution Window for the full rules.
Cross-session tracking
Same device, same browser
Tracking works without extra setup:
- Cookies persist across sessions
- The referral carries over to return visits
- No action needed
Different browsers or devices
Tracking has limits:
- Cookies are browser-specific
- Phone to desktop loses attribution
- Incognito mode loses attribution
Workarounds
To improve cross-device tracking:
- Encourage customers to use the same device.
- Use promo codes as backup.
- Call
affiliatebase('identify', { email })at signup so the referral is tied to the customer’s email. See Affiliate Tracking and Attribution Reference.
Referral states
Referrals move through these states:
| State | Description |
|---|---|
| Visitor | Clicked a link or used a code, and has not signed up or paid |
| Lead | The tracking script’s identify call recorded the visitor’s email, so the referral is tied to a signup |
| Conversion | A verified Stripe payment was matched to the referral |
A referral only moves forward: visitor to lead to conversion, and it can go from visitor straight to conversion when a payment arrives without an earlier signup call. A referral never moves backward. 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 a purchase completes:
- Order amount
- Product purchased
- Customer email
- Payment status
Attribution troubleshooting
Conversion not attributed
Common causes:
- The visitor did not sign up or buy before the attribution window ended.
- The visitor used a different browser or device.
- The generated referral ID was not passed to Stripe as
client_reference_id. - The tracking script is not on the pages that start checkout.
- The affiliate was rejected, disabled, banned, or archived before the first payment.
Wrong affiliate credited
Check:
- Which attribution model the campaign uses.
- Which affiliate’s eligible click owns the referral.
- Whether the customer used a promo code.
- The referral ID Stripe received on the checkout.
- The attribution window timing.
Best practices
For accurate attribution
- Install the script on all pages, not just landing pages.
- Pass the referral to checkout. Make sure Stripe receives the generated referral ID as
client_reference_id. - Use promo codes as backup for offline and cross-device purchases.
- Set an appropriate window that matches your sales cycle.
For fair attribution
- Communicate clearly. Tell affiliates how attribution works.
- Set reasonable windows. Avoid windows that are too short or too long.
- Be consistent. Apply the same rules to all affiliates in a campaign.
- Handle disputes fairly with a clear process.
Technical details
Read the referral ID in the browser
const referralId = window.AffiliateBase?.referral || window.affiliatebase_referral;How the 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