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

Polar UTM tracking: how to track Polar revenue by traffic source

By Devendra Variya, co-founder of Virling. Published 2026-11-18, updated 2026-11-27.

To see which channel brought each Polar order, pass a visitor ID into checkout, read it back from the order, and join it to the visits that came before. With Virling, checkout links on buy.polar.sh get the ID from the script as reference_id with no code, and checkout sessions you create on your server set virling_vid in metadata. Each order then shows the channel, page and campaign behind it.

Pick the row that matches how you sell:

How you sellWhat to doCode needed
Checkout link on buy.polar.shKeep it as a normal <a href> on a page that runs the script, as in step 2. The script adds reference_idNo
Checkout link your own code opens, such as from a buttonSet reference_id on the URL to window.virling?.vid?.() first, when it returns an ID, or use a normal link insteadYes, in the browser
Checkout session your server creates, also when you open it as an overlay or in your own checkout pageSet metadata.virling_vid from the cookie, as in step 3Yes, on the server
Link in an email, a QR code or on another siteSend people to a page that runs the script, and put the checkout link thereNo

Why UTM tags do not reach Polar orders

UTM tags live on the URL your visitor landed on. They do not reach the order, for two reasons:

  • The visitor is usually a few pages in by the time they click Buy, so the tags are no longer in the address bar.
  • Checkout runs on Polar, a different site from yours, so nothing on your page travels with the buyer unless you put it in the checkout link or session.

You could copy the UTM tags into checkout metadata, but that alone loses the first visit. The tags you copy are the ones on the page at checkout time, if there are any. The search, post or referral that first brought the buyer a week earlier is gone, and so is every visit that carried no tags. A visitor ID points back to all of those visits, the first one included.

Step 1: add the Virling script

Put the script on every page that links to checkout. It sets a first-party virling_vid cookie and records the source of each visit against it: referrer, UTM tags or direct.

Step 2: no-code checkout links

For links to buy.polar.sh, you write nothing extra. Keep the link as a normal <a href> on a page that runs the script. The script adds reference_id=<visitor ID> to it when the page loads and again on click, and never replaces a reference_id that is already there. Polar stores it in the order's metadata, where Virling reads it. A plain link is enough:

<a href="https://buy.polar.sh/YOUR_CHECKOUT_LINK">Buy now</a>

Virling only uses a reference_id that looks like one of its visitor IDs, so a reference you set yourself is not mistaken for a visitor. A virling_vid custom field on the checkout link still works too.

Step 3: metadata on checkout sessions

When your server creates a checkout session, read the visitor's virling_vid cookie and set it in metadata:

const checkout = await polar.checkouts.create({
  products: ["PRODUCT_ID"],
  success_url: "https://yourdomain.com/thanks",
  metadata: { virling_vid: req.cookies.virling_vid },
});
// Send the customer to checkout.url

Virling looks for virling_vid in the order's metadata first, then the order's custom field data, then the customer's metadata, then a checkout link's reference_id.

Any server language works, as long as the code that creates the session runs on your own domain, where the browser sends the cookie, and runs when the buyer clicks Buy. The code for each framework is in its own guide:

Step 4: connect Polar

In Polar, create an Organization Access Token with the orders:read and refunds:read scopes, plus subscriptions:read so Retention can tell who still pays, and paste it into Virling. Production and sandbox tokens both work. Virling imports orders from the last 90 days on the first run, then new orders every minute, and checks unpaid orders again every 10 minutes for up to 30 days. There is no webhook to set up.

The full setup is in the Polar docs and on the Polar integration page.

Start free trial

Check that it works in the sandbox

  1. Connect a token from the Polar sandbox.
  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, go to a sandbox checkout your server creates with virling_vid in metadata, as in step 3, 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. If a step fails, see test your setup.

What the sandbox does not do: the script adds reference_id only to links on buy.polar.sh, so it does not tag sandbox links and the no-code link cannot be tested there. To test that link, connect your production token, make one small live payment through it and refund it. A site has one Polar connection, and sandbox orders stay in your reports after you replace the token with a production one.

Why an order stays Unattributed

