我可以在 Firebase Analytics 中找到平均会话持续时间。如何通过 Bigquery 提取此指标
Posted
技术标签:
【中文标题】我可以在 Firebase Analytics 中找到平均会话持续时间。如何通过 Bigquery 提取此指标【英文标题】:Where i can find Average Session Duration in Firebase Analytics. How to Extract this Metrics Through Bigquery 【发布时间】:2019-04-25 10:40:04 【问题描述】:-
在哪里可以找到平均。 Firebase 分析中的会话持续时间指标?
如何提取平均。来自 Bigquery 的会话持续时间指标数据?
平均。会话持续时间指标,以前在 Firebase 分析仪表板中可用。但现在,它在 Firebase 分析仪表板中不可用。现在,我们只看到“每个用户的参与度”。是每个用户的参与度和平均。会话持续时间两者都相同吗?如何提取平均。 Fiebase 分析的会话持续时间?如何在 Bigquery 中查询以提取 Avg。 Firebase 的会话持续时间指标。 enter image description here
【问题讨论】:
【参考方案1】:每位用户的参与度与平均参与度不同。会话持续时间。每位用户的参与度是指用户在一天中在应用中花费的所有时间,而不是在会话中。
您可以找到平均。最新版本下 Firebase Analytics 中的会话持续时间。
这是一个计算平均值的查询。 BigQuery 中的会话长度:
with timeline as
(
select
user_pseudo_id
, event_timestamp
, lag(event_timestamp, 1) over (partition by user_pseudo_id order by event_timestamp) as prev_event_timestamp
from
`YYYYY.analytics_XXXXX.events_*`
where
-- at first - a sliding period - how many days in the past we are looking into:
_table_suffix
between format_date("%Y%m%d", date_sub(current_date, interval 10 day))
and format_date("%Y%m%d", date_sub(current_date, interval 1 day))
)
, session_timeline as
(
select
user_pseudo_id
, event_timestamp
, case
when
-- half a hour period - a threshold for a new 'session'
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
user_pseudo_id
, event_timestamp
, sum(is_new_session_flag) over (partition by user_pseudo_id order by event_timestamp) AS user_session_id
from session_timeline
)
, measured_sessions as
(
select
user_pseudo_id
, user_session_id
-- session duration in seconds with 2 digits after the point
, round((max(event_timestamp) - min(event_timestamp))/ (1000 * 1000), 2) as session_duration
from
marked_sessions
group by
user_pseudo_id
, user_session_id
having
-- let's count only sessions longer than 10 seconds
session_duration >= 10
)
select
count(1) as number_of_sessions
, round(avg(session_duration), 2) as average_session_duration_in_sec
from
measured_sessions
有关如何获取 event_date 和 app_info.id 的其他问题,请参阅以下查询:
with timeline as
(
select
event_date,app_info.id,user_pseudo_id
, event_timestamp
, lag(event_timestamp, 1) over (partition by user_pseudo_id order by event_timestamp) as prev_event_timestamp
from
`<table>_*`
where
-- at first - a sliding period - how many days in the past we are looking into:
_table_suffix
between format_date("%Y%m%d", date_sub(current_date, interval 10 day))
and format_date("%Y%m%d", date_sub(current_date, interval 1 day))
)
, session_timeline as
(
select
event_date,id,
user_pseudo_id
, event_timestamp
, case
when
-- half a hour period - a threshold for a new 'session'
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
event_date,id, user_pseudo_id
, event_timestamp
, sum(is_new_session_flag) over (partition by user_pseudo_id order by event_timestamp) AS user_session_id
from session_timeline
)
, measured_sessions as
(
select
event_date,id, user_pseudo_id
, user_session_id
-- session duration in seconds with 2 digits after the point
, round((max(event_timestamp) - min(event_timestamp))/ (1000 * 1000), 2) as session_duration
from
marked_sessions
group by
event_date, id, user_pseudo_id
, user_session_id
having
-- let's count only sessions longer than 10 seconds
session_duration >= 10
)
select
event_date, id, count(1) as number_of_sessions
, round(avg(session_duration), 2) as average_session_duration_in_sec
from
measured_sessions
group by event_date, id
【讨论】:
嗨,玛雅。谢谢你的支持。它工作正常:)。我得到输出“number_of_sessions”和“average_session_duration_in_sec”。谢谢你。需要您对“如何获取平均会话持续时间日期明智和 app_info.id 明智”的支持......在上述查询中包含“event_date”和“app_info.id”字段的位置以获取日期和应用明智 -平均会话持续时间数据。请。帮助。再次感谢您的大力支持。等待您对我的查询的答复。请。帮助 嗨,玛雅。请。在代码下方找到,我尝试在代码中添加 event_date 和 app_info.id。代码工作正常。但结果是,事件日期和应用程序信息值没有出现。请。帮助 嗨,玛雅。感谢您的及时和出色的支持。你真好。 嗨,玛雅:请问可以吗?帮我解决以下问题·***.com/questions/57951487/… @Maja From Andersen 这里 date_sub 的作用是什么?【参考方案2】:每个会话(自 2019 年 12 月起在此处定义:https://firebase.googleblog.com/2018/12/new-changes-sessions-user-engagement.html)都有一个 session_id(除了其他参数)。我认为计算平均会话持续时间的最安全和最可靠的方法是将数据提取到 BigQuery,然后按会话计算第一个和最后一个时间戳之间的平均差异。为此,您需要展平 event_params
的数组。例如,这就是在 AWS Athena 中完成的方式:
WITH arrays_flattened AS
(SELECT params.key AS key,
params.value.int_value AS id,
event_timestamp,
event_date
FROM your_database
CROSS JOIN UNNEST(event_params) AS t(params)
WHERE params.key = 'ga_session_id'), duration AS
(SELECT MAX(event_timestamp)-MIN(event_timestamp) AS duration
FROM arrays_flattened
WHERE key = 'ga_session_id'
GROUP BY id)
SELECT AVG(duration)
FROM duration
【讨论】:
以上是关于我可以在 Firebase Analytics 中找到平均会话持续时间。如何通过 Bigquery 提取此指标的主要内容,如果未能解决你的问题,请参考以下文章
无法使用 Unity 在 Firebase-Analytics 中获取自定义参数
Firebase Analytics - 无法检索 Firebase 实例 ID
是否不仅可以在 Firebase Analytics 中查看过去 30 分钟内的事件?
如何将以前的Firebase Analytics导出到Bigquery [重复]