-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_acquisition.sql
More file actions
26 lines (25 loc) · 928 Bytes
/
user_acquisition.sql
File metadata and controls
26 lines (25 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
SELECT
CAST(DATE_TRUNC('month', signup_ts) AS DATE) AS cohort_month,
acquisition_channel,
country,
COUNT(DISTINCT user_id) AS signups,
COUNT(DISTINCT CASE
WHEN latest_stage IN ('activated_account', 'first_purchase', 'repeat_purchase')
THEN user_id
END) AS activated_users,
COUNT(DISTINCT CASE WHEN is_observed_customer THEN user_id END) AS purchasing_users,
ROUND(
CAST(COUNT(DISTINCT CASE
WHEN latest_stage IN ('activated_account', 'first_purchase', 'repeat_purchase')
THEN user_id
END) AS DOUBLE) / NULLIF(COUNT(DISTINCT user_id), 0),
4
) AS activation_rate,
ROUND(
CAST(COUNT(DISTINCT CASE WHEN is_observed_customer THEN user_id END) AS DOUBLE)
/ NULLIF(COUNT(DISTINCT user_id), 0),
4
) AS purchase_conversion_rate
FROM modeled_users
WHERE signup_ts IS NOT NULL
GROUP BY 1, 2, 3;