Lemon Squeezy affiliate tracking, renewals included.

Lemon Squeezy affiliate tracking with AffiliateTracking takes one script tag, which adds the token to your checkout links, and one webhook. On cloud, one API key adds that webhook for you. First orders, subscription renewals and refunds all land in the same ledger.

Orders and renewalsPartial refundsCloud and self-host

Your checkout link, for a visitor from JaneExample
Your linkhttps://yourstore.lemonsqueezy.com/checkout/buy/8f2c…
After t.js…/checkout/buy/8f2c…?checkout[custom][token]=…
When they payorder_created → Jane's commission, checked by 13 fraud rules

A Lemon Squeezy checkout link with the token added. Example data.

From click to commission

How a Lemon Squeezy sale finds its affiliate

The same path as every other sale, with Lemon Squeezy's custom data carrying the token.

  1. 01The click

    A visitor opens an affiliate's link. AffiliateTracking 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 domain for your attribution window, 30 days unless you change it.

  3. 03The link carries it

    The script adds the token to your checkout links as custom data. Lemon Squeezy keeps it on the order.

  4. 04Lemon Squeezy tells us

    order_created arrives, the 13 fraud rules run, and the customer stays linked to that affiliate.

Set up Lemon Squeezy

The script tag is the only code, unless you create checkouts through the API. On cloud, step 3 is one API key. On self-host, you add the webhook yourself.

  1. Add the script to your site

    Paste it on every page, right before </head>. Your workspace settings show the tag with your own address filled in.

  2. Checkout links: nothing to add

    The script adds the token to every Lemon Squeezy checkout link on the page, overlay buttons included. Creating checkouts through the API? Pass the visitor's at_token cookie as checkout_data.custom.token.

  3. Connect Lemon Squeezy

    On cloud, paste a Lemon Squeezy API key under Connect your billing. AffiliateTracking adds the webhook with all five events, then forgets the key. On self-host, open Settings, then Webhooks, in Lemon Squeezy, add your address, make up a signing secret and tick the five events.

  4. Self-host: set the same secret

    Set the secret you made up as AE_LEMONSQUEEZY_SECRET and restart. On cloud, skip this step: the API key connect made its own secret. AffiliateTracking checks every event against it before it writes anything.

What each Lemon Squeezy event does

Each event has to pass Lemon Squeezy's signature check, and it counts once, however many times Lemon Squeezy sends it.

Checked against the code on . Orders placed in test mode never earn commission.
Lemon Squeezy eventWhat AffiliateTracking does
order_createdReads the token, credits the affiliate and links the customer to them for good. A $0 order (a free trial) links the customer without a commission.
subscription_createdLinks the customer to the affiliate, so the first paid renewal earns.
subscription_payment_successEach renewal credits the linked affiliate. No token needed.
order_refundedTakes back the same share of the commission. Partial refunds take back part of it.
subscription_payment_refundedDoes the same for a refunded renewal payment.

Good to know before you start

Four details worth knowing before you go live.

Free trials

Checkout links the customer to the affiliate. Their first paid renewal earns the commission.

Renewals need no token

Once a customer has an affiliate, every renewal credits that same affiliate, with no custom data needed.

Test mode stays out

Test orders pass through without touching the ledger, so you can try checkout without paying anyone.

Keep the name "token"

The custom data key has to be token, exactly. Other custom data you pass stays untouched.

Where Lemon Squeezy 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. The double-entry commission ledger explains the rest.

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. Lemon Squeezy events post journals like these.

Lemon Squeezy FAQ

How do I run an affiliate program on Lemon Squeezy?

Lemon Squeezy takes the payments and AffiliateTracking tracks who sent each one. Add the script to your site, add the token to your checkout links, and point a webhook at your workspace. Then invite affiliates.

Lemon Squeezy has its own affiliates. Why use this?

Use whichever fits. AffiliateTracking holds suspicious sales before you pay them and keeps every cent in a ledger you can check. It also works the same way if you move to Stripe, Paddle or Polar.

Do I need a developer?

Not for checkout links or the overlay. You paste one script tag. If your server creates checkouts through the Lemon Squeezy API, a developer passes the token as custom data.

Does it work with the checkout overlay?

Yes. The overlay opens the same checkout link, so the token rides along.

What happens when I refund an order?

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

Your Lemon Squeezy store,
now with affiliates.

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