Where i can find Average Session Duration in Firebase Analytics. How to Extract this Metrics Through Bigquery
Engagement per User is not the same as Avg. Session Duration. Engagement per User is all the time a user spends in the app in a day, not in a session.
You can find Avg. Session Duration in Firebase Analytics under Latest Release.
Here is a query for calculating avg. session length in 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
How to calculate Session duration and avg. Session duration in Google Analytics raw data?
You can use the field totals.timeOnSite
as described in the ga table schema, something like:
SELECT
AVG(totals.timeOnSite) avgTimeOnSite
FROM `project_id.dataset_id.ga_sessions_*`
WHERE _TABLE_SUFFIX BETWEEN "20170701" and "20170702"
Related Topics
In SQL, Is Update Always Faster Than Delete+Insert
How to Copy a Huge Table Data into Another Table in SQL Server
SQL Error: Ora-00933: SQL Command Not Properly Ended
Why Does Using an Underscore Character in a Like Filter Give Me All the Results
SQL Primary Key: Integer VS Varchar
How to Do Multiple Case When Conditions Using SQL Server 2008
How Do SQL Exists Statements Work
Why Does Isnumeric('.') Return 1
A Way to Extract from a Datetime Value Data Without Seconds
How to Delete a Fixed Number of Rows with Sorting in Postgresql
What Are the Benefits of Using Database Cursor
SQL Comma-Separated Row with Group by Clause
How to Populate Calendar Table in Oracle
Pivot Query on Distinct Records