posthog/ai-plugin

modeling-revenue-metrics

Build reusable revenue models — MRR, ARR, gross revenue, new/expansion/contraction/churn, ARPU, LTV, and per-customer/per-account revenue — on either PostHog data-warehouse views (HogQL) or an external dbt project.

ソースを見る
リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

Modeling revenue metrics

Turn payment/subscription data into durable revenue models. Read modeling-warehouse-foundations first for the view-vs-dbt decision, the view-* workflow, and convertCurrency(); this skill is the revenue-specific layer on top. Metric definitions live in `references/revenue-metric-definitions.md`; copy-paste recipes in `references/posthog/` and `references/dbt/`.

Step 1 — find where revenue lives

Revenue reaches PostHog two ways; both feed the same *managed `revenue_analytics_` views**:

  • A payment platform as a warehouse source — Stripe today (Chargebee/Polar/RevenueCat coming). Best when

the business runs on a billing platform. Connect via setting-up-a-data-warehouse-source.

  • Custom revenue events — you send events (e.g. purchase_completed) with a revenue property. Best when

there's no supported platform or you already track revenue in-product.

If neither exists yet, use suggesting-data-imports to recommend a source. In dbt, the equivalent is staging whichever billing tables landed in the warehouse.

Step 2 — model on the managed views, not raw tables

PostHog auto-generates a curated set of views per source. Do not re-derive revenue from raw Stripe tables — the managed views already handle deferred-revenue recognition, currency, and a stable schema.

Discover the exact names (they're prefixed by source, e.g. stripe.<prefix>.…, plus a cross-source revenue_analytics.all.…):

sql
SELECT table_name FROM system.information_schema.tables WHERE table_name ILIKE '%revenue_analytics%'
Managed viewGrainUse for
revenue_item (start here)1 / invoice line itemGross revenue, monthly recurring revenue, revenue by product/customer/period. Implements deferred revenue + currency.
mrr1 / (customer, subscription)Live snapshot of current MRR — not a time series.
customer1 / customerdim_customer: email, country, cohort, metadata.
subscription1 / subscriptionSubscription state for churn/expansion logic.
charge1 / chargeRaw charges; prefer revenue_item unless you specifically need charges.
product1 / productProduct dimension.

Key revenue_item columns: amount (already converted to the project base currency), currency (that base currency), original_amount / original_currency (as charged), is_recurring, customer_id, subscription_id, product_id, group_0_keygroup_4_key (B2B account keys), timestamp.

Rules before you model (revenue gotchas)

  1. MRR is empty without a subscription config. For event-based revenue, MRR only populates when a

subscription property is configured. Empty MRR + populated gross revenue is expected behaviour, not a bug — say so instead of "fixing" it.

  1. The `mrr` managed view is a current snapshot, not history ("MRR at the current time"). For MRR _over

time, sum recurring `amount` per month from `revenueitem (see the recipe), or materialize a monthly snapshot of the mrr` view on a schedule.

  1. `amount` is already in base currency. Use it directly for reporting. Only call

convertCurrency(original_currency, 'XXX', original_amount, timestamp) when you need a different target currency, or when working from raw events.

  1. Link revenue to people via metadata. Person/group-level revenue needs

posthog_person_distinct_id metadata on the Stripe customer (or the person join). Without it, revenue is customer-level only.

  1. Don't build on the Revenue dashboard — it's being retired (~2026-06-30). Model against the

revenue_analytics_* views and the person/group revenue properties.

  1. Exclude test accounts. Confirm filter_test_accounts behaviour so QA/internal charges don't inflate

revenue.

Step 3 — build the model

PostHog: write the HogQL (alias every column), view-create, verify with view-get, then view-materialize the expensive monthly rollups (a daily sync_frequency is usually right for revenue). Recipes: `references/posthog/`mrr_and_arr.sql, gross_revenue_by_month.sql, revenue_by_customer.sql.

dbt: stage the billing source → fct_revenue_item, fct_mrr, dim_customer marts with tests. Recipes: `references/dbt/`. Note dbt has no convertCurrency() — supply a rate seed.

Then register the model (references/governance.md in foundations): annotate columns and, if MRR/ARR is a headline number, propose it to the semantic layer.

File map

FileRead when
`references/revenue-metric-definitions.md`Precise definitions: MRR, ARR, gross, new/expansion/contraction/churn, ARPU, LTV.
`references/posthog/`HogQL view recipes on the managed views.
`references/dbt/`dbt staging + fct_*/dim_* marts + schema.yml tests.

Companions

modeling-warehouse-foundations (mechanics), setting-up-a-data-warehouse-source + suggesting-data-imports (get Stripe/revenue data in), modeling-dimension-tables (currency/plan dimensions), querying-posthog-data (HogQL + the semantic-layer metric check).

同じリポジトリから

関連する Skills

すべての Skills
posthog
公式

assessing-heatmaps

Assesses what a page's heatmap is telling you and recommends concrete changes. Pulls click / rageclick / scroll-depth data for a URL, names the hot elements by cross-referencing autocapture events on the same page, and can create a saved heatmap the user opens in PostHog, then summarizes the behavior and proposes improvements.\nTRIGGER when: user asks what a heatmap shows, why people aren't clicking something, where users rage-click, how far they scroll, what to change on a page based on heatmap/click data, or to 'analyze/assess/review the heatmap' for a URL.\nDO NOT TRIGGER when: the user only wants to create a saved heatmap screenshot with no analysis (use heatmaps-saved-create directly), or is asking about session replay in general (use investigating-replay).

導入数
1
GitHub Stars
80
更新日
9月4日
posthog
公式

auditing-endpoints

Audit every endpoint in a PostHog project for staleness, failed materialisations, and unused materialised versions. Use when the user asks "what endpoints can I clean up?", "are any of my endpoints broken?", "which materialised versions are still being called?", or wants a one-shot cleanup pass over the Endpoints product. Produces a prioritised report grouped by issue type, with recommended actions but does not modify anything without explicit confirmation.

導入数
1
GitHub Stars
80
更新日
9月4日
posthog
公式

auditing-experiments-flags

Audit PostHog experiments and feature flags for configuration issues, staleness, and best-practice violations. Read when the user asks to audit, health-check, or review experiments or feature flags, check flag hygiene, or verify experiment setup.

導入数
1
GitHub Stars
80
更新日
9月4日
posthog
公式

authoring-data-quality-checks

Adds and runs data quality checks (dbt-test style assertions) on a project's warehouse tables and saved-query views: not-null, uniqueness, accepted values, referential integrity, row-count bounds, freshness, and custom HogQL. Use when asked to test a model, validate a view, check for nulls or duplicates, add data quality checks, find out why a number looks wrong, or judge whether a warehouse table is trustworthy before using it in an analysis. To describe what data means (metrics, certifications, joins), see setting-up-data-catalog instead. Trigger terms: data quality, data test, dbt test, not null check, uniqueness check, freshness check, referential integrity, row count check, validate model, is this table trustworthy.

導入数
1
GitHub Stars
80
更新日
9月4日