Lemon Squeezy affiliate tracking, renewals included.
Lemon Squeezy affiliate tracking with AffiliateTracking takes one line on your checkout links and one webhook. 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 12 fraud rulesFrom 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. We record the click, and they land on 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
Your checkout links get the token as custom data. Lemon Squeezy keeps it on the order.
- 04Lemon Squeezy tells us
order_created arrives, the 12 fraud rules run, and the customer stays linked to that affiliate.
Set it up in four steps
Step 2 is the only code. The rest happens in Lemon Squeezy and in your settings.
-
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>
-
Add the token to your checkout links
This adds it to every Lemon Squeezy link on the page, overlay buttons included. Creating checkouts through the API? Pass it as checkout_data.custom.token instead.
// Example: add the token to Lemon Squeezy links window.addEventListener('load', () => { const token = window.AffiliateTracking && AffiliateTracking.token(); if (!token) return; document.querySelectorAll('a[href*="lemonsqueezy.com/checkout/buy"]') .forEach((a) => { const url = new URL(a.href); url.searchParams.set('checkout[custom][token]', token); a.href = url.toString(); }); }); -
Add a webhook in Lemon Squeezy
In Settings, then Webhooks, add your address, make up a signing secret and tick four events.
# Callback URL https://yourbrand.affiliatetracking.co/webhooks/lemonsqueezy # Events order_created order_refunded subscription_payment_success subscription_payment_refunded
-
Paste the same signing secret
On cloud, paste it into the Lemon Squeezy field under Billing webhooks in your settings. AffiliateTracking checks every event against it before it writes anything.
# Cloud: Settings, Billing webhooks, Lemon Squeezy Signing secret: the one you made up # Self-host AE_LEMONSQUEEZY_SECRET="the same secret"
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. |
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.
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 ever move to Stripe or Paddle.
Do I need a developer?
For step 2, a little. It's one short script on your pages. Everything else happens in settings.
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.
Try cloud free for 14 days. Or buy self-host for $99 once.