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 12 fraud rules

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 12 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 5 events in the table below
  • 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 .
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.
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.

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.

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.

Try cloud free for 14 days with one restricted key. Or buy self-host for $99 once.