How to Track Affiliate Referrals with Stripe
Why Stripe Affiliate Tracking Needs Webhooks
The naive approach to affiliate tracking with Stripe is to fire a JavaScript event on your thank-you page when a checkout completes. The problem: users close the tab early, adblockers fire, Stripe Checkout redirects fail, and you end up missing 20–40% of conversions.
The correct approach is server-side: Stripe sends a webhook to your tracking tool when a payment succeeds, and the tracker records the conversion regardless of what the browser does. This is what Trackli uses — and it's the only reliable method for subscription businesses.
How the Attribution Chain Works
Here's the flow from click to commission:
- Affiliate shares their unique link — e.g.,
yourapp.com/yourslug/affiliatename - Visitor clicks the link. Trackli records the click and sets a
refcookie/parameter. - Visitor signs up. Your app stores the
refcode on the user record or passes it as a Stripe metadata field. - Visitor subscribes. Stripe fires a
checkout.session.completedorcustomer.subscription.createdwebhook. - Trackli receives the webhook, reads the
reffrom Stripe metadata, and creates a commission record for the affiliate.
The key step is passing the ref code into Stripe metadata at checkout creation. Here's how that looks in a Node.js backend:
const session = await stripe.checkout.sessions.create({
...
metadata: {
trackli_ref: req.session.affiliateRef || "",
},
});
Setting Up the Stripe Webhook in Trackli
In Trackli, go to Settings → Integrations → Stripe. Trackli will give you a webhook endpoint URL. In your Stripe dashboard:
- Go to Developers → Webhooks → Add endpoint
- Paste the Trackli webhook URL
- Select the events:
checkout.session.completed,customer.subscription.created,invoice.payment_succeeded - Copy the signing secret and paste it into Trackli
That's it. From this point, every Stripe payment that includes a trackli_ref in its metadata will automatically create a commission record.
Handling Trials and Delayed Conversions
Many SaaS products offer a free trial. The affiliate referral happens at signup, but the conversion (first payment) happens days or weeks later. Trackli handles this by storing the ref code at signup and then matching it when the first invoice pays — even if the webhook fires 30 days later.
You just need to make sure the ref code is stored on the Stripe customer record at the time of trial creation, not just the checkout session:
await stripe.customers.update(customerId, {
metadata: { trackli_ref: affiliateRef },
});
Recurring Commissions
If you're paying affiliates a percentage of recurring revenue, Trackli can be configured to create a commission on every invoice.payment_succeeded event, not just the first one. This makes recurring commissions fully automatic — affiliates get credited every month without any manual work on your end.
Testing Your Setup
Use Stripe's test mode to verify the integration before going live. Send a test webhook from the Stripe dashboard and confirm the commission appears in your Trackli dashboard. Check that the affiliate attribution is correct and the commission amount matches your configured rate.
Once you're confident in test mode, switch to live mode. Your first real affiliate conversion should appear in Trackli within seconds of the Stripe payment completing.
Start your free Trackli account and connect Stripe in minutes.

