virling Pricing Self-host Demo Changelog Agencies GitHub Start free trial
tools / checkout snippet generator

Checkout snippet generator

A payment is credited to a visit only when checkout carries the visitor's ID from the virling_vid cookie. Pick your payment provider below and copy the code that passes it in. Everything runs in your browser.

Payment provider
// Stripe Checkout (Node, stripe): pass the visitor ID on the session
const session = await stripe.checkout.sessions.create({
  client_reference_id: req.cookies.virling_vid,
  line_items: [{ price: "price_...", quantity: 1 }],
  mode: "subscription",
  success_url: "https://yourdomain.com/thanks",
});

// Your own PaymentIntent (Elements): put it in metadata
const intent = await stripe.paymentIntents.create({
  amount: 4900,
  currency: "usd",
  metadata: { virling_vid: req.cookies.virling_vid },
});

// Payment Links (buy.stripe.com) need nothing:
// the Virling script adds client_reference_id on click.

Virling reads metadata.virling_vid on the charge or its PaymentIntent, then metadata.virling_vid or client_reference_id on the Checkout Session. See the Stripe docs.

See which channel brought each payment

With the visitor ID in checkout, Virling credits each payment to the visit that led to it, and shows revenue for every channel, referrer and page. Virling is open source under AGPLv3: self-host it free, or start a 14-day hosted trial.

Start free trial Link checkout to visits · See the demo

How to pass the visitor ID into checkout

  1. Add the Virling script to your site, so every visitor gets a virling_vid cookie on your domain.
  2. Pick your payment provider above and copy the snippet.
  3. Put it where you create the checkout. On your server, read the virling_vid cookie from the request. In the browser, window.virling?.vid?.() returns the same ID.
  4. Make a test payment from a page that runs the script, wait for the next sync, and open the payments list. The payment should show a channel instead of Unattributed.

The script loads with defer. If your checkout code runs in the browser and can run before it, wait for it:

async function visitorId() {
  for (let i = 0; i < 20 && !window.virling?.vid; i++) {
    await new Promise((r) => setTimeout(r, 100));
  }
  return window.virling?.vid?.() || null;
}

Hosted checkout links on buy.stripe.com, buy.polar.sh, checkout.dodopayments.com and *.lemonsqueezy.com need no code: the script adds the visitor ID to them. The full reference is in link checkout to visits.

Guides on checkout attribution

questions

Checkout snippet FAQ

What is the Virling visitor ID?

An ID that the Virling script stores in the first-party virling_vid cookie on your domain. Passing it into checkout is how a payment is matched to the visit that led to it.

Do I need code for checkout links?

No. On buy.stripe.com, buy.polar.sh, checkout.dodopayments.com and *.lemonsqueezy.com links, the script adds the visitor ID itself when the page loads and again on click. A parameter already on the link is never replaced.

Should I read the ID on the server or in the browser?

Either works. Your server receives the virling_vid cookie with every request, and window.virling?.vid?.() returns the same ID in the browser. Check the value before using it, since it is empty when the script is blocked or not loaded yet.

What happens to payments without the visitor ID?

They still count toward revenue, as Unattributed, but are not credited to any visit or channel.

Does it work in cookieless mode?

No. In cookieless mode there is no visitor ID: window.virling.vid() returns null and checkout links are left as they are.

See which channel brought each payment

With the visitor ID in checkout, Virling links every payment to the visit it came from, so you see the post, search or AI answer behind your revenue. 14 days free.

Start free trial See the demo