๐ฒ Casino Analytics Dashboard - Part 6
SQL Cohort retention
I wrote the SQL cohort analysis to find whoโs about to leave.
Main Goals of the day:
- Write SQL to calculate intra-week retention (Day 0 to Day 6)
- Focus on first deposit date as cohort anchor
- Donโt do โmonthlyโ โ do weekly, because my data is 7 days
Step by Step
๐ Step 1: Found first deposit date per player โ MIN(session_start) where deposit > 0
๐ Step 2: Joined back to sessions โ now I know: โPlayer P0123 deposited on Sep 2โ
๐ Step 3: Calculated day_diff = session_date - cohort_date
๐ Step 4: Filtered to day_diff BETWEEN 0 AND 6 โ only sessions within 7 days of first deposit
๐ Step 5: Grouped by cohort_date + day_diff โ counted active players per day
Challenges / Insights
Cohort analysis is used for monthly retention. I tried to adapt it according to the simulated dataset in the window you have.**
With this method, you could see the effects on a 7-day cohort of the marketing campaigns.
And guess what?
Itโs more useful.
Because in iGaming:
- If a player doesnโt return by Day 4 โ theyโre gone.
- If they return by Day 2 โ theyโre hooked.
This isnโt academic, but survival.
SQL Snippet Final
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
WITH first_deposit AS (
SELECT player_id, MIN(session_start) AS cohort_date
FROM player_sessions
WHERE deposit_amount > 0
GROUP BY player_id
)
SELECT
DATE(fd.cohort_date) AS cohort_date,
DATEDIFF(ps.session_start, fd.cohort_date) AS day_diff,
COUNT(DISTINCT ps.player_id) AS active_users
FROM player_sessions ps
JOIN first_deposit fd ON ps.player_id = fd.player_id
WHERE ps.session_start BETWEEN fd.cohort_date AND fd.cohort_date + INTERVAL '6 days'
GROUP BY 1,2
ORDER BY 1,2;
</pre>
Next Step
๐ Generate the heatmap in Python โ show it visually.