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.
The connection between your revenue data and persons and groups is automatically done when you're using revenue events (since we know what person/group an event belongs to) but we need your help to map them in case you're using a data warehouse source.
The easy way
Let the wizard handle the metadata configuration for you by running this command in your project directory with your terminal:
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: Update existing customers before charges
For customers created before you added the metadata, add a Customer.modify call before your charge or checkout code. This ensures existing customers get tagged the next time they make a payment.
Search your codebase for any of these patterns:
PaymentIntent.create— one-off chargesSubscription.create— new subscriptionscheckout.Session.create— Stripe CheckoutInvoice.create— manual invoices
Then add the following before that code:
Using Stripe Checkout? If you use
checkout.Session.createand let Stripe create customers automatically, you won't have aCustomer.createcall in your code. Instead, handle this in yourcheckout.session.completedwebhook:
Tip: Set
client_reference_idto your internal user ID when creating Checkout Sessions. This lets you look up the user in your database when the webhook fires.
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.