191 첫 방문 후 N일 이내의 LTV로 첫 방문 획득을 최적화하기
“첫 방문 후 30일 이내의 LTV” 사용자의 첫 번째 매체를 평가하는 SQL 문입니다.
WITH
master
AS
(
SELECT
user_pseudo_id
,
MAX
(user_first_touch_date)
AS
user_first_touch_date
,
MAX
(user_first_medium)
AS
user_first_medium
,
SUM
(revenue)
AS
revenue
FROM
(
SELECT
user_pseudo_id
,
CAST
(DATETIME_TRUNC(DATETIME(timestamp_micros(user_first_touch_timestamp),
'America/Los_Angeles'
),
day
)
AS
date
)
AS
user_first_touch_date
, PARSE_DATE(
""
%Y%m%d
""
,event_date)
AS
event_date
, traffic_source.medium
AS
user_first_medium
, ecommerce.purchase_revenue_in_usd
AS
revenue
FROM
`bigquery-
public
-data.ga4_obfuscated_sample_ecommerce.events_2020*`
WHERE
event_name
IN
(
'first_visit'
,
'purchase'
)
)
WHERE
DATE_DIFF(event_date, user_first_touch_date,
day
) <=30
AND
user_first_touch_date >=
'2020-11-01'
GROUP
BY
user_pseudo_id
)
SELECT
user_first_medium,
COUNT
(
DISTINCT
user_pseudo_id)
AS
users
,
SUM
(revenue)
AS
ltv_within_30days_from_first_visit
, ROUND(
SUM
(revenue)/
COUNT
(
DISTINCT
user_pseudo_id),2)
AS
avg_ltv_within_30days_from_first_visit
FROM
master
GROUP
BY
user_first_medium
ORDER
BY
2
DESC
답글 남기기