Stripe Checkout UTM parameters: how to pass them
By Devendra Variya, co-founder of Virling. Published 2026-11-17, updated 2026-11-29.
Stripe Checkout does not pick up the UTM parameters on your page. To keep them, your server passes them when it creates the Checkout Session: UTM tags in metadata, or a visitor ID in client_reference_id that points back to your analytics. For Payment Links, add client_reference_id to the link URL. A visitor ID is the better choice, because it keeps every visit, not just the tags of the last one.
Where Stripe can hold a UTM tag or visitor ID
client_reference_idon the Checkout Session: one string, up to 200 characters. It is the only one of these you can set from a Payment Link URL. Its limits are in Stripe client_reference_id.metadataon the Checkout Session: up to 50 keys, key names up to 40 characters, values up to 500 characters (Stripe metadata docs).payment_intent_data.metadataorsubscription_data.metadata: Stripe does not copy session metadata to the PaymentIntent or Subscription, so set these too if you want the values on the payment itself.
Both fields are in the Checkout Session API reference, and both arrive in the checkout.session.completed event.
Which one to use. For a visitor ID, take client_reference_id if it is free and session metadata.virling_vid if it is not. Use subscription metadata for values you want to read on the subscription later, not for the visitor ID:
| Question | client_reference_id | Session metadata | subscription_data.metadata |
|---|---|---|---|
| What fits | One string, up to 200 characters | Up to 50 keys, values up to 500 characters | Up to 50 keys, values up to 500 characters |
| Where it is saved | The Checkout Session | The Checkout Session | The Subscription |
| Where Stripe copies it | Nowhere: it is a field of the session only | Not copied by default | Each invoice the subscription creates, as a snapshot in parent.subscription_details.metadata |
| Set per buyer on a Payment Link | Yes, in the URL | No: the link's own metadata is copied to each session, the same for every buyer | No: set on the link, the same for every buyer |
| Read by Virling as the visitor ID | Yes, unless the session's metadata.virling_vid is set | Yes, from virling_vid | No |
| Use it when | You have one ID to pass and the field is free | The field already holds your own ID, or you want UTM tags in Stripe too | You want a plan or team ID on the subscription and its invoices |
Sources: create a Checkout Session, Payment Link URL parameters and metadata. In payment mode, payment_intent_data.metadata is the counterpart of the last column: it is saved on the PaymentIntent and copied to the charge, and Virling does read virling_vid there.
Step 1: keep the tags or the ID until checkout
UTM tags are on the landing URL only. By the time the visitor clicks Buy, they are usually a few pages in, so store what you need when they land. With the Virling script, the visitor ID is already in the first-party virling_vid cookie, and the script records the UTM tags of every visit against it, so you only pass the ID.
Step 2: pass them to a server-created Checkout Session
Pass the visitor ID in client_reference_id. If you also want the UTM tags readable in Stripe, put them in metadata on the session and on the PaymentIntent:
const session = await stripe.checkout.sessions.create({
client_reference_id: req.cookies.virling_vid,
line_items: [{ price: "price_...", quantity: 1 }],
mode: "payment",
success_url: "https://yourdomain.com/thanks",
// Optional: the tags you stored on landing
metadata: { utm_source: utm.source, utm_campaign: utm.campaign },
payment_intent_data: {
metadata: { utm_source: utm.source, utm_campaign: utm.campaign },
},
});For mode: "subscription", use subscription_data.metadata instead of payment_intent_data. If client_reference_id already holds your own user or cart ID, put the visitor ID in metadata.virling_vid instead; Virling checks that first.
Step 3: pass them to a Payment Link
A Payment Link has no server code, so the values go in the link URL. Stripe accepts client_reference_id there, with letters, digits, dashes and underscores up to 200 characters, and drops invalid values without an error (Stripe Payment Link URL parameters):
<a href="https://buy.stripe.com/abc123?client_reference_id=VISITOR_ID">Buy now</a>
With the Virling script on the page, you do not write this by hand: it adds client_reference_id to every buy.stripe.com link when the page loads and again on click, and never replaces a value that is already there. A plain link is enough:
<a href="https://buy.stripe.com/abc123">Buy now</a>
Payment Links also accept utm_source, utm_medium, utm_campaign, utm_content and utm_term, up to 150 characters each. Stripe's docs describe passing them on to your redirect URL after payment when the link is set to redirect, so read them on your thank-you page. Links opened from an email or a QR code skip your page, so they carry no visitor ID.
If you embed a pricing table instead, the ID goes in an attribute of the table; see how to track the source of Stripe pricing table sales. For a form on your own page, see Stripe embedded checkout UTM tracking or, with your own PaymentIntent, Stripe Elements UTM tracking.
The checkout snippet generator writes these snippets for your setup, and the full Stripe setup is on the Stripe integration page. Framework guides cover Next.js, Express, Nuxt, Vue, Angular, Convex, SvelteKit, Remix, Astro, Flask, Django, FastAPI, Rails, Phoenix, Laravel, Symfony and Spring Boot.
Where the values show up in Stripe
Metadata you set on the PaymentIntent shows in the Metadata section of the payment in the Dashboard, and you can query it with the Search API (Stripe search docs). client_reference_id and session metadata stay on the Checkout Session, which you read through the API or the checkout.session.completed webhook.
One sale, from tagged link to payments list
Example only: the buyer, the IDs, the price and the dates are made up. A SaaS with a $29 monthly plan links to its site from a newsletter and keeps its own user ID in client_reference_id.
- May 4, 09:00, the tagged link: a reader opens
https://yourdomain.com/?utm_source=newsletter&utm_medium=email&utm_campaign=may-issuein a mail app that sends no referrer. The script stores the visit against the visitor IDvexample2077. - May 11, 14:00, back without tags: the same browser returns by typing the URL. That is a second visit, Direct, with the same ID.
- May 11, 14:05, checkout: the server creates the session with
mode: "subscription",client_reference_id: "user_311"andmetadata: { virling_vid: "vexample2077" }. - May 11, 14:08, paid: Stripe creates the subscription, its first invoice and a $29.00 charge.
- The next sync: Virling finds the session through the subscription.
metadata.virling_vidis set, souser_311is not read. With the default last non-direct model, the Email visit on May 4 gets the credit.
The row in the payments list at /app/yourdomain.com/payments, for this example:
| Customer | Source | Spent | Time to complete |
|---|---|---|---|
| A generated name | $29.00 | 7d |
Open the row and the journey shows both visits, with the first marked Credited and Campaign may-issue. Tags read from the URL at checkout would have been empty, because the May 11 visit had none. Each renewal keeps the channel of this first payment and needs no metadata (renewals).
Symptoms, causes and fixes
Open the payment in the payments list and look for Visitor under Details:
| What you see | Cause | Fix |
|---|---|---|
| No visitor ID on any payment | The session is created where there is no cookie, such as a background job or a webhook handler | Read virling_vid in the request the buyer's browser sends, and pass it on |
| No visitor ID when a separate frontend calls your API | The browser does not send the cookie: fetch to another origin leaves cookies out by default | Send credentials and allow them in CORS, with the API on your domain or a subdomain, or send window.virling?.vid?.() in the request body |
| Session metadata is set, but the payment in the Dashboard has none | Stripe does not copy session metadata to the PaymentIntent or Subscription | Nothing to fix for Virling, which reads the session. To see it in Stripe, set payment_intent_data.metadata or subscription_data.metadata too |
| The ID is on the subscription, but the payment is Unattributed | It is only in subscription_data.metadata, which is not read | Set client_reference_id or metadata.virling_vid on the session |
| Visitor is your own user or cart ID | client_reference_id holds your ID and is read as the visitor ID | Keep it there and add metadata.virling_vid, which is checked first |
| There is a visitor ID, but the payment is Unattributed | No visit of that visitor was recorded inside the lookback window before the payment | Run the script on every page where people arrive, and choose a longer window if buyers take longer |
| A second test payment shows the channel of the first | Both have the same Stripe customer, so the second counts as a renewal | Use a new customer for each test |
| A one-off invoice is Unattributed | For an invoice without a subscription, only the metadata of the charge and its PaymentIntent is read | Set metadata.virling_vid there; see Stripe invoice attribution |
A payment made before a fix usually stays Unattributed, so make a new one to check, with the steps in the Stripe docs.
Why UTM in metadata is not attribution
A UTM tag in metadata records one visit, usually the one that ended in checkout. It cannot tell you:
- About earlier visits: a buyer who found you from a newsletter and came back a week later from search shows only the second one.
- About visits without tags: search, referrals and AI answers carry no UTM, so those payments look untagged.
- About buyers who come back on a new device or from a bookmark: the tags you stored are gone.
A visitor ID solves this. Stripe holds one short ID, and your analytics holds every visit behind it, so you can pick first touch or last touch later without changing checkout. How that join works, step by step, is in how to track Stripe revenue by traffic source. If checkout.stripe.com shows up as a source in your reports, see checkout.stripe.com referral traffic. For naming the tags themselves, see which UTM parameters to use. Selling credit packs or plans in an AI app? See Stripe for AI apps.
Frequently asked questions
Does Stripe Checkout keep the UTM parameters from my page?
No. A Checkout Session only stores what your server passes when it creates the session. Put the UTM tags in metadata or pass a visitor ID in client_reference_id.
Can I add UTM parameters to a Stripe Payment Link?
Yes. Payment Links accept utm_source, utm_medium, utm_campaign, utm_content and utm_term in the URL, and Stripe passes them on to your redirect URL after payment when the link is set to redirect. Values must be letters, digits, dashes or underscores, up to 150 characters.
Should I use client_reference_id or metadata?
client_reference_id is one string of up to 200 characters, and it is the only one of the two you can set from a Payment Link URL. Metadata holds up to 50 keys, so it fits several UTM tags. Virling reads either.
Why does my session metadata not show on the payment?
Stripe does not copy Checkout Session metadata to the PaymentIntent or Subscription. Set payment_intent_data.metadata or subscription_data.metadata as well if you want the values there.
Is UTM in metadata enough for attribution?
It tells you the tags of one visit, usually the last. It misses earlier visits, visits without tags and buyers who come back days later. A visitor ID joined to every visit gives the whole path.
Should I put the visitor ID in subscription_data.metadata?
Not as the only place. Stripe saves it on the Subscription, and Virling does not read the Subscription's metadata. Put the ID in client_reference_id or metadata.virling_vid on the Checkout Session. Renewals keep the channel of the customer's first payment, so they need no ID of their own.
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.