Link Stripe Checkout to visitors

Pass Boostra's visitor and session IDs into Stripe Checkout metadata so every payment is tied to the visit that produced it.

Updated

Connecting Stripe brings your payments into Boostra. To credit each payment to the right visitor, channel and landing page, the payment has to carry Boostra's IDs. The strongest way to do that is to put them into the metadata of the Stripe Checkout Session your server creates.

Read the IDs in the browser#

Once the tracker has loaded, window.boostra("ids") returns three values: visitorId (starts with bv_), sessionId (starts with bs_) and externalId (your own user ID, set after you identify the user). Send them to your server along with the checkout request.

Add them to the Checkout Session#

On your server, copy the IDs into the session's metadata, and the same fields into subscription_data.metadata for subscriptions, so renewals are linked as well:

// In the browser, before you call your checkout endpoint:
const ids = window.boostra?.("ids") ?? {};
// On your server, when you create the Checkout Session:
const metadata = {
  boostra_visitor_id: ids.visitorId,
  boostra_session_id: ids.sessionId,
  boostra_external_id: ids.externalId,
};
const session = await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{ price: priceId, quantity: 1 }],
  success_url: successUrl,
  metadata,
  subscription_data: { metadata },
});

Use optional chaining (window.boostra?.(...)) so your checkout keeps working if the tracker is blocked. Leave a value out when it is null; Boostra simply falls back to the next matching method.

If you sell through Stripe Payment Links (buy.stripe.com), the tracker adds the visitor ID to the link as client_reference_id automatically. You don't need to change anything.

Check that it works#

  1. Make a real purchase on your live site (Boostra reads live payments only).
  2. Open the visitor in User Profiles and look at the Orders tab, or check that the payment shows up in your revenue by channel.

The app also has a developer page with the same snippet, "Link Stripe revenue with traffic", at /docs/stripe on platform.getboostra.com.

Payments that carry no IDs can still be matched by other signals, but less reliably. See How revenue is matched.

Related articles