Integration
Stripe affiliate tracking: attribute sales and pay commissions
Your affiliate program plugs into the Stripe account you already have. Sales, renewals and refunds flow in on their own, and commissions are calculated on what Stripe actually collected — not on an estimate.
Updated
What connecting Stripe actually does
An affiliate program needs to answer one question reliably: which affiliate brought this paying customer? Stripe already knows a payment happened. What it does not know is where the visitor came from three days earlier. Connecting the two is the entire job.
Two pieces do it. A snippet on your site remembers which affiliate link a visitor arrived through. A webhook on your Stripe account tells us when that visitor pays. Everything else — commission amounts, approval windows, payouts, invoices — follows from those two facts.
1. The tracking snippet
One tag, anywhere in your pages. It reads ?via=CODE from the URL, records the click, and sets a cookie:
<script src="https://earnwithaffiliate.com/snippet.js?program=your-slug" async></script>The cookie is set on your own domain, not ours. That is what makes the attribution survive ad blockers and the end of third-party cookies: from the browser's point of view it is your site remembering its own visitor, because the script runs inside your page even though the file is served from us.
2. Three ways a sale gets attributed
At checkout, the affiliate code has to reach Stripe. There are three routes, resolved in this order, and most merchants only ever use the second one.
- Checkout metadata — your backend reads the cookie and puts the code on the session and on
subscription_data.metadata. The most explicit route, and the one that carries attribution onto renewal invoices. client_reference_id, with no backend code — Stripe accepts this field on a Payment Link (as a URL parameter), a Buy Button and a Pricing Table (as an HTML attribute). The snippet fills it in itself, including on elements rendered after page load.- A tracked coupon — the fallback for when a customer used a promo code instead of clicking a link. Coupons are created in your Stripe account automatically.
The second route has one trap worth knowing about, because it is invisible when you get it wrong: client_reference_id lives only on the Checkout Session. Stripe does not copy it onto the subscription or onto later invoices. Handled naively, the first sale would be credited and then every recurring commission would silently stop. We keep the link on our side so renewals inherit the right affiliate.
3. The webhook, signed by your account
You add one endpoint in your Stripe dashboard. It is specific to your account and signed with its own secret — we verify every delivery against it, so an event that did not come from your Stripe is rejected rather than trusted.
These are the events that matter, and what each one does:
checkout.session.completed— the first sale. Creates the conversion and the affiliate's commission.invoice.paid— a renewal. Creates the recurring commission, inheriting the affiliate from the sale that opened the subscription.charge.refunded— voids the matching commission, or posts a negative adjustment if it was already paid out.charge.dispute.createdandcharge.dispute.closed— same treatment on a chargeback, and the reverse if you win the dispute.
The restricted key, and what it can't do
You also give us a Stripe restricted key. It exists so tracked coupons can be created in your account and so invoices can be read back. It is deliberately narrow:
- Coupons and Promotion codes — write
- Invoices — read
- Subscriptions and Customers — read, only if you import existing subscribers
It cannot read your balance, cannot create a payment, and cannot move money. If it stops working — revoked, rotated, expired — your dashboard says so with the date and the provider's own message, instead of showing a green badge that never turns back.
Coming from another affiliate tool
The day you switch, your existing subscribers keep renewing — but those renewals arrive with no attribution, because the snippet was not on your site when they first subscribed. Left alone, the affiliates who brought those customers stop being paid on the day of the migration.
We scan your live subscriptions and reattach each one to the affiliate who brought it, wherever the proof exists on Stripe's side. Analysis and import are two separate steps: you see who we are about to credit before anything is written.
Frequently asked questions
Do I have to change my site's code?
One script tag, and in most cases that is all. If you use a Stripe Payment Link, Buy Button or Pricing Table, the snippet decorates them itself and you write no backend code at all. If you create your checkout session server-side, it is a single line to copy.
Does it work with subscriptions?
Yes, and that is the main case. The first sale creates the initial commission; every renewal invoice creates a new one automatically, for as long as the customer stays subscribed. You choose whether your commission is recurring or paid once.
What permissions does my Stripe key need?
A restricted key is enough. It needs Coupons and Promotion codes write access (to create tracked coupons), Invoices read, plus Subscriptions and Customers read if you want to import your existing subscribers. It never needs access to your balance or the ability to create payments.
What happens if a customer is refunded?
Stripe notifies us, we find the original sale and the commission is voided before any payout. If it had already been paid to the affiliate, it is deducted from their next payout rather than claimed back — the original line is never rewritten.
Can I migrate from another tool?
Yes. We scan your live Stripe subscriptions and reattach each one to the affiliate who brought it, wherever the proof exists (metadata or tracked coupon). Renewals therefore keep paying commission after the migration. Nothing is retroactive: past commissions stay with the tool you are leaving.
Do payment details go through you?
No. The payment happens at Stripe, between you and your customer. We receive the event once it has happened, signed by your account, to know what to bill and which affiliate to credit.
Connect your Stripe and open your program
The free plan is enough to set everything up and check that a sale flows through correctly. No credit card.