Blog / Measuring in PostHog and Stripe
PostHog data warehouse: joining Stripe revenue to product events
PostHog's data warehouse syncs Stripe into tables you can join to events in SQL. Setup, the join key, three queries, and what the sync costs.
The PostHog data warehouse syncs external sources, Stripe first among them, into tables you can query with SQL next to your events and persons. For a SaaS, that means one query can answer questions neither tool answers alone: which acquisition channel brings paying customers, whether activated users convert to paid more often, which paying accounts stopped using the product. Setup takes a restricted Stripe key and one decision about the join key. The first million synced rows each month are free.
What the data warehouse is
PostHog's data warehouse docs describe four pieces:
- Sources. Managed connectors for Stripe, Postgres, Salesforce, HubSpot and others, plus file uploads (CSV, JSON, Parquet) or imports from S3 and similar storage. Managed sources sync on a schedule you set.
- SQL. One editor queries the synced tables and PostHog's own tables (
events,persons,sessions,groups) together. - Views. A saved query becomes a view other queries can reference. Ticking "Materialize this view" stores the result and refreshes it daily by default.
- Insights. Query results chart like any other insight and sit on dashboards.
On cost, the pricing page bills "rows synced." The first 1,000,000 rows a month are free, then $0.000015 per row up to 10 million, falling by tier above that. Every row synced in the first 7 days of a new source is free, so the historical import of your Stripe account costs nothing. Our PostHog pricing article covers the rest of the bill.
Step 1: connect Stripe
The Stripe source docs give the path: Data pipeline, Sources tab, New source, Stripe. Authenticate with OAuth or, as PostHog recommends, a restricted API key created in Stripe under Developers, API keys. The key needs read access on the Core resources (charges, customers, products and others), on Billing (invoices, prices, subscriptions and others) and on Connect. Write access on Webhooks is optional and lets PostHog register its webhook for you. If your Stripe account is not set to English, switch it before connecting.
You then choose how each table syncs. This choice decides whether your numbers are right:
| Sync method | What it does | Use it for |
|---|---|---|
| Webhook (recommended) | Stripe pushes changes, applied at the next scheduled sync | Tables whose rows change: subscriptions, invoices, customers |
| Append-only (incremental) | Fetches new rows by Stripe's created cursor | Rows that never change after creation. It misses updates to existing rows |
| Full refresh | Re-downloads every row each sync | Small tables. PostHog warns it is costly on large accounts |
The trap is append-only on subscriptions. A subscription created as active and canceled three months later stays active in your table, and every churn query built on it undercounts. Use the webhook for anything with a status.
Synced tables carry a stripe_ prefix (stripe_customer, stripe_invoice, stripe_subscription), and you can add your own prefix at setup. Amounts keep Stripe's convention: the Invoice object stores amount_paid "in the smallest currency unit," so cents for USD.
Step 2: pick the join key
Stripe knows a customer by cus_ ID and email. PostHog knows a person by distinct IDs and properties. You need one value present on both sides.
Email is the default. PostHog's join docs pair events.distinct_id with stripe_customer.email, which only works if you identify users by email. If you identify by your own user ID, match on the person's email property instead, lowercased on both sides. PostHog's own example query does exactly that. It needs you to set email as a person property when you call identify, which our PostHog identify article covers.
The metadata field is sturdier. PostHog's revenue setup asks you to store the user's distinct ID in a posthog_person_distinct_id metadata field when your code creates the Stripe customer. For customers that already exist, it says to add the same field to a new subscription, payment intent or invoice instead. This survives a customer who pays with a different email from the one they signed up with, which email matching never will.
One mistake to avoid: persons.id is a UUID that PostHog generates. It never matches a Stripe field, even if your distinct IDs are emails.
Step 3: query join, saved join, or warehouse property
PostHog offers three ways to use Stripe data, and they are not interchangeable:
| Method | How it works | Where the data is usable |
|---|---|---|
| Query join | A JOIN written in one SQL query | That query only |
| Saved table join | Defined once from the SQL editor or the Data Catalog's Relationships tab, applied whenever the source table is queried | SQL, insight filters and breakdowns |
| Warehouse property | Copies a synced column onto person or group properties at each sync | Everywhere a person property works, including feature flags, experiments and surveys |
The warehouse properties docs explain why the third exists: joins resolve at query time, so flags and experiments, which read stored properties, cannot see them. Copying plan from Stripe onto persons is how you target a flag at paying users. Two catches: the key column must hold a distinct ID (an email column only works if your distinct IDs are emails), and a sync never creates a person, so Stripe customers who never used the product are skipped.
Start with query joins. Promote a join to a saved one when you write it for the third time.
Three queries worth running
Each query below matches on lowercased email and counts USD only. Open the schema panel in the SQL editor first: column names and types follow your project, and a field may differ from what is shown here. Run each query, check a few rows against Stripe by hand, then save it as an insight.
Paid revenue by first-touch channel
PostHog stores the first-touch UTM source on the person as $initial_utm_source, backfilled when the user is identified, per its UTM docs. Joined to paid invoices, it shows which channel brings revenue rather than signups.
WITH paid AS (
SELECT
lower(c.email) AS email,
sum(i.amount_paid) / 100.0 AS paid_revenue
FROM stripe_invoice AS i
INNER JOIN stripe_customer AS c ON c.id = i.customer
WHERE i.status = 'paid'
AND i.currency = 'usd'
AND i.created >= now() - INTERVAL 180 DAY
GROUP BY lower(c.email)
)
SELECT
coalesce(p.properties.$initial_utm_source, 'direct or unknown') AS channel,
count() AS paying_customers,
round(sum(paid.paid_revenue), 2) AS revenue_180d,
round(avg(paid.paid_revenue), 2) AS revenue_per_customer
FROM persons AS p
INNER JOIN paid ON lower(p.properties.email) = paid.email
GROUP BY channel
ORDER BY revenue_180d DESC
If two persons share an email (a user who signed up twice), their revenue counts twice. Check the total against Stripe once before you trust the split.
Paid conversion of activated versus non-activated signups
This is the query that turns an activation definition into money. Replace signed_up and project_created with your own signup and activation events. The 30-day lag leaves recent signups time to pay.
WITH signups AS (
SELECT
lower(person.properties.email) AS email,
min(timestamp) AS signed_up_at
FROM events
WHERE event = 'signed_up'
AND timestamp >= now() - INTERVAL 210 DAY
AND timestamp < now() - INTERVAL 30 DAY
GROUP BY lower(person.properties.email)
),
activated AS (
SELECT DISTINCT s.email AS email
FROM events AS e
INNER JOIN signups AS s ON lower(e.person.properties.email) = s.email
WHERE e.event = 'project_created'
AND e.timestamp >= s.signed_up_at
AND e.timestamp <= s.signed_up_at + INTERVAL 7 DAY
),
paying AS (
SELECT DISTINCT lower(c.email) AS email
FROM stripe_invoice AS i
INNER JOIN stripe_customer AS c ON c.id = i.customer
WHERE i.status = 'paid' AND i.amount_paid > 0
)
SELECT
if(email IN (SELECT email FROM activated), 'activated in 7 days', 'not activated') AS segment,
count() AS signups,
countIf(email IN (SELECT email FROM paying)) AS became_paying,
round(100.0 * countIf(email IN (SELECT email FROM paying)) / count(), 1) AS paid_conversion_pct
FROM signups
GROUP BY segment
A large gap between the two rows says your activation event predicts revenue, and every point of activation has a price. No gap means the event is the wrong one, which is worth knowing before you build onboarding around it.
Paying customers who went quiet
The most actionable of the three, because it ends with names. It lists customers with an active subscription and no event in the last 14 days. It is only correct if stripe_subscription syncs by webhook.
SELECT
lower(c.email) AS email,
c.id AS stripe_customer_id
FROM stripe_customer AS c
WHERE c.id IN (
SELECT customer FROM stripe_subscription WHERE status = 'active'
)
AND lower(c.email) NOT IN (
SELECT DISTINCT lower(person.properties.email)
FROM events
WHERE timestamp >= now() - INTERVAL 14 DAY
AND person.properties.email IS NOT NULL
)
ORDER BY email
Stripe gives subscriptions in a trial the trialing status, so trials are left out on purpose. Save it as a materialized view and the list refreshes every day.
What happened to revenue analytics
PostHog used to ship a revenue analytics dashboard on top of the Stripe source. The revenue analytics docs now say the dashboard "has been removed." What remains are managed views such as revenue_analytics_customer, revenue_analytics_subscription and revenue_analytics_revenue_item, created when you add a revenue source. The revenue item view applies deferred revenue and currency conversion for you. These views work in the SQL editor and SQL insights, not in the visual Trends or Funnels builder.
Once Stripe customers carry the posthog_person_distinct_id metadata, PostHog also exposes persons_revenue_analytics and groups_revenue_analytics tables mapping each person or group to its all-time revenue. If you run several currencies, build on the managed views rather than raw stripe_invoice: the conversion is already done.
When a spreadsheet is still enough
Below about a hundred paying customers, export the Stripe customer list and a PostHog cohort as CSV and match them on email in a spreadsheet. It takes an hour and answers the channel and activation questions once. The warehouse pays off when you ask the same question every week, when you want the answer on a dashboard next to the funnel, or when you want a Stripe value inside a feature flag.
Whichever route you take, read the output as a ranking of gaps. If activated signups convert to paid far more often, the Activation stage of your AARRR funnel is the priority, and the gap between the two conversion rates multiplied by monthly signups and average revenue gives you its price. If a channel brings signups but little revenue, it is an acquisition problem with a number on it. Price each gap in monthly dollars, pick the largest, and work on that one this week.
Frequently asked questions
What is the PostHog data warehouse?
It is the part of PostHog that syncs external sources such as Stripe, HubSpot or Postgres into tables you query with SQL next to your events and persons. You can join those tables to PostHog data, save queries as views, materialize them on a schedule, and chart the results in insights.
How much does the PostHog data warehouse cost?
PostHog bills synced rows. The first 1 million rows each month are free, then the price per row falls by tier, starting at $0.000015 per row. Every row synced in the first 7 days of a new source is free, which covers the historical import. Check the pricing page, since tiers change.
How do I join Stripe customers to PostHog persons?
The simplest key is email: lowercase the Stripe customer's email and the person's email property and match them. PostHog's join docs show this pairing. For revenue analytics, PostHog instead asks you to store the user's distinct ID in a posthog_person_distinct_id metadata field on the Stripe customer.
Can I use Stripe data in PostHog feature flags?
Not through a join. Joins resolve when a query runs, so feature flags, experiments and surveys cannot see them. To target a flag on a Stripe value such as plan, use warehouse properties, which copy a synced column onto person or group properties on every sync.
Sources
- PostHog docs, Data warehouse: https://posthog.com/docs/data-warehouse
- PostHog docs, Linking Stripe as a source: https://posthog.com/docs/data-pipelines/sources/stripe
- PostHog docs, Joining data: https://posthog.com/docs/data-warehouse/join
- PostHog docs, Views: https://posthog.com/docs/data-warehouse/views
- PostHog docs, Warehouse properties: https://posthog.com/docs/data-warehouse/warehouse-properties
- PostHog docs, Revenue analytics: https://posthog.com/docs/revenue-analytics
- PostHog docs, Connect revenue to customers: https://posthog.com/docs/revenue-analytics/connect-to-customers
- PostHog docs, Revenue analytics managed views: https://posthog.com/docs/revenue-analytics/managed-views
- PostHog, Pricing: https://posthog.com/pricing
- PostHog pocket guide, Which features drive revenue?: https://posthog.com/learn/warehouse/pocket-guide/features-drive-revenue
- PostHog docs, UTM segmentation: https://posthog.com/docs/data/utm-segmentation
- Stripe API reference, The Subscription object: https://docs.stripe.com/api/subscriptions/object
- Stripe API reference, The Invoice object: https://docs.stripe.com/api/invoices/object