Cross-Domain Tracking

Track referrals across multiple domains and subdomains

Table of Contents

Cross-Domain Tracking

When your customer journey spans multiple domains, special configuration ensures affiliate tracking continues seamlessly. This guide covers common scenarios and solutions.

Common Scenarios

Subdomain Checkout

Marketing: yoursite.com
Checkout:  checkout.yoursite.com
App:       app.yoursite.com

Third-Party Checkout

Your site:      yoursite.com
Stripe hosted:  checkout.stripe.com

Multiple Domains

Main brand:     mainbrand.com
Product site:   product.com

Subdomain Tracking

How It Works

Cookies can be shared across subdomains when set correctly. AffiliateBase automatically configures cookies for subdomain sharing.

Automatic Configuration

The tracking script sets cookies at the root domain:

.yoursite.com → works on:
  - yoursite.com
  - www.yoursite.com
  - checkout.yoursite.com
  - app.yoursite.com

Setup Requirements

  1. Install tracking script on all subdomains
  2. Use the same organization ID
  3. Cookies will be shared automatically

Verification

Test by:

  1. Click affiliate link on yoursite.com
  2. Navigate to checkout.yoursite.com
  3. Check window.affiliatebase_referral still exists

Third-Party Checkout Pages

The Challenge

When checkout happens on a different domain (like checkout.stripe.com), cookies don’t transfer. The referral must be passed explicitly.

Solution: client_reference_id

Pass the referral ID to Stripe before redirecting:

// Before redirecting to Stripe
const referralId = window.affiliatebase_referral;

const session = await stripe.checkout.sessions.create({
  // ... other options
  client_reference_id: referralId,
});

// User redirects to checkout.stripe.com
// Referral is passed via the session, not cookies

For Stripe Payment Links, the tracking script automatically appends the referral:

Original: https://buy.stripe.com/xxxxx
Modified: https://buy.stripe.com/xxxxx?client_reference_id=referral-id

No additional configuration needed if the tracking script is installed.

Multiple Domains

Different Root Domains

Tracking doesn’t automatically work across different root domains:

mainbrand.com → product.com (cookies don't transfer)

Solution Options

Option 1: Pass referral in URL

When linking between domains, include the referral:

const referralId = window.affiliatebase_referral;
const targetUrl = `https://product.com?referral=${referralId}`;

Option 2: Use promo codes

Promo codes work regardless of domain:

Customer uses code "JOHN20" on product.com
→ Attributed to affiliate John

Option 3: Server-side tracking

Store referral server-side (in session/database) and retrieve on the other domain.

Handling Redirects

Preserving Parameters Through Redirects

If your site uses redirects, ensure tracking parameters are preserved:

Incoming: yoursite.com/?via=john
Redirect: yoursite.com/welcome?via=john  ✓ Good
Redirect: yoursite.com/welcome           ✗ Lost tracking

Common Redirect Issues

  • Marketing redirects stripping parameters
  • CMS/plugin redirects not preserving query strings
  • HTTPS upgrades dropping parameters

Single Page Applications (SPAs)

Client-Side Navigation

For SPAs, tracking must handle route changes:

// The script handles initial load
// For subsequent navigation, referral persists in cookies

// If manually navigating with a new referral:
window.history.pushState({}, '', '/?via=newaffiliate');
// Script will detect and update

React/Next.js/Vue

The tracking script works with SPAs:

  1. Install script in your app shell
  2. Initial page load captures referral
  3. Subsequent navigation maintains cookies

Testing Cross-Domain

Subdomain Test

  1. Set up tracking on both subdomains
  2. Click affiliate link on subdomain A
  3. Navigate to subdomain B
  4. Verify window.affiliatebase_referral exists

Different Domain Test

  1. Click affiliate link on domain A
  2. Manually pass referral to domain B
  3. Verify referral is captured on domain B

Limitations

What Doesn’t Work

  • Different browsers: Referral won’t transfer
  • Different devices: Referral won’t transfer
  • Incognito/Private mode: Cookies may not persist
  • Cookie blocking: Some browsers block third-party cookies

Workarounds

For challenging scenarios:

  1. Use promo codes as universal backup
  2. Capture email early for manual attribution
  3. Encourage customers to complete journey in one session

Best Practices

For Multi-Domain Setups

  1. Single source of truth: One domain captures initial referral
  2. Explicit passing: Always pass referral ID between domains
  3. Fallback methods: Use promo codes as backup
  4. Test thoroughly: Verify all paths work

For Subdomain Setups

  1. Consistent script: Same tracking script everywhere
  2. Same organization: Use same org ID across subdomains
  3. Test cookies: Verify cookies accessible on all subdomains

Troubleshooting

Referral Lost Between Subdomains

  1. Check cookie domain is set to root
  2. Verify both subdomains have script installed
  3. Check for cookie blocking in browser
  4. Look for CORS or security issues

Referral Lost at Checkout

  1. Verify client_reference_id is passed to Stripe
  2. Check referral existed before redirect
  3. Test in non-incognito browser
  4. Review Stripe session data

Next Steps