🎯 Mục tiêu bài học
- Hiểu khái niệm Cohort và tại sao phân tích theo cohort quan trọng hơn aggregate metrics
- Xây dựng Cohort Retention Table hoàn chỉnh bằng SQL
- Vẽ và đọc Retention Curves — phát hiện trends và anomalies
- Tính toán Churn Rate và hiểu mối quan hệ với Retention
- So sánh retention theo segments để tìm insight actionable
| Thông tin | Chi tiết |
|---|---|
| ⏱️ Thời lượng | 55 phút |
| 📖 Chủ đề chính | Cohort Analysis, Retention, Churn |
| 💡 Kiến thức cần có | Bài 01-05, SQL Window Functions |
| 🎯 Output | Cohort retention table cho ShopVN |
📖 Thuật ngữ quan trọng
| Thuật ngữ | Tiếng Việt | Mô tả |
|---|---|---|
| Cohort | Nhóm đồng đại | Nhóm khách hàng chia theo thời điểm đầu tiên (first purchase month) |
| Retention Rate | Tỷ lệ giữ chân | % khách hàng quay lại mua ở tháng N sau tháng đầu |
| Churn Rate | Tỷ lệ rời bỏ | % khách hàng không quay lại = 1 - Retention |
| Cohort Size | Kích thước cohort | Số khách hàng trong mỗi cohort |
| Month 0 | Tháng gốc | Tháng khách hàng mua lần đầu tiên |
| Month N | Tháng thứ N | N tháng sau tháng gốc |
| Retention Curve | Đường cong giữ chân | Biểu đồ retention rate theo thời gian |
| Stickiness | Độ dính | Mức độ quay lại thường xuyên (DAU/MAU) |
| Resurrection | Hồi sinh | Khách hàng quay lại sau thời gian dài không mua |
| Average Lifespan | Vòng đời trung bình | Thời gian trung bình khách hàng active |
Checkpoint
Cohort = nhóm khách hàng theo tháng mua đầu tiên. Retention Rate đo % khách quay lại ở tháng N. Churn Rate = 1 - Retention Rate. Retention Curve giảm dần theo thời gian — tốc độ giảm phản ánh chất lượng sản phẩm/dịch vụ.
📊 Tại sao phân tích Cohort?
Vấn đề của Aggregate Metrics
Khi nhìn tổng số đơn hàng tăng 20% MoM, bạn nghĩ business đang tốt. Nhưng thực tế có thể là:
- ✅ Khách cũ mua lại nhiều hơn → Tốt (retention cao)
- ❌ Chỉ có khách mới, khách cũ đã rời đi → Xấu (churn cao)
Cohort Analysis giúp tách biệt hành vi khách cũ vs khách mới, cho thấy bức tranh thực.
So sánh 2 scenario
| Scenario | Tháng 1 | Tháng 2 | Tháng 3 | Aggregate Growth |
|---|---|---|---|---|
| A (Tốt) | 1000 new + 0 return | 800 new + 300 return | 600 new + 500 return | +10% MoM |
| B (Xấu) | 1000 new + 0 return | 1100 new + 50 return | 1200 new + 30 return | +15% MoM |
Scenario B có growth rate cao hơn (15% vs 10%) nhưng retention cực thấp (5% vs 30%). Khi chi phí thu hút khách mới (CAC) tăng, Scenario B sẽ sụp đổ. Cohort Analysis phát hiện vấn đề này.
💻 Xây dựng Cohort Table bằng SQL
Step 1: Xác định Cohort Month cho mỗi khách
1-- Step 1: First purchase month = cohort month2WITH customer_cohort AS (3 SELECT4 customer_id,5 MIN(order_date) AS first_order_date,6 FORMAT(MIN(order_date), 'yyyy-MM') AS cohort_month7 FROM fact_orders8 WHERE status = 'Delivered'9 GROUP BY customer_id10),1112-- Step 2: Gắn cohort month vào mỗi order13orders_with_cohort AS (14 SELECT15 o.customer_id,16 o.order_date,17 c.cohort_month,18 c.first_order_date,19 DATEDIFF(MONTH, c.first_order_date, o.order_date) AS month_number20 FROM fact_orders o21 JOIN customer_cohort c ON o.customer_id = c.customer_id22 WHERE o.status = 'Delivered'23),2425-- Step 3: Đếm unique customers ở mỗi month_number26cohort_data AS (27 SELECT28 cohort_month,29 month_number,30 COUNT(DISTINCT customer_id) AS customers31 FROM orders_with_cohort32 GROUP BY cohort_month, month_number33),3435-- Step 4: Lấy cohort size (month_number = 0)36cohort_sizes AS (37 SELECT38 cohort_month,39 customers AS cohort_size40 FROM cohort_data41 WHERE month_number = 042)4344-- Step 5: Retention Rate Table45SELECT46 d.cohort_month,47 s.cohort_size,48 d.month_number,49 d.customers AS retained_customers,50 ROUND(d.customers * 100.0 / s.cohort_size, 1) AS retention_rate_pct51FROM cohort_data d52JOIN cohort_sizes s ON d.cohort_month = s.cohort_month53WHERE d.month_number <= 1254ORDER BY d.cohort_month, d.month_number;Đọc Cohort Table
| Cohort | Size | M0 | M1 | M2 | M3 | M6 | M12 |
|---|---|---|---|---|---|---|---|
| 2024-01 | 5,000 | 100% | 25% | 18% | 15% | 10% | 7% |
| 2024-02 | 4,800 | 100% | 27% | 20% | 16% | 11% | — |
| 2024-03 | 5,200 | 100% | 24% | 17% | 14% | 9% | — |
| 2024-04 | 5,500 | 100% | 28% | 21% | 17% | — | — |
Đọc theo hàng: Cohort 2024-01 (5,000 khách mới tháng 1), đến tháng 3 (M3) còn 15% quay lại mua = 750 khách. Đọc theo cột: So sánh M1 giữa các cohort — nếu M1 tăng dần từ 25% lên 28% → platform đang improve retention.
Checkpoint
Cohort Table có hàng = cohort month (tháng mua đầu tiên), cột = month_number (0, 1, 2...). Month 0 luôn 100%. Retention rate giảm dần theo tháng. So sánh cùng cột giữa các cohort cho thấy improvement hoặc degradation.
📈 Retention Curves & Patterns
Đặc điểm Retention Curve E-commerce
Retention Curve Pattern
Benchmark Retention Rate E-commerce
| Tháng | Poor | Average | Good | Excellent |
|---|---|---|---|---|
| M1 | dưới 15% | 20-25% | 25-35% | trên 35% |
| M3 | dưới 8% | 10-15% | 15-20% | trên 22% |
| M6 | dưới 5% | 7-10% | 10-15% | trên 15% |
| M12 | dưới 3% | 5-7% | 7-12% | trên 12% |
E-commerce có retention thấp hơn SaaS hoặc subscription business vì khách hàng mua theo nhu cầu (not recurring). Retention M12 khoảng 5-10% là bình thường. Focus vào việc tăng M1 retention sẽ có impact lớn nhất.
Retention theo Customer Segment
1-- Retention Rate theo customer segment2WITH customer_cohort AS (3 SELECT4 o.customer_id,5 c.customer_segment,6 MIN(o.order_date) AS first_order_date,7 DATEDIFF(MONTH, MIN(o.order_date), o.order_date) AS month_number8 FROM fact_orders o9 JOIN dim_customer c ON o.customer_id = c.customer_id10 WHERE o.status = 'Delivered'11 GROUP BY o.customer_id, c.customer_segment,12 DATEDIFF(MONTH, MIN(o.order_date), o.order_date)13)14SELECT15 customer_segment,16 COUNT(DISTINCT CASE WHEN month_number = 017 THEN customer_id END) AS m0_customers,18 COUNT(DISTINCT CASE WHEN month_number = 119 THEN customer_id END) AS m1_customers,20 COUNT(DISTINCT CASE WHEN month_number = 321 THEN customer_id END) AS m3_customers,22 ROUND(23 COUNT(DISTINCT CASE WHEN month_number = 1 THEN customer_id END) * 100.024 / NULLIF(COUNT(DISTINCT CASE WHEN month_number = 0 THEN customer_id END), 0)25 , 1) AS m1_retention_pct26FROM customer_cohort27GROUP BY customer_segment28ORDER BY m1_retention_pct DESC;📉 Churn Analysis
Churn Rate = 1 - Retention Rate
1-- Monthly Churn Rate2WITH monthly_active AS (3 SELECT4 FORMAT(order_date, 'yyyy-MM') AS month,5 COUNT(DISTINCT customer_id) AS active_customers6 FROM fact_orders7 WHERE status = 'Delivered'8 GROUP BY FORMAT(order_date, 'yyyy-MM')9),10monthly_new AS (11 SELECT12 FORMAT(MIN(order_date), 'yyyy-MM') AS first_month,13 COUNT(DISTINCT customer_id) AS new_customers14 FROM fact_orders15 WHERE status = 'Delivered'16 GROUP BY customer_id17)18SELECT19 a.month,20 a.active_customers,21 COALESCE(n.new_customers, 0) AS new_this_month,22 a.active_customers - COALESCE(n.new_customers, 0) AS returning_customers,23 ROUND(24 (a.active_customers - COALESCE(n.new_customers, 0)) * 100.025 / LAG(a.active_customers) OVER (ORDER BY a.month), 126 ) AS returning_rate_pct27FROM monthly_active a28LEFT JOIN (29 SELECT first_month, SUM(new_customers) AS new_customers30 FROM monthly_new31 GROUP BY first_month32) n ON a.month = n.first_month33ORDER BY a.month;Nguyên nhân Churn phổ biến
| Nguyên nhân | Tỷ lệ | Giải pháp |
|---|---|---|
| Trải nghiệm giao hàng kém | 30% | Cải thiện fulfillment, theo dõi delivery |
| Sản phẩm không đúng mô tả | 25% | Kiểm soát chất lượng listing |
| Giá không cạnh tranh | 20% | Dynamic pricing, price matching |
| Thiếu chương trình loyalty | 15% | Reward points, membership tiers |
| Trải nghiệm app/web kém | 10% | UX improvement, page speed |
Giảm churn 5% có thể tăng lợi nhuận 25-95% (Harvard Business Review). Lý do: khách cũ đã quen sản phẩm, không cần chi phí acquisition, và order thường lớn hơn khách mới.
📋 Tổng kết
Kiến thức đã học
| Chủ đề | Nội dung chính |
|---|---|
| Cohort Analysis | Nhóm khách theo first purchase month, theo dõi qua thời gian |
| Retention Table | Hàng = cohort, cột = month_number, giá trị = retention % |
| SQL Implementation | MIN(order_date) → DATEDIFF → COUNT DISTINCT → % |
| Retention Curves | Drop mạnh M0→M1 (70-80%), flatten out sau M6 |
| Churn Analysis | Churn = 1 - Retention, top reasons và solutions |
| Benchmark | M1: 20-25%, M6: 7-10%, M12: 5-7% cho E-commerce |
Key Takeaways
- ✅ Cohort Analysis phát hiện vấn đề mà aggregate metrics che giấu
- ✅ M1 Retention là metric quan trọng nhất — cải thiện M1 impact toàn bộ curve
- ✅ Churn rate giảm 5% có thể tăng profit 25-95%
- ✅ So sánh retention giữa các cohort cho thấy improvement efforts có hiệu quả không
Bài tiếp theo: Product Analytics →
🎉 Bạn đã thành thạo Cohort & Retention Analysis! Module tiếp theo sẽ chuyển sang phân tích sản phẩm và vận hành.
