Stripe affiliate tracking, from link to payout.

AffiliateTracking does Stripe affiliate tracking for Payment Links, the Pricing Table, the Buy Button and your own Checkout Sessions. Add one script tag to your site, connect Stripe, and every sale, renewal and refund lands in the ledger.

Payment Links: no extra codeSubscriptions and renewalsRefunds claw back

What the script does to a Payment LinkExample
Your linkhttps://buy.stripe.com/7sI5kQ
After t.js, for a visitor from Janehttps://buy.stripe.com/7sI5kQ?client_reference_id=at1_…
When they paycheckout.session.completed → Jane's commission, checked by 13 fraud rules

A Stripe Payment Link before and after the script. Example data.

From click to commission

How a Stripe sale finds its affiliate

Four steps, and you only set up the first two once.

  1. 01The click

    A visitor opens an affiliate's link. It records the click and sends them to your site with a signed token.

  2. 02The script keeps it

    t.js saves the token in a cookie on your own domain for the length of your attribution window, then tidies the address bar.

  3. 03Checkout carries it

    Payment Links, the Pricing Table and the Buy Button get it automatically. Your own Checkout Sessions pass it as metadata.

  4. 04Stripe tells us

    The webhook arrives, the 13 fraud rules run, and the commission lands or waits on hold with the evidence.

Setup for each kind of Stripe checkout

Start with the script tag on every page of your site, right before </head>. Then it depends on how you sell.

Payment Links, Pricing Table, Buy Button

  • Nothing else to do. The script adds the token to buy.stripe.com links, <stripe-pricing-table> and <stripe-buy-button>
  • One-time and subscription checkouts both count. Trials count on their first paid invoice
  • A client_reference_id you set yourself is left alone

Your own Checkout Sessions

  • Read the at_token cookie on your server when you create the session
  • One-time payment: pass it as metadata[aff_token]
  • Subscription: pass it as subscription_data[metadata][aff_token], so every invoice carries it
  • App on another subdomain? The cookie stays on the host that set it, so send AffiliateTracking.token() from the browser instead

Connect Stripe

Cloud does it with one key. Self-host takes a webhook you add yourself.

On cloud: paste one restricted key

  • Create a restricted key (rk_) with Webhook Endpoints: Write and Checkout Sessions: Read
  • Paste it in your workspace settings. We create the webhook on your account with only the events we need
  • Reconnecting replaces our endpoint instead of adding another. Disconnecting deletes it
  • It refuses a full secret key (sk_), on purpose

On self-host: add the webhook

  • In Stripe, add an endpoint at https://your-host/webhooks/stripe
  • Pick the first 7 events in the table below. On webhook API versions from 2025-03-31, add invoice_payment.paid too
  • Set AE_STRIPE_SECRET to its signing secret, the one starting whsec_. Not your API key
  • Restart, and Stripe events start counting

What each Stripe event does

Every event has to pass Stripe's signature check first, and it counts once, however many times Stripe sends it.

Checked against the code on . On cloud, the restricted key subscribes your webhook to the first 7 events and keeps the list current.
Stripe eventWhat AffiliateTracking does
checkout.session.completedA paid one-time checkout earns a commission. A subscription checkout links the customer to the affiliate for life.
checkout.session.async_payment_succeededDelayed payment methods, like bank debits, earn a commission once the money arrives.
invoice.paidThe first invoice, every renewal and upgrade invoices earn a commission for the linked affiliate.
charge.refundedTakes back the same share of the commission. Partial refunds take back part of it.
charge.dispute.funds_withdrawnA chargeback takes back the disputed share of the commission, like a refund.
charge.dispute.funds_reinstatedLogged. If you win the dispute, the commission stays taken back; add it again by hand if the partner should keep it.
invoice_payment.paidOnly for webhook API versions from 2025-03-31: links an invoice to its payment, so refunds of subscription invoices take their commission back too.
customer.subscription.deletedLogged. Renewals stop on their own because no more invoices arrive.

Sell more than one thing on Stripe? Pick which sales count

If your Stripe account sells several products, list the ones your affiliates earn on. Sales of anything else earn nothing.

On cloud it's the "Which Stripe sales count" field in your settings. On self-host it's two settings: the list, and a read-only key to look up what a one-time checkout sold. Product, price and Payment Link IDs all work.

Moving from Rewardful, FirstPromoter, Tolt or Tapfiliate

Your affiliates' old links keep working once their old codes are in AffiliateTracking. Then tell the script which parameter those links use.

A visit to yoursite.com/?via=jane passes through Jane's tracking link once, records the click and comes back with her token. Import brings your affiliates and their codes over, with a dry run first. Balances don't move, so pay those out in your old tool first.

Where Stripe sales show up

Each paid sale becomes a journal in the partner's ledger, in the sale's own currency. A refund adds a second journal that takes the share back. Nobody edits a journal after the fact.

Partners see the same entries in their portal, with proof that every journal sums to zero. Trace a Stripe refund through the ledger.

Partner ledger on demo data: every journal entry with its source, amount, line count, a journal sum of 0 and a running balance.
A partner ledger on demo data. Stripe events post journals like these.

Stripe FAQ

How do I set up an affiliate program on Stripe?

Add the AffiliateTracking script to your site, connect Stripe with one restricted key on cloud or one webhook on self-host, and invite your affiliates. Stripe keeps taking the payments. AffiliateTracking tracks who sent each one and what they're owed.

Do I need a developer?

Not for Payment Links, the Pricing Table or the Buy Button. You paste one script tag. If you create your own Checkout Sessions, a developer adds a few lines to pass the token along.

Does it work with free trials?

Yes. Checkout links the customer to the affiliate, and the commission comes from the first paid invoice after the trial.

What happens when a customer gets a refund?

The same share of the commission comes back. If you already paid the affiliate, it comes off their next payout.

Will it change how my Stripe checkout looks?

No. It only adds a reference to the checkout link or session. If you already set client_reference_id yourself, it's left alone.

Does Stripe pay my affiliates?

Not yet. AffiliateTracking works out who's owed what, and you pay them yourself. See how a payout run decides amounts.

What if a customer disputes a charge?

When Stripe withdraws the disputed money, the same share of the commission comes back, once per dispute. If you win the dispute, the commission stays taken back. Add it again by hand if the partner should keep it.

Does it work on self-host?

Yes. Self-host uses the same script. You add the Stripe webhook yourself and set its signing secret as AE_STRIPE_SECRET.

Your Stripe account,
now with affiliates.

Self-host for free: the code is open source. Or let us run it for you.