---
title: "Track Stripe revenue by traffic source"
description: "See which channels, referrers and campaigns bring Stripe customers. Works with Stripe Checkout and Payment Links without code, or with Checkout Session metadata."
url: "https://datapocket.vo1d.studio/guides/stripe-revenue-attribution"
lang: "en"
updated: "2026-11-23"
---

# Track Stripe revenue by traffic source

Connect a restricted Stripe key to DataPocket, then either add `?session_id={CHECKOUT_SESSION_ID}` to your Checkout or Payment Link success URL (no code) or pass the visitor's `dp_vid` cookie in the Checkout Session metadata. Each payment is then matched to the visitor who paid and credited to the channel, campaign and landing page of their first visit.

What this guide answers:

- Step 1: how do you connect Stripe?
- Step 2a: how do you attribute payments without code?
- Step 2b: how do you attribute payments with Checkout Session metadata?
- How are renewals and refunds handled?

## Step 1: how do you connect Stripe?

In Stripe → Developers → API keys, create a restricted key with Read on Checkout Sessions, Invoices, Charges and Customers, and Write on Webhook Endpoints (so DataPocket can register its webhook for you). Paste it in DataPocket under Settings → Revenue → Stripe.

> **No DataPocket account yet?** Stripe revenue attribution is part of the free plan: unlimited sites, 5 years of history, no card. [Create a free account](https://datapocket.vo1d.studio/signup)

## Step 2a: how do you attribute payments without code?

Set the success URL of your Checkout Session or Payment Link to include the session ID:

```
https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}
```

![Two ways to match a Stripe payment to a visitor: a session_id in the Checkout or Payment Link success URL, or the dp_vid cookie in Checkout Session metadata](https://datapocket.vo1d.studio/guides/stripe-revenue-attribution/stripe-checkout-session-attribution-paths.svg)

When the buyer lands on that page, the tracking script reports the session ID, DataPocket fetches the session from Stripe with your key, and the sale is linked to that visitor.

## Step 2b: how do you attribute payments with Checkout Session metadata?

If you create Checkout Sessions on your server, pass the DataPocket cookies as metadata. This also works when the buyer never reaches your success page:

```js
const session = await stripe.checkout.sessions.create({
  // …your line_items, mode, success_url…
  metadata: {
    datapocket_visitor_id: req.cookies.dp_vid,
    datapocket_session_id: req.cookies.dp_sid,
  },
});
```

Python and PHP versions are in each framework's [install guide](https://datapocket.vo1d.studio/docs).

## How are renewals and refunds handled?

- Subscription renewals (`invoice.paid`) inherit the visitor of the customer's first payment, so recurring revenue stays on the channel that found them.
- Refunds (`charge.refunded`) mark the payment refunded, and it stops counting as revenue.

Comparing tools for Stripe revenue? [DataPocket vs DataFast](https://datapocket.vo1d.studio/compare/datafast) and [DataPocket vs Plausible](https://datapocket.vo1d.studio/compare/plausible) show which ones connect to Stripe and what they charge for it. [Google Analytics 4 needs ecommerce events you send yourself](https://datapocket.vo1d.studio/compare/google-analytics), and [Umami reads revenue from events too](https://datapocket.vo1d.studio/compare/umami).

## Questions

### Does it work with Stripe Payment Links?

Yes. Add `?session_id={CHECKOUT_SESSION_ID}` to the Payment Link's confirmation page URL.

### Can DataPocket change anything in my Stripe account?

The restricted key can only read Checkout Sessions, Invoices, Charges and Customers, and create the webhook endpoint DataPocket uses. It can't create charges or refunds.

## Related

- [How to see which traffic sources make money](https://datapocket.vo1d.studio/guides/revenue-by-traffic-source)
- [DataPocket vs DataFast](https://datapocket.vo1d.studio/compare/datafast)
- [Install DataPocket on Next.js](https://datapocket.vo1d.studio/docs/nextjs)
- [All guides](https://datapocket.vo1d.studio/guides)
