Connect to customers
Contents
Revenue analytics is currently works best for:
- Small to medium-sized companies
- Companies with subscription models (mostly SaaS)
If you process more than 20,000 transactions per month, or your revenue comes primarily from one-off payments rather than recurring subscriptions, revenue analytics may feel less useful, slower, or provide less insight than expected.
PostHog automatically connects revenue data to persons and groups when you use revenue events. For data warehouse sources, you need to map the connection manually.
Step 1: Add metadata when creating new customers
Search your codebase for where you create Stripe customers (e.g. stripe.Customer.create or equivalent) and add the posthog_person_distinct_id metadata field.
Step 2: Tag existing customers via charges, subscriptions, or invoices
For customers created before you added the metadata in step 1, you don't need to update the customer object directly. Instead, pass posthog_person_distinct_id as metadata on any charge, subscription, or invoice tied to that customer. PostHog automatically resolves it from the most recently created child object.
Add the metadata to whichever Stripe call you already make. Here are the most common patterns:
Subscriptions
One-off charges (payment intents)
Stripe Checkout
Pass the metadata in the checkout session's subscription_data or payment_intent_data depending on your checkout mode. Also set client_reference_id to your internal user ID so you can look up the distinct ID.
How does this work? PostHog looks for
posthog_person_distinct_idin the metadata of subscriptions, charges, and invoices tied to each Stripe customer. If the customer object doesn't have the metadata directly, PostHog uses the value from the most recently created child object.
Once this is connected you'll be able to properly see who your top customers are in the Top customers dashboard.
You'll also get access to the persons_revenue_analytics and groups_revenue_analytics tables in the data warehouse. This is a simple map of person_id/group_key to what their all-time revenue is.