:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-modeling): derive lifecycle new from person creation date (#111614)
posthog[bot]87d4fbfb0801
diff --git a/products/data_modeling/skills/modeling-product-usage-metrics/references/dbt/fct_lifecycle.sql b/products/data_modeling/skills/modeling-product-usage-metrics/references/dbt/fct_lifecycle.sqlindex 8582ad7c4ab6..5ae889533f57 100644--- a/products/data_modeling/skills/modeling-product-usage-metrics/references/dbt/fct_lifecycle.sql+++ b/products/data_modeling/skills/modeling-product-usage-metrics/references/dbt/fct_lifecycle.sql@@ -1,4 +1,6 @@-- Lifecycle: per person-week status (new / returning / resurrecting). Dormant is derived downstream.+-- "New" is the first-ever active week, because stg_events has no profile creation date.+-- If your warehouse has a users table with created_at, join it and use that week instead, as query-lifecycle does.{{ config(materialized='table') }}with activity as (diff --git a/products/data_modeling/skills/modeling-product-usage-metrics/references/posthog/lifecycle.sql b/products/data_modeling/skills/modeling-product-usage-metrics/references/posthog/lifecycle.sqlindex 2fa27e7f5c2a..a0bfde04a94a 100644--- a/products/data_modeling/skills/modeling-product-usage-metrics/references/posthog/lifecycle.sql+++ b/products/data_modeling/skills/modeling-product-usage-metrics/references/posthog/lifecycle.sql@@ -1,31 +1,43 @@-- Lifecycle: classify each person's weekly activity as new / returning / resurrecting, and count dormant.--- Compares each active week to the person's previous active week and their first active week in the window.--- Note: first_week is the earliest week WITHIN this window, so a user active just before it can show as--- "new" at the window's left edge. Extend the window one interval earlier if that boundary matters.+-- Mirrors query-lifecycle: "new" means the person profile was created in that week, not the first event+-- in the window. Personless events are excluded, because lifecycle needs a person profile.+-- Reports 12 weeks, including the current week. The activity query reads one more week as a lookback,+-- so the first reported week can be classified as returning.+-- Checked against query-lifecycle for persons, weekly intervals and a Monday week start only.+-- Events of one person can carry different person.created_at values. Take the earliest per person, as the+-- native insight does, so that one person never counts in two buckets in the same week.WITH activity AS (- SELECT DISTINCT+ SELECTperson_id,- toStartOfWeek(timestamp) AS week+ toStartOfWeek(timestamp) AS week,+ min(person.created_at) AS created_atFROM eventsWHERE event = 'core_action'- AND timestamp >= now() - INTERVAL 12 WEEK+ AND properties.$process_person_profile != 'false'+ AND timestamp >= toStartOfWeek(now()) - INTERVAL 12 WEEK+ AND timestamp < toStartOfWeek(now()) + INTERVAL 1 WEEK+ GROUP BY person_id, week),enriched AS (SELECTperson_id,week,- min(week) OVER (PARTITION BY person_id) AS first_week,+ toStartOfWeek(min(created_at) OVER (PARTITION BY person_id+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)) AS created_week,lagInFrame(week) OVER (PARTITION BY person_id ORDER BY weekROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS prev_weekFROM activity)SELECTweek,- countIf(week = first_week) AS new,- countIf(week != first_week AND prev_week = week - INTERVAL 1 WEEK) AS returning,- countIf(week != first_week AND (prev_week IS NULL OR prev_week < week - INTERVAL 1 WEEK)) AS resurrecting+ countIf(week = created_week) AS new,+ countIf(week != created_week AND prev_week = week - INTERVAL 1 WEEK) AS returning,+ countIf(week != created_week AND (prev_week IS NULL OR prev_week < week - INTERVAL 1 WEEK)) AS resurrectingFROM enriched+WHERE week >= toStartOfWeek(now()) - INTERVAL 11 WEEKGROUP BY weekORDER BY week+-- A person whose profile was created in an earlier week than their first qualifying event shows as+-- resurrecting in that week, as in the native insight.-- Dormant (users active the prior week but not this week) is derived from the gaps; compute it as a-- negative series in the consuming view/insight, or with a symmetric self-anti-join if you need it inline.diff --git a/products/data_modeling/skills/modeling-product-usage-metrics/references/usage-metric-definitions.md b/products/data_modeling/skills/modeling-product-usage-metrics/references/usage-metric-definitions.mdindex a46ed815438a..5fe556d6924f 100644--- a/products/data_modeling/skills/modeling-product-usage-metrics/references/usage-metric-definitions.md+++ b/products/data_modeling/skills/modeling-product-usage-metrics/references/usage-metric-definitions.md@@ -24,15 +24,24 @@ intervals** they were active, then count units per bucket.## Lifecycle-Classify each unit's activity in each interval relative to the previous one and its first-ever activity:--| Bucket | Meaning |-| ---------------- | -------------------------------------------------------------------------------------- |-| **New** | Active this interval, first-ever activity is this interval. |-| **Returning** | Active this interval and the immediately previous interval. |-| **Resurrecting** | Active this interval, inactive the previous interval, but active at some point before. |-| **Dormant** | Not active this interval, but active the previous interval (plotted negative). |-+Classify each unit's activity in each interval relative to the previous interval and the interval in which the+unit started:++| Bucket | Meaning |+| ---------------- | ------------------------------------------------------------------------------ |+| **New** | Active this interval, and the unit started this interval. |+| **Returning** | Active this interval and the immediately previous interval (not new). |+| **Resurrecting** | Active this interval, inactive the previous interval, and not new. |+| **Dormant** | Not active this interval, but active the previous interval (plotted negative). |++- **When a unit started depends on the platform.**+ - PostHog (`query-lifecycle` and the HogQL recipe): the person profile `created_at`.+ - dbt or another warehouse: the first-ever chosen event over the full event history, or `created_at` from a+ users table if you have one.+- On PostHog, a person created in an earlier interval than their first chosen event counts as resurrecting in+ that interval, not new.+- Do not use "first event inside the analysis window" as new. It labels every existing user who is active at+ the window's start as new. Use the full history or a profile creation date.- Output: stacked bars per interval (dormant negative). New + returning + resurrecting = active users;dormant shows churn out.- Reading: dormant outpacing returning + resurrecting = leaky bucket (growth masks churn); resurrection