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.
// 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.
// Dodo Payments (Node, dodopayments): checkout session with metadata
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: "pdt_...", quantity: 1 }],
return_url: "https://yourdomain.com/thanks",
metadata: { virling_vid: req.cookies.virling_vid },
});
// Send the customer to session.checkout_url
// Static payment links (checkout.dodopayments.com/buy/...) need nothing:
// the Virling script adds metadata_virling_vid on click.
// Polar (Node, @polar-sh/sdk): checkout session with 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
// Checkout links (buy.polar.sh) need nothing:
// the Virling script adds reference_id.
// LemonSqueezy: checkout links (STORE.lemonsqueezy.com/checkout/buy/...)
// need nothing: the Virling script adds checkout[custom][virling_vid].
// For checkouts you create on your server, POST /v1/checkouts with:
// data.attributes.checkout_data.custom = { virling_vid: req.cookies.virling_vid }
// Creem (Node): checkout with metadata
const res = await fetch("https://api.creem.io/v1/checkouts", {
method: "POST",
headers: { "x-api-key": process.env.CREEM_API_KEY, "content-type": "application/json" },
body: JSON.stringify({
product_id: "prod_...",
success_url: "https://yourdomain.com/thanks",
metadata: { virling_vid: req.cookies.virling_vid },
}),
});
// Send the customer to (await res.json()).checkout_url
// RevenueCat (Node): set the customer attribute virling_vid before the purchase
await fetch(`https://api.revenuecat.com/v2/projects/${projectId}/customers/${appUserId}/attributes`, {
method: "POST",
headers: { authorization: `Bearer ${process.env.REVENUECAT_SECRET_KEY}`, "content-type": "application/json" },
body: JSON.stringify({ attributes: [{ name: "virling_vid", value: req.cookies.virling_vid }] }),
});
// Paddle (Paddle.js): pass the visitor ID as custom data
Paddle.Checkout.open({
items: [{ priceId: "pri_...", quantity: 1 }],
customData: { virling_vid: window.virling?.vid?.() },
});
// Or on your server, POST /transactions with:
// custom_data: { virling_vid: req.cookies.virling_vid }
// WooCommerce: add to your theme's functions.php (or a snippets plugin)
// so every order keeps the visitor ID from the virling_vid cookie.
add_action('woocommerce_checkout_create_order', 'virling_vid_on_order');
add_action('woocommerce_store_api_checkout_update_order_from_request', 'virling_vid_on_order');
function virling_vid_on_order($order) {
$vid = $_COOKIE['virling_vid'] ?? '';
if (preg_match('/^[A-Za-z0-9-]{8,64}$/', $vid)) $order->update_meta_data('virling_vid', $vid);
}
<script>
// Shopify: in your theme's theme.liquid, after the Virling script.
// It stores the visitor ID on the cart, and Shopify copies cart
// attributes onto the order as note attributes.
addEventListener("load", function () {
var vid = window.virling && virling.vid && virling.vid();
if (vid) fetch("/cart/update.js", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ attributes: { virling_vid: vid } })
});
});
</script>
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.
Virling reads metadata.virling_vid on the payment. Static payment links need nothing: the script adds metadata_virling_vid on click. See the Dodo Payments docs.
Virling reads virling_vid from the order's metadata, its custom field data, or the customer's metadata. See the Polar docs.
Virling reads virling_vid from the checkout custom data in its webhook. Checkout links need no code. See the LemonSqueezy docs.
Virling reads virling_vid from the checkout's metadata in the checkout.completed webhook, then from the subscription's or customer's metadata. See the Creem docs.
Virling reads the customer attribute virling_vid from each webhook event. Set it from your app with the SDK's setAttributes, or from your server. See the RevenueCat docs.
Virling reads virling_vid from the transaction's custom_data. See the Paddle docs.
Virling reads virling_vid from the order's meta data. Add the snippet once, and every order keeps the visitor ID from the cookie. See the WooCommerce docs.
Virling reads virling_vid from the order's note attributes. The snippet sets it as a cart attribute, which Shopify copies onto the order. See the Shopify 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.
How to pass the visitor ID into checkout
- Add the Virling script to your site, so every visitor gets a
virling_vidcookie on your domain. - Pick your payment provider above and copy the snippet.
- Put it where you create the checkout. On your server, read the
virling_vidcookie from the request. In the browser,window.virling?.vid?.()returns the same ID. - 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
- Cross-domain checkout attribution: keeping the visit when checkout runs on another domain.
- Track Stripe revenue by traffic source: from a visit to a Stripe payment, step by step.
- Why Shopify orders show as Direct: what breaks the link between visit and order.
- Persist UTM parameters across pages: ways to keep the tags until checkout, with code.
- Unattributed payments: what happens to payments without a visitor ID.
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.