User Re-Activation Month

10pts
Spotify

Problem Statement

Spotify tracks user engagement to measure the effectiveness of "win-back" campaigns. A key metric is identifying re-activated users.

A user is considered re-activated if they have a Premium event after a period of total inactivity lasting 6 months or longer. Inactivity is defined as the gap between any two consecutive events for a specific user.

Rules:

  • The inactivity gap must be strictly >= 180 days (6 months).
  • The event that ends the gap must be of event_type Premium.
  • Output columns: user_id, reactivation_date, days_since_last_event.
  • reactivation_date is the date of the Premium event.
  • If a user has multiple re-activations, show all of them.
  • Result must be sorted by reactivation_date ascending, then user_id ascending.
Tests your understanding of
Window Functions, Date Math and User Retention

Input Tables

user_events
event_id(INTEGER)user_id(INTEGER)event_type(VARCHAR)event_timestamp(TIMESTAMP)
110Free2023-01-01 10:00:00
210Premium2023-08-15 12:00:00
311Free2023-01-01 10:00:00
411Free2023-03-01 10:00:00
511Premium2023-04-01 10:00:00
612Free2023-01-01 10:00:00
712Premium2024-02-01 10:00:00

Expected Output

user_id(INTEGER)reactivation_date(DATE)days_since_last_event(INTEGER)
102023-08-15226
122024-02-01396

Tags

HardWindow FunctionsDate MathUser Retention
35-45 min
27%

Hints