Skip to main content

How Attribution Works

Understanding how AffiliateBase tracks and attributes conversions to affiliates

Table of Contents

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

When someone clicks an affiliate link like:

https://yoursite.com?via=affiliate-token

The tracking script:

  1. Detects the via parameter
  2. Validates the affiliate token
  3. Creates a referral record
  4. Stores data in cookies

Step 2: Browser Storage

The tracking script stores the active referral in browser state:

ValuePurpose
ab_referral cookieCurrent referral ID, visitor ID, affiliate, campaign, coupon, and expiration data
ab_attribution local storage fallbackBackup 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 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. Stripe webhook notifies AffiliateBase.
  5. 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:

  1. Promo code (highest) - Customer entered affiliate’s code
  2. Referral cookie - Active referral from link click
  3. 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:

WindowUse Case
7 daysShort sales cycles
30 daysShorter SaaS or ecommerce evaluation
60 daysStandard default and longer consideration
90 daysHigh-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:

StateDescription
VisitorClicked link, hasn’t converted
LeadTook qualifying action
ConversionMade 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:

  1. Cookie expired (outside attribution window)
  2. Different browser/device used
  3. client_reference_id not passed to Stripe
  4. Tracking script not on checkout pages

Wrong Affiliate Credited

Check:

  1. Which attribution model the campaign uses
  2. Which affiliate’s eligible click owns the referral
  3. Was a promo code used?
  4. Cookie value at time of purchase
  5. Attribution window timing

Best Practices

For Accurate Attribution

  1. Install script on all pages - Not just landing pages
  2. Pass referral to checkout - Make sure Stripe receives the generated referral ID as client_reference_id
  3. Use promo codes as backup - For offline/cross-device
  4. Set appropriate window - Match your sales cycle

For Fair Attribution

  1. Communicate clearly - Explain how attribution works
  2. Set reasonable windows - Not too short, not too long
  3. Be consistent - Same rules for all affiliates
  4. 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