Track Stripe revenue by traffic source

Updated

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.

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.

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:

text
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

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.

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 and DataPocket vs Plausible show which ones connect to Stripe and what they charge for it. Google Analytics 4 needs ecommerce events you send yourself, and Umami reads revenue from events too.

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

Track Stripe revenue by traffic source · DataPocket