Skip to main content

Cohort Analysis

A cohort groups units by a shared, dated inclusion rule. A retention table becomes meaningful only after the inclusion event, cohort calendar, return event, cell calculation, eligibility, and follow-up maturity are fixed. “Week 1” can mean a calendar week or a rolling seven-day interval; those are different metrics.

Prerequisites​

Complete funnel analysis. Keep the same validated, deduplicated, consented event population and restated close.

Learning goals​

  • Define inclusion and return criteria independently.
  • Distinguish UTC calendar buckets from rolling durations.
  • Keep immature cells and right-censored actors visible.
  • Explain why identity snapshots can move actors and denominators.

Cohort membership and return​

This example assigns an actor to the date of their first eligible signup_started. Day 0 is the half-open UTC interval from that actor's cohort midnight through the next midnight. A return is any later eligible page_view, account_created, or feature_used in the cell. The inclusion event itself is not a return.

Standard cells answer “returned in this period.” Rolling retention would require return in every period through the cell; cumulative retention would mean returned in any period by then. Label the calculation because the same table coordinates can otherwise carry incompatible meanings.

Metric contract​

  • Population: actors whose first valid, consented signup start occurs on 2026-10-01 UTC.
  • Unit: resolved actor × UTC signup-date cohort.
  • Observation window: inclusion and day-0 returns in [2026-10-01T00:00:00Z, 2026-10-02T00:00:00Z) at the 2026-10-04 restated close.
  • Denominator: all eligible actors assigned to the 2026-10-01 cohort, whether or not they return.
  • Missingness: cells without complete follow-up are censored, not zero; invalid, denied, and unavailable late rows remain reported exclusions.
  • Identity: fixed 2026-10-02 snapshot; a later approved merge may restate cohort size and must create a new version.

Worked example​

import json
from datetime import datetime
from pathlib import Path

root = Path("tests/fixtures/product-analytics")
rows = [json.loads(line) for line in (root / "events-v1.jsonl").read_text().splitlines()]
plan = json.loads((root / "tracking-plan-v1.json").read_text())
parse = lambda value: datetime.fromisoformat(value.replace("Z", "+00:00"))
deduped = {}
for row in sorted(rows, key=lambda item: parse(item["received_at"])):
deduped.setdefault(row["event_id"], row)
def valid(row):
required = plan["events"][row["event_name"]]["required_properties"]
kinds = {"string": str, "boolean": bool}
return all(key in row["properties"] and isinstance(row["properties"][key], kinds[kind]) for key, kind in required.items())
def actor(row):
return row["user_id"] or plan["identity_snapshot"]["links"].get(row["anonymous_id"], row["anonymous_id"])
eligible = [row for row in deduped.values() if row["analytics_consent"] and row["purpose"] == "product_measurement" and valid(row)]
starters = {actor(row) for row in eligible if row["event_name"] == "signup_started"}
return_names = {"page_view", "account_created", "feature_used"}
returned = {actor(row) for row in eligible if actor(row) in starters and row["event_name"] in return_names and parse(row["occurred_at"]) > min(parse(item["occurred_at"]) for item in eligible if actor(item) == actor(row) and item["event_name"] == "signup_started")}
print(f"cohort=2026-10-01 eligible_starters={len(starters)} day0_returned={len(returned)} retention={len(returned)/len(starters):.3f}")
print("calendar=UTC interval=[day0,day1) identity_snapshot=2026-10-02")

Expected output:

cohort=2026-10-01 eligible_starters=2 day0_returned=2 retention=1.000
calendar=UTC interval=[day0,day1) identity_snapshot=2026-10-02

Limitations and common mistakes​

  • Comparing a mature old cohort with an incomplete new cohort.
  • Hiding the timezone or mixing rolling and calendar periods.
  • Allowing multiple inclusion events to duplicate one actor across a supposedly first-touch cohort.
  • Interpreting a cohort difference as an intervention effect; acquisition mix, seasonality, and instrumentation can differ.
  • Reporting tiny cohorts without uncertainty or privacy thresholds.

Practice​

Design a weekly cohort table. State whether weeks begin Monday or Sunday, whether day-0 activity counts, how users acquired near the data close are censored, and whether the cells are standard, rolling, or cumulative.

Next steps​

Retention and churn turns return behavior into time-at-risk reasoning and handles incomplete follow-up.

Primary sources​

Checked 2026-10-19: Google Analytics cohort exploration definitions, NIST guidance on right-censored observations, and OpenTelemetry event timestamp conventions.