Необходимо подсчитать количество сессий за весь диапазон дат выгруженной статистики. В качестве примера есть вот эта статья https://www.ga4bigquery.com/sessions-dimensions-metrics-ga4/. Основной запрос брала отсюда. Согласно комментариям, сменила count, однако система начала ругаться (Unrecognized name: event_name at [10:30]). Может, кто-то сталкивался? Как можно решить проблему? Спасибо
Полный запрос выглядит так:
-- subquery to define static and/or dynamic start and end date for the whole query
with date_range as (
select
'20220601' as start_date,
format_date('%Y%m%d',date_sub(current_date(), interval 1 day)) as end_date),
-- subquery to prepare and calculate engagement data
engagement as (
select
count(distinct case when event_name = 'session_start' then concat(user_pseudo_id, cast(event_timestamp as string)) end) as sessions,
sum(engagement_time_msec)/1000 as engagement_time_seconds,
count(distinct case when session_engaged = '0' then concat(user_pseudo_id,session_id) end) as bounces
from (
select
user_pseudo_id,
(select value.int_value from unnest(event_params) where key = 'ga_session_id') as session_id,
max((select value.string_value from unnest(event_params) where key = 'session_engaged')) as session_engaged,
max((select value.int_value from unnest(event_params) where key = 'engagement_time_msec')) as engagement_time_msec
from
-- change this to your google analytics 4 export location in bigquery
`celtic-current-353007.analytics_309529570.events_*`,
date_range
where
_table_suffix between date_range.start_date and date_range.end_date
group by
user_pseudo_id,
session_id))
-- main query
select
-- sessions (metric | the total number of sessions)
count(distinct case when event_name = 'session_start' then concat(user_pseudo_id, cast(event_timestamp as string)) end) as sessions,
-- engaged sessions (metric | the number of sessions that lasted longer than 10 seconds, or had a conversion event, or had 2 or more screen or page views)
max(engaged_sessions) as engaged_sessions,
-- engagement rate (metric | the percentage of engaged sessions compared to all sessions)
safe_divide(max(engaged_sessions),count(distinct case when event_name = 'session_start' then concat(user_pseudo_id, cast(event_timestamp as string)) end)) as engagement_rate,
-- engagement time (metric | the average length of time in seconds that the app was in the foreground, or the web site had focus in the browser)
safe_divide(max(engagement_time_seconds),max(engaged_sessions)) as engagement_time,
-- bounces (metric | the total number of non-engaged sessions)
max(bounces) as bounces,
-- bounce rate (metric | bounces divided by total sessions)
safe_divide(max(bounces),count(distinct case when event_name = 'session_start' then concat(user_pseudo_id, cast(event_timestamp as string)) end)) as bounce_rate,
-- event count per session (metric | number of times an individual event (i.e. 'page_view') was triggered divided by all sessions)
safe_divide(count(distinct case when event_name = 'page_view' then concat(user_pseudo_id, cast(event_timestamp as string)) end),count(distinct case when event_name = 'session_start' then concat(user_pseudo_id, cast(event_timestamp as string)) end)) as event_count_per_session
from
-- change this to your google analytics 4 export location in bigquery
`celtic-current-353007.analytics_309529570.events_*`,
date_range,
engagement
where
_table_suffix between date_range.start_date and date_range.end_date
gist.github.com
event_name
. Т.е. даже не значение, а система не может понять, что это такоеevent_name
. Я, как человек, понимаю, что этоимя_события
, но ваше окружение этого не понимает :). Вообщем, не слушайте меня, тут может подтянутся спецыselect * from имя_таблицы
. Затем постепенно добавлятьwhere
и таким образом выйти на ошибку ( это всё мои фантазии )