Track Stripe revenue
Pick the guide that matches how you sell through Stripe.
Pass userID to Stripe
Roadway ties a Stripe customer to your user through the user ID stored in the Stripe Customer's metadata.
Put the user ID in the Stripe Customer's metadata under the key user_id, or another key you agree with Roadway. Roadway doesn't read the Checkout Session, client_reference_id, or subscription or charge metadata. With Payment Links, copy the ID onto the Customer after checkout, for example from a checkout.session.completed webhook.
You need:
- A user ID that matches the value in your analytics tool and your Users table
- Developer access to your Stripe integration
- Your Stripe API keys, kept server-side only
Choose where to store it
| Your Stripe integration | Store user_id in |
|---|---|
| Checkout Sessions (API), new customer | metadata on the Customer. Create the Customer first and pass customer to the session. |
| Checkout Sessions (API), existing customer | metadata on the Customer, and pass customer to the session |
| Stripe Billing from your backend | metadata on the Customer |
| Payment Links | metadata on the Customer, set after checkout by a checkout.session.completed webhook that reads client_reference_id |
| No users in your product | Talk to Roadway. This needs custom modeling. |
Steps for Checkout Sessions
-
Create the customer with your user ID when the account is created:
const customer = await stripe.customers.create({ email: user.email, metadata: { user_id: user.id } // for example "usr_8f2c" }); -
Create the session for that customer:
const session = await stripe.checkout.sessions.create({ mode: 'subscription', customer: customer.id, line_items: [{ price: 'price_123', quantity: 1 }], success_url: 'https://example.com/welcome?session_id={CHECKOUT_SESSION_ID}', cancel_url: 'https://example.com/pricing' });Session and subscription metadata aren't needed. Only the Customer metadata is read.
-
For existing customers without the ID, update them in bulk:
await stripe.customers.update('cus_Nx8', { metadata: { user_id: 'usr_8f2c' } });
Steps for Payment Links
-
In the Stripe Dashboard, open Payment Links and select your link.
-
Click the arrow next to Copy, choose URL parameters, select Client reference ID, and enter a value.
-
Generate a per-visitor link on your site by appending
client_reference_id=<user ID>:https://buy.stripe.com/XXXX?client_reference_id=usr_8f2c -
Set
metadata.user_idon the Customer after checkout, for example in acheckout.session.completedwebhook that readsclient_reference_id:// webhook handler for checkout.session.completed const session = event.data.object; if (session.customer && session.client_reference_id) { await stripe.customers.update(session.customer, { metadata: { user_id: session.client_reference_id } }); }
client_reference_id allows alphanumeric characters, dashes, and underscores, up to 200 characters. Stripe silently drops invalid values. Metadata set on the Payment Link itself is copied to every session, so it can't hold a per-user ID.
Verify
-
Use Stripe test mode only to check that the metadata is set in the Dashboard. Roadway syncs live data only.
-
In the Stripe Dashboard, open the customer, and confirm
user_idunder Metadata. -
After Roadway syncs your live data, confirm each customer's user ID matches a row in your Users table:
SELECT c.customer_id, c.creator_user_id, u.user_id AS matched_user FROM roadway.dim__customers c LEFT JOIN roadway.dim__users u ON u.user_id = c.creator_user_id WHERE u.user_id IS NULL LIMIT 20;The query lists customers with no matching user. It should return few or no rows.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Customers have no user_id |
Customers created before you added metadata, or by a flow that doesn't set it | Backfill with customers.update |
Payment Link customers have no user_id |
The webhook didn't copy client_reference_id to the Customer |
Check the webhook, and that the value has only letters, numbers, dashes, underscores |
user_id formats differ from analytics |
Prefix or case differences | Standardize |
Vendor docs: Payment Links URL parameters (Stripe), Checkout Sessions API, Metadata (Stripe)
Stripe Payment Links with GA4
Use this only if you have no users in your product, for example when customers pay through a Stripe Payment Link.
If you have users, use Pass userID to Stripe instead.
The idea: redirect buyers to a thank-you page on your site with the Checkout Session ID in the URL. GA4 records that ID on the buyer's browser session.
This route needs custom modeling by Roadway and isn't available by default. Contact Roadway first.
You need:
- GA4 installed with Google Tag Manager (steps below). Steps for gtag.js are in the next section.
- Edit access to your Stripe Payment Links and your site
stripe_checkout_sessionssynced to your warehouse if you use Airbyte, or the Stripe connector
Steps
-
Create a thank-you page on your site, such as
https://example.com/thank-you. -
Redirect Payment Links to it. In Stripe, open each Payment Link, go to After payment, choose Don't show confirmation page, and set the redirect to:
https://example.com/thank-you?session_id={CHECKOUT_SESSION_ID}Stripe replaces
{CHECKOUT_SESSION_ID}with the real session ID. Do this for every Payment Link you use. -
Create a URL variable in GTM. Go to Variables > New > URL, set Component Type to Query, set Query Key to
session_id, and name itURL - session_id. -
Pass it to GA4. Open your Google tag, expand Shared event settings (or Fields to Set on a legacy GA4 Configuration tag), add parameter
checkout_session_idwith value{{URL - session_id}}, and save. Events fired on the thank-you page then carry the ID. -
(Optional) register a custom dimension. In GA4, go to Admin > Custom definitions > Create custom dimension, name it
Checkout Session ID, set Scope to Event, and set Event parameter tocheckout_session_id. You only need this to see the value in GA4 reports. The BigQuery export includes it inevent_paramsregardless. -
Publish the container.
With gtag.js instead of GTM
On the thank-you page, read the query parameter and send it as an event parameter:
var sessionId = new URLSearchParams(window.location.search).get('session_id');
if (sessionId) {
gtag('event', 'stripe_checkout_complete', { checkout_session_id: sessionId });
}
Verify
-
Make a live purchase and land on the thank-you page. Roadway syncs live data only, so test-mode sessions won't appear.
-
In GA4 DebugView, confirm an event on the thank-you page with
checkout_session_idequal to the ID in the URL. -
In BigQuery:
SELECT user_pseudo_id, (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'checkout_session_id') AS checkout_session_id FROM `your_project.analytics_PROPERTY_ID.events_*` WHERE (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'checkout_session_id') IS NOT NULL LIMIT 20; -
Confirm the same
checkout_session_idexists in Stripe'scheckout_sessionsdata.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
URL shows {CHECKOUT_SESSION_ID} literally |
Payment Link redirect is set to a static page, or placeholder misspelled | Use the exact placeholder |
| Parameter missing in GA4 | Variable or tag not published, or the page was loaded without the query string | Test in GTM Preview |
| Buyers who close the tab before redirect | Redirect doesn't run | Expected. Shows as missing attribution |
Vendor docs: Payment Links: after payment, Create custom dimensions (Google)
Stripe through Airbyte
If you land Stripe data in your warehouse with Airbyte, Roadway can build recurring-revenue metrics from the standard Stripe streams.
Roadway officially supports the Airbyte Stripe source connector.
You need:
- An Airbyte instance (cloud or self-hosted) and a warehouse destination Roadway can read. See Warehouse access.
- A Stripe restricted API key with read access to the streams below
- Your user ID stored in Stripe
Streams to sync
| Table | Description | Required |
|---|---|---|
stripe_customers |
Customers and metadata | Yes |
stripe_subscriptions |
Subscription lifecycle and billing | Yes |
stripe_subscription_items |
Items within subscriptions | Yes |
stripe_charges |
Charges | Yes |
stripe_invoices |
Invoices | Yes |
stripe_invoice_line_items |
Invoice line items | Yes |
stripe_products |
Product catalog | Yes |
stripe_prices |
Prices | Yes |
stripe_plans |
Legacy plans | Yes |
stripe_balance_transactions |
Balance transactions | Yes |
stripe_coupons |
Discounts and coupons | Yes |
stripe_events |
Webhook events | Yes |
stripe_checkout_sessions |
Checkout sessions | Required if you bill with Payment Links |
stripe_payment_intents |
Payment intents | Optional |
stripe_refunds |
Refunds | Optional |
Steps
- In Airbyte, create a Stripe source with your account ID, a start date, and the API key.
- Create a connection to your warehouse destination.
- Select the streams above.
- Set the sync mode to Incremental (Append or Append + Deduped) for each stream. Roadway deduplicates.
- Set the table prefix to
stripe_. - Run the first sync.
- Give Roadway read access to the destination schema. See your warehouse guide.
- Store your user ID in each Customer's metadata under
user_id. See Pass userID to Stripe.
Verify
SELECT COUNT(*) AS customers,
COUNT(CASE WHEN metadata LIKE '%user_id%' THEN 1 END) AS with_user_id
FROM stripe_customers;
The metadata column's format depends on your destination. Adapt the check so it extracts your user_id key properly.
Also confirm no duplicates:
SELECT id, COUNT(*) FROM stripe_customers GROUP BY id HAVING COUNT(*) > 1;
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Missing checkout sessions | Stream not selected | Add stripe_checkout_sessions |
| Old data missing | Start date too late | Set an earlier start date and re-sync |
Vendor docs: Airbyte Stripe connector, Airbyte sync modes