Sub topic 2
Engagement: what counts as an active user
This chapter assumes you can write SQL with SELECT, JOIN, and GROUP BY, that you know what an event log is, and that you can read percentages. The examples use PostgreSQL.
Defining an active user
An active user is someone who performed a core action within a stated window. Choose an action that reflects real value, such as project_created or message_sent. Avoid app_open, which background processes and accidental taps can trigger.
Write each metric definition in three parts: the population, the event, and the window. For example: "Users who signed up in March 2026 and performed core_action at least once in the 7 days after signup."
DAU, WAU, MAU and stickiness
DAU, WAU, and MAU count distinct active users per day, week, or month. Stickiness is DAU divided by MAU. A stickiness of 0.25 means that on an average day, a quarter of the monthly users came back.
-- DAU, MAU and stickiness for 2026-03-31
WITH dau AS (
SELECT COUNT(DISTINCT user_id) AS n
FROM events
WHERE event_name = 'core_action'
AND event_time >= DATE '2026-03-31'
AND event_time < DATE '2026-04-01'
),
mau AS (
SELECT COUNT(DISTINCT user_id) AS n
FROM events
WHERE event_name = 'core_action'
AND event_time >= DATE '2026-04-01' - INTERVAL '30 days'
AND event_time < DATE '2026-04-01'
)
SELECT dau.n AS dau, mau.n AS mau, dau.n * 1.0 / mau.n AS stickiness
FROM dau, mau;A common error is counting events instead of users. One user who creates 40 projects still counts once.
Retention fundamentals
Retention is the share of a group that is still active at a later point. Unlike engagement, retention follows the same users over time. A user who was active in week 0 and again in week 3 is retained at week 3.
Cohort analysis and retention tables
A cohort is a group of users who share a starting point, usually their signup week. A retention table places one cohort per row and one week since signup per column. Each cell holds the share of that cohort that was active in that week.
-- Weekly cohort retention (PostgreSQL)
WITH cohorts AS (
SELECT user_id, DATE_TRUNC('week', signup_at) AS cohort_week
FROM users
),
cohort_sizes AS (
SELECT cohort_week, COUNT(*) AS size
FROM cohorts
GROUP BY cohort_week
),
activity AS (
SELECT DISTINCT user_id, DATE_TRUNC('week', event_time) AS active_week
FROM events
WHERE event_name = 'core_action'
)
SELECT
c.cohort_week,
(a.active_week::date - c.cohort_week::date) / 7 AS week_number,
COUNT(DISTINCT a.user_id) * 1.0 / s.size AS retention
FROM cohorts c
JOIN activity a
ON a.user_id = c.user_id
AND a.active_week >= c.cohort_week
JOIN cohort_sizes s
ON s.cohort_week = c.cohort_week
GROUP BY c.cohort_week, week_number, s.size
ORDER BY c.cohort_week, week_number;Retention curves: N-day, unbounded, and bracket retention
Reading a retention curve requires knowing how the retained user is defined.
| Type | A user counts as retained when | Best for |
|---|---|---|
| N-day | Active on day N exactly | Precise day-level checks |
| Unbounded | Active on day N or any later day | Long-term loyalty |
| Bracket | Active at any point in a range, such as days 7 to 13 | Weekly or irregular products |
Exercise
A user signs up on Monday and returns the following Tuesday, day 8, and never again. Is this user counted as retained under day-7 N-day retention? Under bracket retention for week 1 (days 7 to 13)?
Show answer
No for N-day, because day 7 exactly is not met. Yes for bracket week 1, because day 8 falls within days 7 to 13.