virling Pricing Self-host Demo Changelog Agencies GitHub Start free trial
integrations / polar for ai apps

See which post, search or AI answer brings your paying users on Polar.

For founders of AI apps and GPT wrappers who sell subscriptions or credits through Polar. Virling ties each paying user to the channel that brought them, including referrals from ChatGPT, Perplexity and other AI answers, so you see which channel brings the users who pay, not only the ones who sign up and spend free credits. Open source under AGPL, hosted or self-hosted.

Start free trial See the demo

Polar records each order and its customer, but not the post or AI answer that sent them to you. Virling puts a visitor ID on every visit, finds that ID on the Polar order, and gives the payment to the visits that led to it. How that visit is picked is in Model and lookback window.

Checkout sessions and metadata

Most AI apps on Polar create a checkout session on the server for a signed-in user. Polar copies the session's metadata to the order, so that is where the visitor ID goes:

const checkout = await polar.checkouts.create({
  products: ["PRODUCT_ID"],
  success_url: "https://yourapp.com/thanks",
  metadata: { virling_vid: req.cookies.virling_vid },
});
// Send the customer to checkout.url
  • Where Virling looks. virling_vid in the order's metadata, then in the order's custom field data, then in the customer's metadata. An ID stored on the customer also covers orders that carry none of their own.
  • Checkout links. A buy.polar.sh link on a page that runs the script gets reference_id=<visitor ID>, unless it already has one. Polar keeps it in the order's metadata, and Virling only accepts a reference_id shaped like a visitor ID, so your own reference values are left alone.
  • Sandbox. Sandbox tokens work, but the script does not add the ID to sandbox links, so test with a checkout session that sets metadata.

Usage-based billing and meters

Polar can bill by usage: your app sends events, a meter adds them up, and a metered price charges for them on the subscription's billing cycle. Virling reads none of the events or meters. Usage shows up when Polar charges for it, as part of an order with billing reason subscription_cycle, which is a renewal and keeps the channel of the customer's first payment. A heavy month therefore raises that channel's revenue and net LTV through one larger renewal, not through usage counts.

Virling counts each order's net_amount, after discounts and before tax, in the order's currency.

Benefits such as license keys

A Polar product can grant benefits when it is bought: license keys, file downloads, repository or Discord access, or credits added to a meter. Virling does not read benefits, and it does not see license key activations or credits being spent in your app. The order that granted them is what counts, so a credit pack sold as a one-time product is credited like any order: from its own checkout when it is the customer's first purchase, and to the channel of their first payment after that.

What Virling reads from Polar, and what it does not

  • Reads orders (orders:read): the last 90 days on the first run, then new ones every minute. Draft and pending orders are checked again every 10 minutes for up to 30 days and imported once paid.
  • Reads refunds (refunds:read): a succeeded refund lowers its order, even one older than 90 days if the refund came after you connected, and a pending refund counts once it succeeds within 7 days.
  • Reads subscription status (subscriptions:read, optional) once an hour. active, trialing and past_due count as live on the Retention page; without the scope, retention falls back to payment recency.
  • Keeps trials apart. A $0 order with billing reason subscription_create starts a trial. It is never counted as revenue, a payment or a customer, and a later payment of that customer with no visitor ID of its own is credited from the visits before the trial.
  • Does not read usage events, meters, benefits, license keys, products or customer emails, and the token needs no write scope.

Set it up

  1. Add the site and the script. Click + Add a site and paste the tag on your marketing site and your app, so a visitor keeps one ID from the landing page to checkout. Leave cookieless mode off.
  2. Create a token. In your Polar organization's settings, create an Organization Access Token with orders:read, refunds:read and subscriptions:read, and paste it under payments. It starts with polar_oat_; Virling tries production first, then sandbox, and names any missing scope.
  3. Put the visitor ID on orders. Set metadata.virling_vid on checkout sessions, and keep checkout links on pages that run the script.

The Next.js walkthrough is in Next.js Polar UTM tracking, and Polar UTM tracking covers why UTM tags do not reach Polar orders and what to pass instead. ChatGPT revenue tracking shows how to read which ChatGPT visits pay. Every setting is on the Polar integration page, and Virling for AI apps covers other payment providers.

Open source

The code is AGPLv3 and public on GitHub, and the self-hosted binary has the same features as the hosted service.

Frequently asked questions

Which channel brings paying users to my AI app on Polar?

Connect Polar with an organization access token and set virling_vid in the metadata of each checkout session; buy.polar.sh links on your pages get the ID from the script. The Channels card then shows whether a post, a search or an AI answer brought the users who pay.

How is a credit pack bought on Polar credited?

A pack that is the customer's first order is credited from the visitor ID on that order. Any later order by the same Polar customer, a pack or a subscription_cycle charge alike, keeps the channel of their first payment.

Does Virling read usage or credit balances from Polar?

No. Virling reads Polar orders, refunds and, when allowed, subscriptions. It does not read usage events, meters or credit balances, so usage counts only once it is part of a paid order.

Do free credits count as revenue?

No. Virling counts payments, not signups or usage. A user who only spends free credits is a visitor, not a customer. A $0 order with billing reason subscription_create starts a trial, which is never counted as revenue, a payment or a customer.

Does Virling read license keys or other Polar benefits?

No. Benefits such as license keys, file downloads and meter credits are not read, and the token needs no scope for them. Only the order that granted the benefit counts, at its net amount.

Full guides: Polar in the docs, Link checkout to visits and Renewals.

Start free trial