Stripe powers payments for millions of SaaS businesses, but it doesn't include native affiliate tracking. You need additional tools to connect affiliate referrals to Stripe conversions.
This guide explains how affiliate tracking works with Stripe, your options for implementation, and best practices for accurate attribution.
How Stripe Affiliate Tracking Works
The Basic Flow
- Visitor clicks affiliate link → Tracking cookie stored in browser
- Visitor browses your site → Cookie persists
- Visitor signs up → Customer created (may or may not involve payment yet)
- Visitor pays via Stripe → Payment successful
- Attribution happens → System connects payment to original affiliate click
- Commission calculated → Affiliate credited for the conversion
The technical challenge: connecting step 1 (click) to step 4 (Stripe payment) when they might be days or weeks apart.
What Needs to Connect
Affiliate tracking system must know:
- Which affiliate link was clicked
- When it was clicked
- The visitor's identity (usually a cookie)
Stripe must know:
- Customer identity
- Payment details
- Subscription status
Your system must bridge these:
- Connect visitor (cookie) to customer (email/ID)
- Pass customer identity to affiliate system
- Track ongoing payments for recurring commissions
Implementation Options
Option 1: Purpose-Built Affiliate Software (Recommended)
Platforms like PromoteKit, Rewardful, or FirstPromoter handle the entire integration:
How it works:
- Add a tracking script to your site
- Connect your Stripe account via OAuth
- The platform handles attribution automatically
Advantages:
- Minimal development required
- Handles edge cases (trials, upgrades, refunds)
- Webhook management included
- Dashboard and reporting built-in
- Recurring commission tracking automatic
Best for: Most SaaS businesses. Unless you have unique requirements, purpose-built software is the right choice.
Option 2: Affiliate Networks
Platforms like ShareASale, CJ Affiliate, or Impact use postback/pixel tracking:
How it works:
- Add network's tracking pixel to your site
- Fire a conversion pixel when payment occurs
- Pass order details (amount, order ID) to the network
Advantages:
- Access to network's affiliate base
- Established trust among affiliates
Disadvantages:
- Designed for e-commerce, not SaaS subscriptions
- Recurring commission tracking often manual
- Higher fees
- Less control
Best for: Companies wanting access to established affiliate networks, primarily selling one-time products.
Option 3: Build In-House
Create your own tracking system:
Required components:
- Tracking script to drop and read cookies
- Database to store click data
- Stripe webhook handlers for payments
- Attribution logic to connect clicks to payments
- Affiliate dashboard
- Payout management system
Advantages:
- Complete control
- No ongoing software costs
- Customization for unique needs
Disadvantages:
- Significant development time (weeks to months)
- Ongoing maintenance burden
- Edge cases are complex
- Opportunity cost vs. core product
Best for: Very large programs with unique requirements or engineering capacity to spare.
Technical Implementation Details
Tracking Script
The tracking script runs on your marketing site and handles:
Cookie setting:
// Simplified example
function setAffiliateCookie(affiliateId) {
document.cookie = `affiliate=${affiliateId}; max-age=7776000; path=/`;
// 90-day cookie (7776000 seconds)
}
// Parse referral from URL
const urlParams = new URLSearchParams(window.location.search);
const affiliateId = urlParams.get('ref');
if (affiliateId) {
setAffiliateCookie(affiliateId);
}
Key considerations:
- Use first-party cookies (set on your domain)
- Set appropriate duration (30-90 days typical)
- Handle multiple affiliate touches (first-click vs. last-click)
Connecting Visitor to Customer
When a visitor becomes a customer, connect their cookie to their account:
At signup:
// Read affiliate cookie
function getAffiliateCookie() {
const match = document.cookie.match(/affiliate=([^;]+)/);
return match ? match[1] : null;
}
// Include in signup request
const affiliateId = getAffiliateCookie();
if (affiliateId) {
// Pass to your backend with signup data
signupData.referredBy = affiliateId;
}
In your backend:
// When creating Stripe customer
const customer = await stripe.customers.create({
email: user.email,
metadata: {
affiliate_id: user.referredBy || '',
signup_date: new Date().toISOString()
}
});
Storing the affiliate ID in Stripe customer metadata allows attribution when payments occur.
Stripe Webhooks
Listen for Stripe events to track conversions:
Essential events:
checkout.session.completed— New purchaseinvoice.paid— Subscription paymentcustomer.subscription.created— New subscriptioncustomer.subscription.updated— Plan changescustomer.subscription.deleted— Cancellationcharge.refunded— Refund (reverse commission)
Webhook handler example:
app.post('/webhooks/stripe', async (req, res) => {
const event = stripe.webhooks.constructEvent(
req.body,
req.headers['stripe-signature'],
webhookSecret
);
switch (event.type) {
case 'invoice.paid':
const invoice = event.data.object;
const customer = await stripe.customers.retrieve(invoice.customer);
const affiliateId = customer.metadata.affiliate_id;
if (affiliateId) {
await recordCommission({
affiliateId,
amount: invoice.amount_paid,
invoiceId: invoice.id,
customerId: customer.id
});
}
break;
case 'charge.refunded':
// Reverse commission
break;
}
res.json({ received: true });
});
Handling Subscription Lifecycle
SaaS subscriptions have complex lifecycles. Your tracking must handle:
Trials:
- Customer signs up (affiliate ID captured)
- Trial period (no payment yet)
- Trial converts (first payment → commission)
- Trial expires (no commission)
Upgrades/Downgrades:
- Customer upgrades plan → Increased commission
- Customer downgrades → Decreased commission
- Handle prorations correctly
Cancellations:
- Subscription canceled → Stop future commissions
- Customer reactivates → Resume commissions (same affiliate?)
Refunds:
- Full refund → Reverse commission
- Partial refund → Partial reversal
- Chargeback → Reverse commission
This complexity is why purpose-built software is valuable—these edge cases take significant time to handle correctly.
Attribution Models
Last-Click Attribution (Standard)
The last affiliate link clicked before conversion gets credit.
Pros:
- Simple to implement
- Clear, unambiguous
- Industry standard
Cons:
- May not credit affiliate who introduced customer
- Can be gamed with late-stage cookie stuffing
First-Click Attribution
The first affiliate link clicked gets credit, regardless of later clicks.
Pros:
- Credits discovery
- Rewards content that introduces customers
Cons:
- Doesn't credit later influence
- Old cookies may attribute unrelated conversions
Time-Based Weighting
Recent clicks weighted more heavily than older clicks.
Pros:
- Balances recency and introduction
- More nuanced attribution
Cons:
- Complex to implement
- Harder to explain to affiliates
Recommendation
Start with last-click attribution. It's simple, understood, and works well enough for most programs. Consider more complex models only if you have clear evidence they'd be more accurate.
Best Practices
Use First-Party Cookies
Third-party cookies are being phased out. Set cookies on your own domain:
Good: cookie set on yourdomain.com
Problematic: cookie set on affiliatetracker.com
Store Affiliate ID in Stripe Metadata
Always store the affiliate ID on the Stripe customer:
await stripe.customers.create({
email: email,
metadata: {
affiliate_id: affiliateId,
referred_at: new Date().toISOString()
}
});
This creates a persistent record that survives cookie clearing.
Handle Missing Attribution Gracefully
Not every customer will have affiliate attribution. Don't break your flow:
const affiliateId = customer.metadata?.affiliate_id;
if (affiliateId) {
await processCommission(affiliateId, payment);
}
// Continue regardless
Test Thoroughly
Before launch, verify:
- Clicks are tracked correctly
- Cookies persist appropriately
- Customer creation captures affiliate ID
- Payments trigger commission recording
- Refunds reverse commissions
- Cancellations stop future commissions
- Upgrades/downgrades handled correctly
Monitor for Issues
After launch, watch for:
- Missing attributions (affiliate complaints)
- Duplicate attributions
- Webhook failures
- Cookie problems
Set up alerts for anomalies.
Common Integration Issues
Cookie Blocked or Cleared
Problem: Visitor clicks affiliate link but cookie is blocked (Safari ITP, privacy extensions) or cleared before conversion.
Solutions:
- Use first-party cookies
- Offer coupon codes as backup attribution
- Store click data server-side with visitor fingerprint (limited reliability)
Long Conversion Cycles
Problem: Customer converts after cookie expires.
Solutions:
- Extend cookie duration (90-180 days)
- Capture email early and attribute later
- Accept some unattributed conversions
Multiple Devices
Problem: Customer clicks on mobile, purchases on desktop.
Solutions:
- Account-based tracking (link affiliate to account, not just cookie)
- Coupon codes
- Accept some cross-device attribution loss
Webhook Reliability
Problem: Stripe webhooks occasionally fail or arrive out of order.
Solutions:
- Implement idempotency (don't double-count)
- Retry logic with exponential backoff
- Reconciliation jobs to catch missed events
Choosing Your Approach
Use Purpose-Built Software If:
- You want to launch quickly (days, not weeks)
- You don't have unique tracking requirements
- You prefer to focus on your core product
- You value reliability over customization
Recommended: PromoteKit for Stripe-native tracking.
Build In-House If:
- You have highly unique attribution requirements
- You have engineering capacity to invest
- You're willing to maintain the system long-term
- You want complete control
Use Affiliate Networks If:
- You want access to established affiliate bases
- You're primarily selling one-time products
- You're comfortable with higher fees and less control