我们当前正在从Google Analytics(分析)(移动数据)迁移到Firebase。
firebase中的数据正在流式传输到BigData,我们使用以下查询来计算会话持续时间。
当我在这些会话上运行报告时,通过Firebase报告的平均会话持续时间比Google Analytics(分析)报告的平均会话持续时间短约4倍。
我在各种设备(Android,iOS)上遇到相同的问题,并同时向Google Analytics(分析)和Firebase发送相同的自定义事件
使用session_start事件或不必要的user_properties并直接使用ga_session_number来获得相同的结果。
with timeline as
(
select
geo.city as geo_city
,device.operating_system as device_category
, user_pseudo_id
, event_name
, event_timestamp
, lag(event_timestamp, 1) over (partition by user_pseudo_id order by event_timestamp) as prev_event_timestamp
from
`projid.analytics_xxx.events_*`
)
, session_timeline as
(
select
event_name
, geo_city
, device_category
, user_pseudo_id
, event_timestamp
, prev_event_timestamp
, case
when
event_timestamp - prev_event_timestamp >= (30*60*1000*1000)
or
prev_event_timestamp is null
then 1
else 0
end as is_new_session_flag
from
timeline
)
, marked_sessions as
(
select
device_category
, geo_city
, user_pseudo_id
, event_timestamp
, prev_event_timestamp
, sum(is_new_session_flag) over (partition by user_pseudo_id order by event_timestamp) AS user_session_id
, min(prev_event_timestamp) over (partition by user_pseudo_id order by event_timestamp) AS first_prev_event_timestamp
from session_timeline
)
, measured_sessions as
(
select
device_category
, geo_city
, user_pseudo_id
, user_session_id
, FORMAT_TIMESTAMP("%F", TIMESTAMP_MICROS(first_prev_event_timestamp)) as first_time_date
, FORMAT_TIMESTAMP("%F", TIMESTAMP_MICROS(min(event_timestamp))) as date
, round((max(event_timestamp) - min(event_timestamp))/ (1000 * 1000), 2) as session_duration_seconds
, round((max(event_timestamp) - min(event_timestamp))/ (1000 * 1000 * 60), 2) as session_duration_minutes
, round((max(event_timestamp) - min(event_timestamp))/ (1000 * 1000 * 60 * 60), 2) as session_duration_hours
from
marked_sessions
group by
user_pseudo_id
, user_session_id
, device_category
, geo_city
, first_prev_event_timestamp
having
-- let's count only sessions longer than 10 seconds
session_duration_seconds >= 10
)
select
*
from
measured_sessions
order by date desc, user_pseudo_id desc, user_session_id desc
不仅平均会话时长有显着差异,甚至会话数也不合乎要求。