> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datalyr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stripe

> Connect Stripe payments and deterministically link them to web visitors.

Stripe sends payments, subscriptions, invoices, refunds, and disputes to Datalyr. Add the Datalyr visitor ID to Stripe objects so the payment can be linked to the exact web journey.

## Connect Stripe

<Steps>
  <Step title="Open Sources">
    Find **Stripe** and select **Connect**.
  </Step>

  <Step title="Authorize the account">
    Complete Stripe Apps OAuth and choose the Stripe account used by this workspace.
  </Step>

  <Step title="Link web visitors">
    Follow the setup dialog that opens after authorization. Choose the snippet matching your Stripe integration.
  </Step>

  <Step title="Run one payment">
    Use the supported Stripe test or live flow and verify the resulting event in Datalyr.
  </Step>
</Steps>

No manual Stripe webhook endpoint is required for the current OAuth connection.

## Checkout Sessions

Get the current Datalyr identity in the browser:

```ts theme={null}
const datalyrStripe = datalyr.getStripeMetadata()
// { client_reference_id, metadata: { visitor_id } }
```

Pass it when your server creates the Checkout Session:

```ts theme={null}
const session = await stripe.checkout.sessions.create({
  ...datalyrStripe,
  mode: 'subscription',
  line_items: [{ price: 'price_123', quantity: 1 }],
  success_url: 'https://example.com/success',
  cancel_url: 'https://example.com/pricing'
})
```

The completed Checkout Session uses `client_reference_id` for deterministic attribution.

## PaymentIntents

```ts theme={null}
const visitorId = datalyr.getVisitorId()

await stripe.paymentIntents.create({
  amount: 9900,
  currency: 'usd',
  metadata: { visitor_id: visitorId }
})
```

## Subscriptions

Add `metadata.visitor_id` to the Subscription. Subscription metadata propagates into the supported invoice flow so later renewals remain associated with the original customer identity.

```ts theme={null}
await stripe.subscriptions.create({
  customer: 'cus_123',
  items: [{ price: 'price_123' }],
  metadata: { visitor_id: visitorId }
})
```

## Stripe Payment Links

The current Web SDK automatically decorates supported `buy.stripe.com` Payment Links and Stripe pricing-table or buy-button embeds. It adds the visitor reference without requiring custom checkout code. Do not append unsupported parameters to already-created `checkout.stripe.com` Session URLs.

## What appears in Datalyr

Stripe reporting includes revenue, purchases, conversions, net revenue, refunds, disputes, and subscription lifecycle metrics such as new and cancelled subscriptions when present in the source data.

## Verify attribution

1. Open the website in a private window with test UTMs.
2. Confirm the `pageview` event and visitor ID.
3. Complete a Stripe test payment through the same integration path used in production.
4. Find the Stripe event and confirm value, currency, customer, and transaction identifiers.
5. Open the customer journey and confirm the web visit precedes the payment.

<Warning>
  Email matching is a fallback, not the preferred implementation. Use `client_reference_id` or `metadata.visitor_id` whenever you control Stripe object creation.
</Warning>
