Stripe embedded checkout UTM tracking: keep the source
By Devendra Variya, co-founder of Virling. Published 2026-11-24, updated 2026-12-01.
To track UTM tags with Stripe embedded checkout, pass a visitor ID when your server creates the Checkout Session. Stripe does not copy the UTM tags in your page URL onto the payment, even though the form sits inside that page. Read the virling_vid cookie on your server, set it as client_reference_id, and join the payment to the visits behind that ID. The session carries the ID before the buyer pays, so the return page does not have to load for the source to be kept.
Why the tags on your page are not on the payment
- Your server creates the session. Your page asks your server for a session, and your server calls Stripe. Stripe stores what that call contains, and the page URL is not part of it.
- The form is an iframe. Stripe renders embedded checkout in an iframe on your page (Stripe embedded checkout quickstart). Your URL, with its tags, belongs to the page around it.
- The tags are often gone already. They are on the landing URL. By the time the buyer opens checkout, they are usually a few pages in.
Stripe's API reference lists client_reference_id, up to 200 characters, and metadata on the session. It also lists marketing_attributions, with fields such as utm_source, but your server has to fill that too, and it supports one attribution per session (Checkout Session API reference). A visitor ID is the simpler choice: Stripe holds one short value, and your analytics holds every visit behind it. Virling reads client_reference_id and metadata.virling_vid, not marketing_attributions. The limits of the first field are in Stripe client_reference_id.
The names changed: embedded_page
Stripe renamed the ui_mode values in API version 2026-03-25.dahlia. Many older guides use the old names, and setting one of them on that version or a later one fails (Stripe changelog: ui_mode values):
embedded_pagereplacesembedded: the whole Checkout form inside your page. This post is about this one.hosted_pagereplaceshosted: the page on Stripe's domain, and the default.elementsreplacescustom: your own form built from Stripe's components.client_reference_idis set on the session in the same way.
In Stripe.js, initEmbeddedCheckout() became createEmbeddedCheckoutPage() in the same release, and the old name throws an error there (Stripe changelog: the rename). On older versions, keep the old names. The tracking below is the same.
Track the source of an embedded checkout sale
Step 1: add the script to every page. Put one tag in the <head>, on your landing pages as well as the checkout page. The app shows the exact tag for your site:
<script defer src="https://app.virling.com/v.js" data-site="yourdomain.com"></script>
The script records the referrer and UTM tags of every visit against a visitor ID in the first-party virling_vid cookie. The cookie is on your domain, so your server receives it with the requests your page makes.
Step 2: create the session on your server. This is Express with cookie-parser:
app.post("/create-checkout-session", async (req, res) => {
const session = await stripe.checkout.sessions.create({
ui_mode: "embedded_page",
client_reference_id: req.cookies.virling_vid,
line_items: [{ price: "price_...", quantity: 1 }],
mode: "payment",
return_url: "https://yourdomain.com/return?session_id={CHECKOUT_SESSION_ID}",
});
res.json({ clientSecret: session.client_secret });
});success_url and cancel_url are not allowed with embedded_page; use return_url. If the cookie is missing, the value is undefined and the stripe library leaves the field out, so checkout still works. If client_reference_id already holds your own user or cart ID, set metadata: { virling_vid: req.cookies.virling_vid } instead.
Step 3: mount the form. Ask for the session after the Virling script has run, so a first-time visitor already has the cookie:
<script src="https://js.stripe.com/endive/stripe.js"></script>
<div id="checkout"></div>
<script>
addEventListener("DOMContentLoaded", async () => {
const stripe = Stripe("pk_live_...");
const checkout = await stripe.createEmbeddedCheckoutPage({
fetchClientSecret: async () => {
const res = await fetch("/create-checkout-session", { method: "POST" });
return (await res.json()).clientSecret;
},
});
checkout.mount("#checkout");
});
</script>A defer script runs before DOMContentLoaded, so the cookie is set when the fetch goes out. A hosted checkout usually starts from a click, but an embedded one starts as the page loads, which is why the order matters. If you load Virling from a tag manager, wait until window.virling?.vid exists before mounting. If your API is on another registrable domain, the cookie does not reach it: send window.virling?.vid?.() in the request body and use that value instead.
Step 4: connect Stripe with a restricted key. Create a restricted key with Read on Charges, Checkout Sessions, Customers, Events, Invoices, Subscriptions and PaymentIntents, and paste it into Virling. Virling reads the visitor ID from the Checkout Session behind each charge and credits the payment to the visit, under the attribution model you pick: last non-direct by default, or first touch or last touch.
The checkout snippet generator writes the server call for other providers, and the full setup is on the Stripe integration page.
The return page
Stripe replaces {CHECKOUT_SESSION_ID} in return_url with the session's ID. On the return page, send that ID to your server, retrieve the session and read its status:
app.get("/session-status", async (req, res) => {
const session = await stripe.checkout.sessions.retrieve(req.query.session_id);
res.json({ status: session.status });
});The quickstart shows a success message for complete, and mounts checkout again for open, when the payment failed or was cancelled. Two things to know:
- The buyer may never see it. With
redirect_on_completionset toif_required, Stripe only redirects for payment methods that need it, and withneverit does not redirect at all. The default isalways. Stripe's docs also say not to rely on the landing page alone to fulfil an order, because buyers are not guaranteed to visit it; use thecheckout.session.completedwebhook (Stripe fulfillment docs). The same goes for attribution: tags saved only when the return page loads are lost for buyers who never reach it. - The return can look like a new source. A payment method that redirects sends the buyer through another site and back. Virling treats returns from Stripe's checkout pages as the same visit; for a bank or wallet domain, add it under Same-visit domains in Site settings. More on this in cross-domain checkout attribution.
A worked example: one test purchase
Example data, made up to show what to look for. An imaginary invoicing app sells an $83 one-time plan through embedded checkout. The test buyer arrives from a newsletter link, reads a post, goes to the pricing page and pays there. Before you send the link, paste it into the UTM checker to confirm the tags are spelled the way you want them reported.
| Step | What it holds (example) | What to check |
|---|---|---|
| Landing URL | https://yourdomain.com/blog/late-invoices?utm_source=newsletter&utm_medium=email&utm_campaign=autumn_sale | The tags are still in the address bar after the page loads, and the virling_vid cookie is set, here to vexample456. |
| Checkout page | https://yourdomain.com/pricing, with no tags | The request to /create-checkout-session sends the cookie virling_vid=vexample456. The missing tags are expected: the visit already has them. |
| Checkout Session | cs_test_... with ui_mode: "embedded_page", client_reference_id: "vexample456", amount_total: 8300, status: "complete" | client_reference_id matches the cookie. amount_total is in cents, so 8300 is $83.00. |
| Payment in Virling | $83.00, source newsletter, campaign autumn_sale, channel Email | The row shows the tagged source and not Unattributed. utm_medium=email is what puts it in the Email channel. |
If the session row shows no client_reference_id, the fault is before the payment: the cookie was not set or did not reach your server. If the session has the ID but the payment shows Direct, look for a tagged visit that never arrived, for example tags lost in a redirect before the landing page loaded.
Check that it worked
- Use test-mode keys:
pk_test_in the page,sk_test_on your server, and anrk_test_restricted key in Virling. The Virling script stays quiet onlocalhost; adddata-devto its tag to test there. - Open your site in a private window from a tagged URL such as
?utm_source=test, then go to the checkout page without the tag. - In the developer tools, check that the request to
/create-checkout-sessionsends avirling_vidcookie. - Pay with Stripe's test card
4242 4242 4242 4242, any future date and any CVC. - Retrieve the session with its
cs_test_ID, for example withstripe checkout sessions retrieve cs_test_...in the Stripe CLI. Itsclient_reference_idshould match the cookie. - Wait a minute for the next sync. The payment shows the
testsource instead of Unattributed.
Use a redirect-based payment method as a second test if you accept any, so you see the return page path too. Each Virling step is in the Stripe docs.
For the hosted page and Payment Links, see Stripe Checkout UTM parameters. If you embed a pricing table instead, see Stripe pricing table UTM tracking. In React, the server call is the same; React Stripe UTM tracking covers reading the ID in the browser. If you sell products from your own store without Shopify or WooCommerce, Stripe analytics for online stores shows how orders, repeat orders and refunds are credited.
Frequently asked questions
Does Stripe embedded checkout read UTM parameters from my page URL?
No. The form runs in an iframe and shows a Checkout Session that your server created. Only the values your server sends when it creates the session are on it, so send a visitor ID in client_reference_id.
Is ui_mode embedded or embedded_page?
Stripe renamed embedded to embedded_page in API version 2026-03-25.dahlia, and setting the old value there fails. On an older API version, keep embedded.
Should I use client_reference_id or metadata.virling_vid?
Use client_reference_id unless it already holds your own user or cart ID. In that case put the visitor ID in the session's metadata.virling_vid, which Virling checks first.
Do I need a return page for the source to be recorded?
No. The visitor ID is on the session before the buyer pays, so it does not depend on the return page loading. The return page is for showing the buyer the result.
Why does an embedded checkout sale show as Unattributed?
The session was created without the visitor ID: your page asked for it before the Virling script ran, the request went to another domain without the cookie, the script was blocked or runs in cookieless mode, or client_reference_id holds another value and metadata.virling_vid is empty.
See which campaigns bring Stripe revenue
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.