How to set up Stripe metadata attribution
Write a visitor ID and UTM fields into Stripe metadata for Checkout, Payment Links and subscriptions, and see which copies Stripe makes and which it skips.
Muzahid Maruf, FounderUpdated
On this page
Explore with AI
Opens this article inside the chosen assistant with a ready-made prompt.
Stripe metadata attribution setup is the practice of writing a visitor ID and 6 UTM fields into the metadata of every Stripe object that carries a payment, so one report can show which channel pays your MRR.
Per Stripe's metadata documentation, Stripe forwards metadata in only 4 documented cases. A source set on the Checkout Session alone therefore reaches none of the invoices and charges that follow. This guide covers the full chain in 6 steps.
Step 1 captures the source on your own domain. Step 2 chooses the keys. Step 3 writes the keys onto the Checkout Session. Step 4 carries the ID through Payment Links. Step 5 reads the metadata back from webhooks.
Step 6 tests the chain in a Stripe sandbox. Stripe Checkout, Payment Links and Stripe Billing each need their own field, which is why the setup runs to 6 steps.
Key takeaways
- Stripe allows 50 metadata pairs per object, with keys up to 40 characters and values up to 500, so a visitor ID plus 6 UTM fields uses 7 slots.
- A Checkout Session's metadata is not copied to its PaymentIntent or Subscription. Set payment_intent_data.metadata or subscription_data.metadata yourself.
- Invoices created from June 29, 2023 hold a snapshot of the subscription's metadata, while the renewal charge holds none, so read renewals from the invoice.
- client_reference_id holds up to 200 characters and is the per-click field for Payment Links, where UTM codes reach only your redirect URL.
- Stripe Search finds metadata on 7 object types within 1 minute, but not on Checkout Sessions.
What can Stripe metadata hold?
Stripe metadata is a set of key-value pairs attached to an API object, and Stripe keeps metadata on Customers, Checkout Sessions, PaymentIntents, Charges, Subscriptions, Invoices and other objects.
The limits in the table below (October 2026) shape every schema in this guide, according to Stripe. In practice, start with a single key named vid, pointing at visit history stored in your own database.
Copy UTM fields onto Stripe only when the source must appear in webhook payloads. Stripe's metadata guide recommends the same split for bigger records.
A 7-slot schema leaves 43 spare slots for later needs, such as a plan code or an experiment ID.
| Field | Limit | Consequence |
|---|---|---|
| Metadata pairs per object | 50 | A visitor ID plus 6 UTM fields uses 7 |
| Metadata key | 40 characters | utm_campaign takes 12 |
| Metadata value | 500 characters | Parse landing URLs into discrete values |
| Readable with | Secret keys only | Not from Stripe.js in the browser |
| client_reference_id | 200 characters | Fits a visitor ID, while campaign data goes in metadata |
| UTM codes on a Payment Link | 5 parameters, 150 characters each | Letters, digits, dashes and _ only |
| Checkout Session lifetime | 30 minutes to 24 hours, default 24 | Keys written at creation can be a day old at payment |
Limits from Stripe's metadata, Checkout Session and Payment Links documentation, October 2026.
Which Stripe objects inherit metadata?
Stripe objects inherit metadata only in 4 documented cases, and Customer metadata never copies down, so look it up by customer ID. Three of the exceptions are one-time snapshots, which stay unchanged when you edit the parent later.
The 4th shows the subscription's current values.
| Exception | From | To | What Stripe copies |
|---|---|---|---|
| 1 | PaymentIntent | Charge | A snapshot when the charge is created |
| 2 | Payment Link | Checkout Session | A snapshot when the Session is created |
| 3 | Subscription | Invoice | A snapshot in the invoice's parent details |
| 4 | Subscription | Invoice line item | The current values, for line items of type subscription |
Copy rules from Stripe's metadata documentation, October 2026.
Worked example: a $49 monthly plan
A newsletter reader buys a $49 plan through Stripe Checkout and stays 12 months, which produces 12 invoices and 12 charges worth $588. Metadata on the Checkout Session alone reaches 0 of those 24 objects. Adding subscription_data.metadata puts the source on the Subscription and all 12 invoices, and the 12 charges still carry none.
Per Stripe's Invoice reference, parent.subscription_details.metadata is immutable once the invoice is finalized and exists only on invoices created from June 29, 2023. Fixing a mistyped utm_campaign after the 3rd invoice leaves the typo on 3 invoices.
A Charge in the current Stripe API has no invoice field, so report from invoices or from the invoice.paid event. Alternatively, go from a charge through its PaymentIntent to the Invoice Payments API.
How do you set up Stripe metadata attribution step by step?
Building the chain in a Stripe sandbox first costs nothing and exposes every gap before a real card is charged.
The test card 4242 4242 4242 4242, with any future expiry date and any 3-digit CVC, completes a payment, according to Stripe's testing guide. A failed handler in a sandbox shows up within hours, long before live traffic arrives.
Each of the 6 steps below names the exact field and the Stripe object where the value lands. Work through the steps in order, because Step 5 and Step 6 read what Step 3 and Step 4 wrote.
Step 1: How do you capture the source on your own domain?
Capturing the source means reading the 5 UTM parameters on the first page view and storing them under a visitor ID. Store the record in a first-party cookie or in a Postgres table.
Stripe never sees the ad that sent the visitor, because your server creates the Stripe Checkout Session. According to WebKit's tracking prevention notes (October 2026), Safari's Intelligent Tracking Prevention deletes cookies created in JavaScript after 7 days without user interaction.
For instance, a visitor who clicks a newsletter link on Monday and buys 8 days later may show no JavaScript cookie in Safari. Why UTM parameters get stripped covers the other leaks in detail.
Step 2: Which 9 keys should the schema use?
A metadata schema is the fixed list of key names every Stripe write uses. Pick short, stable names, because Stripe Webhooks and backfills depend on them. The schema below uses 9 of the 50 slots.
Store both touches: 2 sets of 3 keys cost 6 slots and leave the credit rule for report time, as the attribution model comparison lays out.
In practice, ft_source keeps the newsletter that introduced a buyer, while lt_source keeps the Google Ads click that closed the sale. Write the first-touch keys once and never overwrite them.
Overwriting a first-touch value in 2026 would erase the evidence for every later model comparison.
| Key | Example value | Purpose |
|---|---|---|
| vid | A 36-character UUID | Join key to your stored visit history |
| ft_source, ft_medium, ft_campaign | newsletter, email, launch-2026 | First touch, written once and never overwritten |
| lt_source, lt_medium, lt_campaign | google, cpc, brand-2026 | Latest touch before checkout |
| click_id | a gclid or fbclid | Platform click ID for sending conversions back |
| first_touch_at | 2026-10-02T14:08:31Z | Time of the first visit in ISO 8601 |
Step 3: Which fields carry the keys on a Checkout Session?
The Checkout Session call (October 2026) is the moment your server hands the keys to Stripe. In practice, write all 3 fields in one call, so the Session, Subscription and invoice agree. In subscription mode, write 3 fields.
First, the Session's own metadata (1 key, vid) arrives with checkout.session.completed. Second, subscription_data.metadata (7 keys) lands on the Subscription and, through the snapshot, on every invoice. Third, client_reference_id takes up to 200 characters and comes back on the Session.
In payment mode, use payment_intent_data.metadata, which reaches the Charge as a snapshot, per the Checkout Session reference. The Node call below writes vid, 3 first-touch keys and 3 latest-touch keys. The Stripe Checkout attribution guide covers the redirect side.
// visitorId and attr come from your own first-party capture (step 1)const session = await stripe.checkout.sessions.create({ mode: "subscription", line_items: [{ price: "price_123", quantity: 1 }], client_reference_id: visitorId, // up to 200 characters, echoed on the Session metadata: { vid: visitorId }, // lands on the Checkout Session subscription_data: { metadata: { // lands on the Subscription, then on each invoice vid: visitorId, ft_source: attr.firstSource, ft_medium: attr.firstMedium, ft_campaign: attr.firstCampaign, lt_source: attr.lastSource, lt_medium: attr.lastMedium, lt_campaign: attr.lastCampaign, }, }, success_url: "https://example.com/welcome",});// mode: "payment" takes payment_intent_data: { metadata: { ... } } instead.Step 4: Can a Payment Link carry the visitor ID?
A Payment Link is a hosted Stripe checkout URL, and the 5 UTM codes on one reach only your redirect URL.
Stripe's tracking page says the codes pass to the redirect URL after payment, and only when the link's confirmation behavior is a redirect. Stripe does not describe saving the codes on the payment. Two routes do reach the payment.
For instance, one link each for newsletter, Google Ads and affiliate traffic gives 3 links.
Route 1 is a Payment Link per channel, created through the API with metadata on the link, which copies to every Checkout Session, plus the nested metadata fields for the PaymentIntent or Subscription underneath.
Route 1 suits 3 to 5 channels, such as Google Ads, Meta Ads and Product Hunt. Route 2 is a per-click ID: append ?client_reference_id=VISITOR_ID to the link.
Stripe silently drops an ID containing a dot or colon, so a UUID with dashes is safe. The Payment Link reference and the Payment Links attribution guide cover the rest.
curl https://api.stripe.com/v1/payment_links \ -u "<<YOUR_SECRET_KEY>>:" \ -d "line_items[0][price]=price_123" \ -d "line_items[0][quantity]=1" \ -d "metadata[lt_source]=newsletter" \ -d "subscription_data[metadata][lt_source]=newsletter"Step 5: Which webhook events return the metadata?
Reading metadata back (October 2026) means handling webhook events, because every Stripe event carries its object with that object's metadata. Most attribution work needs only these 4 events.
| Event | Object in the payload | Where the source sits |
|---|---|---|
| checkout.session.completed | Checkout Session | metadata and client_reference_id |
| customer.subscription.created | Subscription | metadata set through subscription_data |
| invoice.paid | Invoice | parent.subscription_details.metadata, the snapshot |
| charge.succeeded | Charge | metadata, payment mode only, copied from the PaymentIntent |
Event names from Stripe's event reference, October 2026.
Free trials have no charge yet, so trial-to-paid rates by channel start at customer.subscription.created. Count delayed payment methods on checkout.session.async_payment_succeeded.
Verify the Stripe-Signature header and key rows by subscription ID, since Stripe retries deliveries for up to 3 days in live mode and events can arrive out of order.
| Behavior | Limit |
|---|---|
| Retries of a failed webhook delivery, live mode | 3 days, exponential backoff |
| Retries of a failed sandbox delivery | 3 attempts over a few hours |
| Resending an event from the Stripe Dashboard | 15 days |
| Resending an event from the Stripe CLI | 30 days |
| Metadata search coverage | 7 object types, no Checkout Sessions |
| Clauses in one search query | 10, joined by AND or OR but not both |
| Time until new data is searchable | Under 1 minute |
| Search rate limit | 20 reads a second |
| Oldest API version that supports Search | 2020-08-27 |
Delivery and search limits from Stripe's webhook and search documentation, October 2026.
Stripe Search in the 2026 API takes metadata["vid"]:"VALUE" on charges, customers, invoices, PaymentIntents, prices, products and subscriptions, matching exactly and ignoring case.
Stripe points analytics workloads to Stripe Sigma and bulk exports to Data Pipeline, and its webhook documentation has the signature details.
curl -G https://api.stripe.com/v1/subscriptions/search \
-u "<<YOUR_SECRET_KEY>>:" \
--data-urlencode 'query=metadata["lt_source"]:"newsletter" AND status:"active"'Grouping active subscriptions by lt_source gives MRR by channel. For example, 12 newsletter subscriptions at $49 add up to $588 of MRR, a 36.2% share of the $1,625 total.
| lt_source | Active subscriptions | Plan | MRR | Share of MRR |
|---|---|---|---|---|
| newsletter | 12 | $49 | $588 | 36.2% |
| 8 | $99 | $792 | 48.7% | |
| affiliate | 5 | $49 | $245 | 15.1% |
| Total | 25 | $1,625 | 100% |
Illustrative figures, not customer data.
Step 6: How do you test the chain before you trust it?
A chain test (October 2026) is a Stripe sandbox checkout followed by 4 retrievals, one per object.
Run a subscription checkout in the sandbox, then retrieve the Checkout Session, the Subscription, the first invoice and the charge with 4 stripe get calls from the Stripe CLI. The Session shows 1 key and the Subscription shows 7.
The invoice shows the same 7 in its snapshot, and the charge shows none. Next, repeat the test with 1 payment-mode Session, where the charge should carry the PaymentIntent's keys, as in the table below.
Finally, open a Payment Link with ?client_reference_id=test-123 and confirm the value on the completed Session. A missing key on the invoice means subscription_data.metadata was not set on the Session call.
| Object retrieved | Subscription-mode test | Payment-mode test |
|---|---|---|
| Checkout Session | 1 key (vid) plus client_reference_id | 1 key (vid) plus client_reference_id |
| Subscription | 7 keys from subscription_data | Not created |
| First invoice | The same 7 keys in the snapshot | None |
| Charge | 0 keys | The PaymentIntent's keys |
Expected results of the Step 6 test, from the copy rules in Stripe's metadata documentation.
What does TrackRev do with the visitor ID?
TrackRev is SaaS affiliate software with revenue attribution built in, and we built its Stripe sync to read charges and never write them. The sync reads Stripe with a read-only restricted key, so it never writes metadata.
Its pixel keeps a visitor ID in a first-party cookie named vid and adds the ID to Payment Links, Buy Buttons and Pricing Tables on your pages.
For Checkout Sessions your server creates, pass the cookie value as the Session's reference ID or set metadata.vid on the PaymentIntent. The sync finds the Checkout Session through the charge's PaymentIntent, which Stripe documents for payment-mode Sessions only.
In our experience building TrackRev, Subscription checkouts are the case that needs identify().
| Order | Where each sync looks for the visitor ID |
|---|---|
| 1 | metadata.vid on the charge |
| 2 | client_reference_id on the Checkout Session |
| 3 | metadata.vid on the Checkout Session |
| 4 | The buyer's email, if you called identify() on your site |
Lookup order in TrackRev's Stripe sync.
Renewals inherit the first order's visitor through the subscription ID, so Month 12 credits the original channel without any subscription metadata. The Stripe sync runs hourly, 24 times a day.
Call identify() at signup too, since the pixel writes its cookie from JavaScript and Safari's 7-day cap applies.
Revenue figures need a paid plan from Indie at $29 a month (pricing), and setup steps sit in our Stripe integration page (October 2026). In practice, a buyer who never reaches identify() has no email to match.
When is Stripe metadata not enough?
Stripe metadata is not enough when a question needs more than a snapshot of 1 or 2 touches taken at purchase. We built TrackRev to keep the full click history under one visitor ID for this reason.
Keep the full history of visits and link clicks under the visitor ID, as in the multi-touch attribution setup guide.
Keeping the history lets you switch between First Touch, Last Touch and Linear credit in 2026 without rewriting any Stripe object.
If you only match each payment to a row in your orders table, a single reference ID is enough and 49 slots stay empty. Plan changes in the Stripe customer portal are covered in Stripe Customer Portal attribution.
Sales-led deals sent as Stripe Quotes can carry the source in the quote's subscription data, which lands on the Subscription on acceptance.
Found this useful? Share it.
Frequently asked questions
- No. Of the 4 cases where Stripe copies metadata, Checkout Session to PaymentIntent is absent. Set payment_intent_data.metadata in payment mode or subscription_data.metadata in subscription mode before the buyer pays.
- Stripe copies subscription metadata onto the invoice, not the charge. Read the invoice's parent subscription details, or fetch the subscription directly. Invoices created before June 29, 2023 hold no snapshot.
- Stripe passes 5 UTM codes of up to 150 characters each to your redirect URL after payment, and the codes never reach the charge. A per-click value belongs in client_reference_id, and a link per channel can carry metadata.
- Yes, across 7 object types, with the syntax metadata["key"]:"value". Checkout Sessions are excluded. Matching is exact and case-insensitive, and fresh records usually appear within 1 minute.
- The ID rides on a Payment Link URL as client_reference_id, and the Subscription, PaymentIntent or invoice carries it as metadata. Writing the same ID in both places costs only 1 slot.
- No. TrackRev reads Stripe with a read-only key and checks 4 places for the visitor ID, ending with the buyer's email through identify(). Revenue figures come with paid plans, starting with Indie at $29 a month.

Written by
Founder, TrackRev.io & Contant.io
Muzahid Maruf founded TrackRev.io, SaaS affiliate software with no limit on tracked revenue, and Contant.io. He writes about affiliate programs.
Writes about Marketing attribution · Link tracking · Revenue analytics · SaaS growth
Run your affiliate program without a revenue cap.
Affiliate software for indie hackers and small SaaS teams: $29 a month flat, 0% fees, link tracking and revenue attribution built in. Free to start, no card.