# Stripe client_reference_id: a plain guide

What to put in client_reference_id, what Stripe drops without telling you, where it comes back, and copy-ready examples for links and Checkout.

By the Totems team. Published 2026-12-03. Updated 2026-12-03. https://usetotems.com/blog/stripe-client-reference-id

**What goes in client_reference_id?** Any text you choose that helps you find the buyer later: a visitor id, a cart id or a customer id. On Payment Links it may hold letters, numbers, dashes and underscores, up to 200 characters. Stripe silently drops anything else. It comes back on the Checkout Session and in checkout.session.completed.

`client_reference_id` is a luggage tag. You tie it on when the buyer goes into Stripe. You read it when they come out.

## What is allowed

Stripe's page for Payment Links gives three rules. Letters, numbers, dashes and underscores only. Up to 200 characters. If a value breaks a rule, it is silently dropped, and the payment page still works.





## Where it goes and comes back



It sits on the Checkout Session. That is a different object from the payment. Stripe says metadata does not copy between objects by itself, apart from a few named cases. So if a tool reads only payments, it won't see your tag.



## Copy-ready: Payment Link

Add it to every buy button on your page. This reads an id you saved earlier.

```html title="Your page"
<a class="buy" href="https://buy.stripe.com/YOUR_LINK">Buy</a>
<script>
  const id = localStorage.getItem("visitor_id"); // saved only after a yes
  if (id && /^[A-Za-z0-9_-]{1,200}$/.test(id)) {
    for (const a of document.querySelectorAll("a.buy")) {
      const u = new URL(a.href);
      u.searchParams.set("client_reference_id", id);
      a.href = u;
    }
  }
</script>
```

## Copy-ready: Checkout

```ts title="Your server"
await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{ price: "price_123", quantity: 1 }],
  success_url: "https://studio.example/thanks",
  client_reference_id: visitorId,
  subscription_data: { metadata: { visitor_id: visitorId } },
});
```

For a one-time payment use `payment_intent_data` in place of `subscription_data`.

## Read it





## A checklist

| Check | Pass if |
|---|---|
| Only letters, numbers, - and _ | Yes |
| Under 200 characters | Yes |
| New for each visitor | Yes |
| Nothing private in it | Yes |
| You read it from the session, not the payment | Yes |
| A buyer with no id still pays | Yes |



## What can go wrong

- **Email as the id.** It has an @ and a dot, so it is dropped on a Payment Link. It's also private.
- **The link is shared.** A buyer copies your address with their id and sends it to a friend. Now two people carry one id. Check the email on the payment.
- **Two tools, one field.** A booking plugin and a tracking tool can't both use it.
- **Reading too early.** Some payment methods confirm days later. Wait for `paid`.

## When not to use Totems

If your own system already knows who is logged in, put your user id in the field and you are done. You don't need a tracking tool.

Totems is for when the buyer is a stranger until they pay. Its script passes the visitor id to the checkouts you choose and matches it when the payment arrives. If you use the field for something else, the [Stripe guide](https://usetotems.com/docs/tools/stripe) shows how to use metadata only. That connection is not yet tested with a live account.

## Questions

### Can the buyer see it?

On a Payment Link it is part of the address, so yes. Never put a password, an email or anything private in it.

### Can two buyers share one value?

Stripe won't stop you on a link you reuse. But then you can't tell them apart. Use a new value for each visitor.

### Is it on the payment or the customer?

It is on the Checkout Session. If you need it on the payment too, also set payment_intent_data.metadata.

### What if my shop plugin already uses it?

Leave it alone. Put your id in metadata instead, with your own key, such as visitor_id.

## Sources

- [Stripe: Track a payment link (client_reference_id)](https://docs.stripe.com/payment-links/url-parameters), checked 2026-12-03
- [Stripe: The Checkout Session object](https://docs.stripe.com/api/checkout/sessions/object), checked 2026-12-03
- [Stripe: Metadata](https://docs.stripe.com/metadata), checked 2026-12-03