Open the payment from /app/yourdomain.com/payments and look for Visitor under Details, the visitor ID that came with checkout. If there is none, checkout carried no ID. Then go down this list in order:

  1. It is a renewal. Renewals keep the channel of the customer's first order. Check that order: if it is Unattributed, or older than the first import, its renewals usually are too.
  2. It was a sandbox link. The script does not tag those. Test with a session your server creates.
  3. The session had no metadata. It was created without metadata.virling_vid. Read the cookie on the request that creates the session, as in step 3.
  4. The link skipped your site. A checkout link opened from an email, a QR code or another site carries no visitor ID.
  5. The link was not a normal link. The script only tags an <a href> to buy.polar.sh on a page that runs it, not a URL your code opens.
  6. The link already had a reference_id. The script keeps the one you set, so it cannot add the visitor ID there. Take it off the link, or use a session with metadata.
  7. The visitor had no cookie. In cookieless mode, or before a visitor accepts under Until consent, there is no visitor ID to pass. The same goes for a page where the script is missing or blocked.
  8. It has a visitor, but no visit in the window. That visitor's sessions all started before the lookback window, or after the payment. Choose a longer window if your buyers take longer, and check that the script runs on every page where visitors arrive.
  9. It is older than the script. Orders from before the script was on your site count as revenue but are Unattributed.

Every other cause is in Unattributed revenue. An order made before a fix usually stays Unattributed, so place a new one to check it.

What you see after setup

Each order is joined to the visits of the buyer who paid, and one of those visits gets the credit by a rule you keep fixed (see first touch or last touch). Revenue then groups by channel, referrer, landing page and campaign. Orders without a visitor ID, such as checkout links opened straight from an email, show as Unattributed. Until every payment is matched, the Matched revenue line shows what share of your revenue, Polar orders included, was matched to a visit and why the rest was not.

Refunds and renewals

A refund does not change an order's creation time, and a pending refund can settle later. Virling reads refunds on their own and applies each one to the order it belongs to, on that order's date, so a channel does not look better than it is. Refunds made after you connect count even when the order is older than 90 days, and a pending refund counts once it succeeds, if it does so within 7 days. Orders with billing reason subscription_cycle are marked as renewals, so they are not counted as new customers.

Report Polar 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 seller 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 search3,00045$1,800$0.60
AI60018$720$1.20
Communities4,50027$945$0.21
Email50020$900$1.80
Direct2,00030$1,200$0.60

Communities bring the most visitors but only $0.21 from each, while Email brings the fewest and earns $1.80 from each. AI sends a fifth as many visitors as Organic search and earns twice as much per visitor, but 18 sales in one month is a small sample, so look at a few more months before you move your effort.

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

Frequently asked questions

Does Polar keep the UTM parameters from my site?

No. Checkout runs on Polar, a different site from yours, so the tags on your landing page do not travel with the buyer. Pass a visitor ID in the checkout's metadata instead.

How do I pass metadata to a Polar checkout?

Set metadata when you create a checkout session with polar.checkouts.create. For checkout links on buy.polar.sh, add a reference_id query parameter, which Polar stores in the order's metadata. With the Virling script on the page, checkout links get reference_id without any code.

Should I put UTM tags in Polar checkout metadata?

Put a visitor ID there instead. UTM tags copied at checkout record only the visit the buyer is on when they pay, so the first visit is lost, along with every visit that had no tags, such as search and referrals. A visitor ID points back to all of them.

Does this work with any framework?

Yes. Checkout links need only the Virling script on the page. For checkout sessions, any server code that reads the virling_vid cookie when the buyer clicks Buy and sets it in the checkout's metadata works. There are guides with code for Next.js, Nuxt, SvelteKit and Laravel.

Do I need a Polar webhook?

No. Virling reads orders from the Polar API with an organization access token, checks for new orders every minute and reads the visitor ID from each order.

Which Polar token scopes are needed?

orders:read and refunds:read, plus subscriptions:read if you want to see who still pays. No other scopes are needed, so the token is read-only.

How are Polar refunds counted?

In Virling, a succeeded refund lowers the revenue of the order it belongs to, on that order's date. Refunds made after you connect count even when the order is older than 90 days. A pending refund counts once it succeeds, if it does so within 7 days.

How far back does the first Polar import go?

Virling's first import reads orders from the last 90 days. Orders from before the script was on your site count as revenue but are Unattributed.

What happens to orders with no visitor ID?

They have no visit to join, so Virling shows them as Unattributed. That includes checkout links opened straight from an email or a QR code, which skip your site.

See your Polar 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