Skip to main content

How Affiliate Attribution Works

Follow an AffiliateBase referral from the public via token through browser tracking, Stripe Checkout, conversion, and commission creation.

Table of Contents

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 affiliate

How referrals are captured

When someone clicks an affiliate link like:

https://yoursite.com?via=affiliate-token
  1. The tracking script detects the via parameter and sends the token to AffiliateBase.
  2. AffiliateBase validates the token and creates a referral record, or updates the visitor’s existing referral.
  3. 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:

ValuePurpose
ab_referral_<account_id> cookieCurrent referral ID, visitor ID, affiliate, campaign, coupon, and approved hosts; the cookie expires when the referral does
ab_attribution:<account_id> local storageBackup referral state when cookie reads are limited
window.AffiliateBase.referral / window.affiliatebase_referralGenerated referral ID available to browser checkout code

Step 3: Conversion capture

When the visitor purchases:

  1. AffiliateBase sends the generated referral ID to Stripe automatically for Payment Links, Buy Buttons, and Pricing Tables on the same page.
  2. For backend-created Checkout Sessions, your browser code submits referral_id to your server.
  3. Your server passes that value to Stripe as client_reference_id and mirrored affiliatebase_referral_id metadata.
  4. A Stripe webhook notifies AffiliateBase.
  5. 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 credit

A 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:

  1. 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.
  2. Referral ID on the payment: the generated referral ID that your checkout passed to Stripe as client_reference_id.
  3. Existing customer: a referral already linked to the same Stripe customer.
  4. 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:

StateDescription
VisitorClicked a link or used a code, and has not signed up or paid
LeadThe tracking script’s identify call recorded the visitor’s email, so the referral is tied to a signup
ConversionA 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:

  1. The visitor did not sign up or buy before the attribution window ended.
  2. The visitor used a different browser or device.
  3. The generated referral ID was not passed to Stripe as client_reference_id.
  4. The tracking script is not on the pages that start checkout.
  5. The affiliate was rejected, disabled, banned, or archived before the first payment.

Wrong affiliate credited

Check:

  1. Which attribution model the campaign uses.
  2. Which affiliate’s eligible click owns the referral.
  3. Whether the customer used a promo code.
  4. The referral ID Stripe received on the checkout.
  5. The attribution window timing.

Best practices

For accurate attribution

  1. Install the script on all pages, not just landing pages.
  2. Pass the referral to checkout. Make sure Stripe receives the generated referral ID as client_reference_id.
  3. Use promo codes as backup for offline and cross-device purchases.
  4. Set an appropriate window that matches your sales cycle.

For fair attribution

  1. Communicate clearly. Tell affiliates how attribution works.
  2. Set reasonable windows. Avoid windows that are too short or too long.
  3. Be consistent. Apply the same rules to all affiliates in a campaign.
  4. Handle disputes fairly with a clear process.

Technical details

Read the referral ID in the browser

JavaScript
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

Esc