Measuring user engagement with cohort analysis

Mesut Can ALKAN12 Oct 2022

Problem

A product team needs to know how engagement changes over time, how it reacts to external events and seasonality, and how different user groups behave. The only raw material is an activity table: one row per user and day with a count of app opens. Without per-user weekly statuses the team cannot track groups of users over time or see in which week of a user's life activity drops.

Example from the article: a synthetic activity table with 13,720 users over 42 weeks, used to show how weekly cohorts reveal an engagement drop after the first week.

Solution in brief

Turn the activity log into a user-by-week table, one row per user and week, and flag each row as new, retained, regained or churned with SQL window functions. Group users by the week they joined, then plot the share of each cohort that is still active in its 1st, 2nd, ... Nth week as a heatmap. A second cohort type groups users who left for good by the week they left.

Questions this case answers
  • How to measure how activity of groups of users who joined in the same period decays over time when only a raw per-user activity log is available
  • How to assign each user in each period a lifecycle status (new, retained, regained, churned) from activity counts alone
  • How to measure how user engagement and retention evolve week by week from a raw activity table?
  • How to label every user in every week as new, retained, regained or churned?

Tools and methods

  • Weekly status flags in SQL — new, retained, regained, churned and active flags per user and week.
  • Time cohorts — users grouped by join week, followed week by week in a heatmap.
  • Behaviour cohorts — users who churned for good, grouped by the week they left.
  • pandas, seaborn — pivot tables and heatmaps.
  • SQLite — runs the query in the example.
Continue reading — it's free

Google or a one-time email code. No password.