186 랜딩 페이지와 두 번째 페이지의 전환율 확인하기
유니버설 애널리틱스와 동일한 “랜딩 페이지”와 “두 번째 페이지”를 구하는 SQL 문입니다.
WITH
cv_sessions
AS
(
SELECT
DISTINCT
ga_session_id, 1
AS
cv
FROM
(
SELECT
(
SELECT
value.int_value
FROM
UNNEST(event_params)
WHERE
key
=
'ga_session_id'
)
AS
ga_session_id
FROM
`bigquery-
public
-data.ga4_obfuscated_sample_ecommerce.events_202101*`
WHERE
event_name =
'purchase'
))
, pages
AS
(
SELECT
ga_session_id,
MAX
(landing_page)
AS
landing_page
,
MAX
(IF(second_page = landing_page, third_page, second_page))
AS
second_page
FROM
(
SELECT
ga_session_id
, FIRST_VALUE(page_title) OVER (PARTITION
BY
ga_session_id
ORDER
BY
event_timestamp)
AS
landing_page
, NTH_VALUE(page_title,2) OVER (PARTITION
BY
ga_session_id
ORDER
BY
event_timestamp)
AS
second_page
, NTH_VALUE(page_title,3) OVER (PARTITION
BY
ga_session_id
ORDER
BY
event_timestamp)
AS
third_page
FROM
(
SELECT
event_timestamp
, (
SELECT
value.int_value
FROM
UNNEST(event_params)
WHERE
key
=
'ga_session_id'
)
AS
ga_session_id
, (
SELECT
value.string_value
FROM
UNNEST(event_params)
WHERE
key
=
'page_title'
)
AS
page_title
FROM
`bigquery-
public
-data.ga4_obfuscated_sample_ecommerce.events_202101*`
WHERE
event_name =
'page_view'
))
GROUP
BY
ga_session_id)
SELECT
landing_page, second_page,
COUNT
(
DISTINCT
ga_session_id)
AS
sessions,
SUM
(cv)
AS
cvs
, ROUND(
SUM
(cv) /
COUNT
(
DISTINCT
ga_session_id) * 100 , 2)
AS
cvr_percent
FROM
(
SELECT
p.ga_session_id , p.landing_page , p.second_page ,
COALESCE
(cvs.cv,0)
AS
cv
FROM
pages
AS
p
LEFT
JOIN
cv_sessions
AS
cvs
ON
p.ga_session_id = cvs.ga_session_id
)
--WHERE second_page is not null
GROUP
BY
landing_page, second_page
ORDER
BY
3
DESC
답글 남기기