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
https://yourstore.lemonsqueezy.com/checkout/buy/8f2c……/checkout/buy/8f2c…?checkout[custom][token]=…order_created → Jane's commission, checked by 13 fraud rulesA 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.
- 01The click
A visitor opens an affiliate's link. AffiliateTracking records the click and sends them to your site with a signed token.
- 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.
- 03The link carries it
The script adds the token to your checkout links as custom data. Lemon Squeezy keeps it on the order.
- 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.
-
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.
<script src="https://yourbrand.affiliatetracking.co/t.js" async></script>
-
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.
// Only for checkouts you create through the API checkout_data: { custom: { token: req.cookies.at_token } } -
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.
# Callback URL https://yourbrand.affiliatetracking.co/webhooks/lemonsqueezy # Events order_created order_refunded subscription_created subscription_payment_success subscription_payment_refunded
-
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.
# Self-host AE_LEMONSQUEEZY_SECRET="the same secret" # Cloud Nothing to paste. Connect set it.
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.
| Lemon Squeezy event | What AffiliateTracking does |
|---|---|
order_created | Reads 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_created | Links the customer to the affiliate, so the first paid renewal earns. |
subscription_payment_success | Each renewal credits the linked affiliate. No token needed. |
order_refunded | Takes back the same share of the commission. Partial refunds take back part of it. |
subscription_payment_refunded | Does 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.
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.