# How to Join PostHog and Stripe Data by Customer

To join PostHog and Stripe data, you need one key that exists on both sides: the simplest is to store the Stripe customer id on the PostHog person (or your own app user id in Stripe customer metadata), then map company accounts with PostHog groups. Everything else is handling the edge cases that break that key.

The reason this is a project at all is that the two tools describe the same human in different languages. PostHog knows a person by one or more distinct_ids and whatever properties you attached. Stripe knows a customer by an id, an email and a metadata map. Neither knows the other exists. This guide walks the engineering steps you can follow with any tooling, covers PostHog's own revenue analytics as a fair in-product option, and then shows how to hold both in one connected model with Helix Foundry so you can ask which features paying customers actually use.

## Why usage and revenue don't line up out of the box

Usage and revenue don't line up because each system was built around a different identity. PostHog starts every visitor as an anonymous ID and only links events to a real person once you call identify with a distinct_id, typically at login or signup ([PostHog identify docs](https://posthog.com/docs/product-analytics/identify)). Stripe creates a customer object when someone pays, with a unique id, an email, and a metadata field you control ([Stripe Customer object](https://docs.stripe.com/api/customers/object)).

So you end up with two lists of people that overlap but share no column. A PostHog person might be identified by your database user id. A Stripe customer might have been created by a checkout form where the email was typed differently. The data is correct in each tool and unjoinable across them.

That gap hides the questions that matter: which features do paying customers use, which accounts on the Growth plan have gone quiet, which free users behave like the ones who later upgraded. Answering any of them needs one row per customer with both sides filled in.

## Pick a join key between PostHog persons and Stripe customers

Pick a join key that you control, not one that users control. Email looks tempting because both tools have it, but people change it, share it, and mistype it. You have two sturdy options.

**Option A: put the Stripe customer id on the PostHog person.** When a Stripe customer is created (a webhook on customer creation is the usual trigger), call identify or set a person property with `stripe_customer_id`. Now every PostHog person that has ever paid carries the exact Stripe key. The join is an equality match on that property.

