virling Pricing Self-host Demo Changelog Agencies GitHub Start free trial
blog / 2026-11-09

How to track LemonSqueezy revenue by traffic source

By Devendra Variya, co-founder of Virling. Published 2026-11-09, updated 2026-11-25.

To track LemonSqueezy revenue by traffic source, give each visitor an ID, pass it to LemonSqueezy as checkout custom data, and join each order back to the visits that came before it. LemonSqueezy knows who paid and how much. It does not know which page or channel they came from.

Lemon Squeezy stops processing payments on March 31, 2027. See moving to Stripe Managed Payments without losing attribution.

Step 1: set a visitor ID

Your analytics script sets one first-party ID per visitor and remembers the first source: referrer, UTM tags or direct. Put the script on the pages that link to checkout, not only on the checkout itself. The UTM tags stay with the visit, not the LemonSqueezy checkout; LemonSqueezy UTM tracking shows how the ID ties each order back to them.

Step 2: send the ID to LemonSqueezy at checkout

LemonSqueezy checkouts accept custom data. Pick the option that matches how you sell:

  • Checkout links: add the ID to the link as checkout[custom][name]=value
  • Checkouts you create on your server: when you call POST /v1/checkouts, set data.attributes.checkout_data.custom to an object holding the ID from the visitor's cookie

If your link is built before the analytics script has loaded, the value will be empty, so wait for the script first.

Step 3: catch the custom data in a webhook

This is the step that surprises people. LemonSqueezy only returns checkout custom data in webhooks. Reading orders from the API is not enough, because the ID will not be there. Register a webhook for order_created and subscription_payment_success, check each request's X-Signature against your signing secret, and attach the ID to the order or invoice it came with. The webhook address must be a public https:// URL that LemonSqueezy can reach.

When you connect LemonSqueezy, Virling registers this webhook on each of your stores, and you can filter its Payments page to Unattributed to find the orders that joined no visit.

Start free trial See the demo

Step 4: join orders to visits

Match each order's ID to that visitor's earlier visits and credit one of them with a rule you keep fixed (see first touch or last touch). Orders with no ID have no visit to join, so they show as Unattributed.

Step 5: handle refunds and renewals

Refunds do not change an order's creation time, so a scan that only looks at new orders will miss them. Rescan recent orders for refunds on a schedule, or a channel will look better than it is. Renewal invoices should keep the channel of the subscription's first payment.

Step 6: report revenue per channel

Group the joined orders by channel and divide by visitors to get revenue per visitor. That is the table that tells you where to spend time.

Here is what it can look like for one month. The store and every number are made up, and Unattributed sales are left out because they have no visitors to divide by:

ChannelVisitorsSalesRevenue after refundsRevenue per visitor
Organic search2,40048$1,392$0.58
Social6,00030$840$0.14
Email90036$1,080$1.20
Referral1,00025$700$0.70
Direct1,80027$756$0.42

Social brings the most visitors but only $0.14 from each, while Email brings the fewest and earns $1.20 from each. Referral sends a sixth as many visitors as Social and makes nearly as much, $700 to $840, so one more site that links to you may be worth more than one more post.

Checkout on another domain or a second site? See cross-domain checkout attribution.

What goes wrong

  • Passing the ID but never registering the webhook: orders import with no visitor and fall into Unattributed
  • A webhook address that LemonSqueezy cannot reach, such as a private or http URL
  • Building the checkout link before the script has loaded, so the ID is empty
  • Ignoring refunds, which overstates a channel

Doing it with Virling

Virling imports LemonSqueezy orders and subscription invoices from the last 90 days on the first run, then new ones every minute, and rescans the last 60 days for refunds every 6 hours. When you connect, it registers the webhook on each of your stores for you, checks the signature and attaches the visitor ID. Checkout links on STORE.lemonsqueezy.com need no code, because the script adds checkout[custom][virling_vid] to them. The webhook needs VIRLING_BASE_URL to be a public https:// address.

One thing to know first: LemonSqueezy API keys cannot be made read-only and cover every store on your account. Virling stores the key encrypted, and you can delete it in LemonSqueezy at any time. The setup is in the docs and on the LemonSqueezy integration page.

Check that it works

  1. Switch your LemonSqueezy store to test mode, create an API key there and connect it. Virling must be on a public https:// address.
  2. Open a private window and visit a page that runs the script through a tagged link, such as https://yourdomain.com/?utm_source=test&utm_medium=email.
  3. In the same window, click a test mode checkout link on your page and pay with a test card.
  4. Wait a minute for the next sync, then open the payments list at /app/yourdomain.com/payments. The payment shows the test source and the Email channel of your tagged visit instead of Unattributed.

Use a new email address for each test, because a later payment by the same customer is a renewal and keeps the first payment's channel. A site has one LemonSqueezy connection, and test orders stay in your reports after you replace the key with a live one. If a step fails, see test your setup.

Frequently asked questions

Can LemonSqueezy show which traffic source a sale came from?

Not on its own. LemonSqueezy records the order, not the visit. You need to pass a visitor ID into checkout as custom data and join it to your analytics.

Why does LemonSqueezy need a webhook for this?

LemonSqueezy only returns checkout custom data in webhooks, not in its API responses for orders. A webhook for new orders and subscription payments is how the visitor ID reaches your analytics.

Which channel do LemonSqueezy renewals get?

Renewal invoices keep the channel of the subscription's first payment instead of landing in Direct.

Can I limit the LemonSqueezy API key to read-only?

No. LemonSqueezy API keys cannot be made read-only and they cover every store on your account, so store the key encrypted and delete it in LemonSqueezy to revoke access.

Why is a LemonSqueezy payment Unattributed?

Usually because no webhook brought its visitor ID: Virling was not on a public https:// address when you connected, the order is from before the webhook, or a checkout you create has no virling_vid in its custom data. On your own server, set VIRLING_BASE_URL, then use Replace key to add a missing webhook.

How are LemonSqueezy refunds counted?

In Virling, full and partial refunds lower the revenue of the order or invoice they belong to, on its own date. Orders and invoices from the last 60 days are read again every 6 hours, so a refund can take that long to show, and one on an older order is not picked up automatically.

How far back does the first LemonSqueezy import go?

Virling's first import reads orders and subscription invoices from the last 90 days. They count as revenue, but those from before the webhook are Unattributed.

See your LemonSqueezy revenue by traffic source

Virling is open source under AGPL. Self-host it free, or use the hosted version with a 14-day free trial. It connects to Stripe, Paddle, Shopify, WooCommerce, Polar, LemonSqueezy, Dodo, Creem and RevenueCat.

Start free trial See the demo