How do I attribute Polar or Lemon Squeezy sales to traffic sources?
By Devendra Variya, co-founder of Virling. Published 2026-12-02.
Connect your store to Virling and pass the visitor ID into checkout. Virling then credits each Polar order or Lemon Squeezy order to the visit before it, so you see sales by channel, referrer, campaign and landing page. Checkout links on buy.polar.sh and on your store's lemonsqueezy.com address get the visitor ID from the script, with no code.
Neither provider knows where a buyer came from. Both accept extra data at checkout, and that is the hook: put the visitor ID there, and the order can be joined back to the visit.
Set it up
- Add the script before
</head>on every page of your site. It sets one first-party cookie,virling_vid, the visitor ID. - Connect Polar in the app under Setup, Connect payments, with an organization access token that has
orders:readandrefunds:read, plussubscriptions:readso the Retention page knows who still pays. It starts withpolar_oat_. - Or connect Lemon Squeezy there with an API key. Lemon Squeezy keys cannot be made read-only and cover every store on the account, so Virling stores the key encrypted. It registers a webhook on each store, because Lemon Squeezy returns checkout custom data only in webhooks. The webhook needs Virling on a public
httpsaddress, which the hosted version already is. - Pass the visitor ID at checkout. Keep checkout links as normal links on a page that runs the script: it adds
reference_idto Polar links andcheckout[custom][virling_vid]to Lemon Squeezy links. A checkout your server creates needs one field, shown below. - Test it with a Polar sandbox token or a Lemon Squeezy store in test mode. The script does not add the visitor ID to Polar sandbox links, so test Polar with a checkout your server creates. Wait a minute, then open Payments: the order should show a channel instead of Unattributed.
- Read the answer. The Channels card lists visitors, revenue and revenue per visitor per channel, with Source and Campaign tabs for the referring site and the
utm_campaign. The Pages card shows which landing page sold. The Retention page groups customers by the channel of their first order.
The script tag, on every page:
<script defer src="https://app.virling.com/v.js" data-site="yourdomain.com"></script>
A checkout your server creates, with the visitor ID:
// Polar
const checkout = await polar.checkouts.create({
products: ["PRODUCT_ID"],
success_url: "https://yourdomain.com/thanks",
metadata: { virling_vid: req.cookies.virling_vid },
});
// Lemon Squeezy, POST /v1/checkouts
// data.attributes.checkout_data.custom = { "virling_vid": "<the virling_vid cookie>" }See which traffic sources sell
Virling reads Polar and Lemon Squeezy orders and joins each one to the visit before it. Self-host it free, or use the hosted version.
How the two providers differ
- How payments arrive. Virling reads Polar orders with the token every minute. Lemon Squeezy orders are read every minute too, but the visitor ID only comes through the webhook, so orders from before the webhook are Unattributed.
- Refunds. A Polar refund updates its order when it succeeds. Lemon Squeezy refunds do not change an order, so Virling rescans the last 60 days every 6 hours, and a refund can take that long to show.
- Renewals. On both, renewals and later orders by the same customer keep the channel of the customer's first order. See renewals.
- Both at once. You can connect Polar and Lemon Squeezy to the same site, for example while you move from one to the other.
The docs list every field read: Polar and Lemon Squeezy. For code in a framework, read Polar UTM tracking and how to track Lemon Squeezy revenue by traffic source. Moving off Lemon Squeezy? See keeping attribution through a move to Stripe Managed Payments.
Doing it without Virling
Store the UTM tags of each visitor's first landing in a first-party cookie. When they click buy, add those tags to the checkout as custom data: metadata on a Polar checkout, or checkout[custom] fields on a Lemon Squeezy link. Then export your orders each month and group them by the tags in a spreadsheet. It works, but visitors who arrive without tags land in one blank row, renewals need the first order's tags copied by hand, and refunds need a second export.
Frequently asked questions
Does Polar need a webhook?
No. Virling reads Polar orders with the access token every minute. Lemon Squeezy needs the webhook, because it returns checkout custom data only there.
Why are my Lemon Squeezy sales Unattributed?
Usually because no webhook brought the visitor ID: Virling was not on a public https address when you connected, the order is older than the webhook, or a checkout your server creates has no virling_vid in its custom data.
Does the Lemon Squeezy key need full access?
Lemon Squeezy keys cannot be limited. Virling only reads orders, subscriptions and invoices and adds its webhook, and you can delete the key in Lemon Squeezy at any time.
How far back are orders imported?
90 days for both. Orders from before the script was on your site count as revenue but are Unattributed.
See which channels bring Polar and Lemon Squeezy sales
Virling is open source under AGPL. Self-host it free, or use the hosted version; see pricing. It connects to Stripe, Paddle, Shopify, WooCommerce, Polar, LemonSqueezy, Dodo, Creem and RevenueCat.