**Option B: put your app user id in Stripe customer metadata.** Stripe lets you attach key-value pairs to objects, up to 50 pairs, for your own use ([Stripe metadata docs](https://docs.stripe.com/metadata)). Write `app_user_id` into the customer's metadata at creation. Since that same id is almost certainly what you pass to PostHog as the distinct_id, the two sides now agree without any extra property on the PostHog side.

Option B is usually less work if your signup flow already creates the Stripe customer server-side, because you have the user id in hand at that moment. Option A is better if customers can pay before they have an account in your app. Whichever you choose, backfill: loop through existing Stripe customers and write the id across, or the join only works for new customers.

Two details that bite later. Metadata is only returned when you use a secret key, so run the backfill server-side. And metadata does not copy to related objects automatically, so a key on the customer is not on the subscription or invoice unless you set it there too.

## Handle accounts, groups and the messy cases

Once individuals join, the next problem is that revenue is usually per company while usage is per person. PostHog groups are the fix: define a group type such as `company`, assign events to a group key, and keep the group's properties (plan, seat count, billing status) on the group itself. Then map one Stripe customer, or one Stripe customer per company, to one group key. If your billing is per workspace, the Stripe customer id or a workspace id in metadata becomes the group key.

Then walk through the cases that break naive joins:

- **Several emails for one person.** Someone signs up with a personal address and pays with a work one. If you key on email you get two people and one customer. Key on your own user id and the emails stop mattering.
- **One company, many users.** One Stripe customer maps to many PostHog persons. Join at the group level for revenue, and keep person-level usage underneath. Never sum revenue across persons or you will count one subscription once per seat.
- **One person, several companies.** Consultants and agency staff belong to multiple workspaces. A person-to-customer join is many-to-many here, so go through the group.
- **Test mode data.** Stripe test and live data are separate. A test customer that leaks into your join inflates paying-user counts. Filter by the mode of the key you used, and keep a sandbox key for experiments.
- **Renamed plans.** If you rename Pro to Team, historical subscriptions still carry the old price and product ids. Join on the price or product id, not the display name, and keep a small mapping table from id to current plan name.
- **Anonymous events before identify.** Events from before login sit under an anonymous ID. PostHog merges them once identify links the two, but check your identify calls fire on every login path or some users stay anonymous.

## Option inside PostHog: revenue analytics

If you want the answer without building a pipeline, PostHog has its own route. Its revenue analytics feature exposes revenue properties on persons and groups so you can use them in insights, SQL, managed views and profiles ([PostHog revenue analytics](https://posthog.com/docs/revenue-analytics)). It builds on PostHog's Stripe data warehouse source, where you connect Stripe with a restricted API key or OAuth and choose a sync mode per table ([PostHog Stripe source](https://posthog.com/docs/cdp/sources/stripe)). PostHog also recommends webhooks for real-time syncing of Stripe tables.

This is a good fit when your questions live entirely inside PostHog: break down a funnel by revenue, filter a cohort to paying customers, look at a person's profile with their spend next to their events. You still need a join key, because PostHog has to know which person each Stripe customer is, so the steps above still apply.

Where it stops being enough is when the question needs more than those two tools. Revenue and usage are one slice of a customer. Once you also want CRM notes, call transcripts, or a database table in the same question, you need a model that holds all of them, not a feature inside one analytics product.

## Joining them in one ontology with Helix Foundry

Helix Foundry is an open-source (Apache 2.0) app that connects a company's databases, tools and documents, has an ontology agent draft one ontology over them, and loads it into HelixDB as a connected graph you can explore and query, with every value traced to the row or quote it came from. HelixDB is the graph-vector database underneath; Foundry is the app you work in.

Both tools are on Foundry's connector list. For PostHog you create a personal API key with Query and Project read scopes, pick your region (US Cloud, EU Cloud or self-hosted) and an event history of 1 to 365 days, 30 by default. Foundry syncs persons, person_distinct_ids and groups in full, and events and daily event counts for the history you chose. PostHog syncs at most once a day, because PostHog limits repeated exports through its query API. For Stripe you create a restricted key named Helix Foundry with Read on the objects you want, and it syncs customers, subscriptions, invoices, charges, products, prices and more. Use a test key first, and give Read on Events so Pro and Max syncs read only changed objects ([Foundry connectors](https://docs.helix-db.com/foundry/data/connectors)).

The steps:

1. Run it locally with `git clone https://github.com/helixdb/helix-foundry.git`, `cd helix-foundry`, `docker compose up -d --wait`, then open http://localhost:3000. Or use Helix Cloud at foundry.helix-db.com and pick Set up with your agent. The self-hosted install is single-user on localhost with no sign-in, so keep it on your own machine ([Foundry repo](https://github.com/HelixDB/helix-foundry)).
2. Add the PostHog and Stripe connections and let the first syncs finish.
3. Generate an ontology and tell the agent your goal, for example: link each PostHog person to a Stripe customer through the Stripe customer id property or the app user id in metadata, and roll people up to companies through groups ([generate and version an ontology](https://docs.helix-db.com/foundry/ontologies/generate-and-version)).
4. Review the draft. Values the sources disagree on, such as an email that differs between the two tools, wait in a review queue for a person to settle instead of being silently merged ([review](https://docs.helix-db.com/foundry/ontologies/review)).
5. Make the version current and load it into the graph.

The result is one connected graph where a person, their events, their group and their Stripe subscription sit on linked records, and each fact points back to its source row. Foundry is a reader here: it does not write back to PostHog or Stripe, so setting the join key on each side is still your job, as described above. The same approach extends past these two tools. Foundry also lists Attio and Granola as SaaS connectors, so you can add CRM and call notes to the same model, as in [this customer ontology walkthrough](https://www.helix-db.com/content/foundry/build-a-customer-ontology-from-attio-granola-and-stripe).

## Questions you can answer once they're joined

With persons, groups and Stripe customers on one graph, the questions that were a pile of exports become one ask. Analyst, Foundry's question interface, answers in plain language with charts and the queries it ran ([ask questions](https://docs.helix-db.com/foundry/ask/ask-questions)). Examples worth asking first:

- Which features do customers on a paid subscription use most, compared with free users?
- Which companies on a paid plan had a drop in activity over the last 30 days?
- Which customers have an active subscription but no identified PostHog person, meaning your join key is missing for them?
- Which paid accounts have one user doing all the work, a single point of failure at renewal?
- Which accounts have an open or failed invoice and low recent usage, the ones most likely to churn?

That third question is a useful audit before any other. It tells you how complete the join is, which is what decides whether you can trust the rest.

Pin the answers that you keep checking to a dashboard ([dashboards](https://docs.helix-db.com/foundry/automate/dashboards)), and if you want an AI agent to ask the same questions, it can query the ontology through the Helix MCP ([query from agents](https://docs.helix-db.com/foundry/agents/query-from-agents)). Keep one expectation in view: PostHog data refreshes at most once a day, so these are daily, not live, answers.

## Try it on your own data

Start with the key, because nothing else works without it. Pick Option A or Option B, backfill your existing Stripe customers, and run the missing-key audit so you know your coverage. Then decide how far you need to go. If revenue-by-usage inside PostHog answers your questions, turn on revenue analytics and stop there. If you want PostHog, Stripe and the rest of your customer data in one model you can question and hand to an agent, that is the case for a Foundry ontology.

Spin up Foundry with the Docker commands above, or open foundry.helix-db.com, connect PostHog and a Stripe test key, and ask it the missing-key question first.

## Fix the join key first, then connect everything else

The join is an identity problem, not a tooling problem: once the Stripe customer id sits on the PostHog person, or your app user id sits in Stripe metadata, every tool can match the two. Fix that key, map accounts through groups, and handle the test mode and renamed plan cases. Then clone helix-foundry, connect PostHog and Stripe, and ask which paying accounts are using less before they churn.
