Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to calculate session duration in BigQuery for GA4 event table data

We recently moved to GA4 from UA and trying to calculate the session duration. I have the following question-

  • Is it correct that session_start does not always trigger? 
  • How can we calculate the session duration?
  • Is there any specific event for the session end?
  • Will there be a discrepancy between bigquery raw table and GA4 report?

 

Please help me out with how to effectively calculate the session duration. 

Solved Solved
0 1 10.2K
1 ACCEPTED SOLUTION

Hi @sd_db,

Yes, session_start does not always trigger. In GA4, a session is initiated when a user either opens your app in the foreground or views a page or screen and no session is currently active (e.g. their previous session has timed out). By default, a session ends (times out) after 30 minutes of user inactivity. However, you can adjust the session timeout period. There is no limit to how long a session can last.

To calculate the session duration, you can use the sessionDuration metric. This metric measures the average amount of time that a user spends on your website or app in a single session. To calculate the session duration, you can use the following formula:

Session duration = (Total session time) / (Total number of sessions)

Total session time = Sum of all session times

Total number of sessions = Number of sessions

Session time = (Start time) - (End time)

Start time = Time of first event in session

End time = Time of last event in session

There is no specific event for the session end. However, you can use the sessionEnd event to track when a session ends. This event is triggered when a user either closes your app or leaves your website for more than 30 minutes.

There may be a discrepancy between the BigQuery raw table and GA4 report. This is because the BigQuery raw table contains all of the data from your website or app, while the GA4 report only contains data that has been processed by Google Analytics. The discrepancy will be most noticeable for sessions that are very short or very long.

 

View solution in original post

1 REPLY 1

Hi @sd_db,

Yes, session_start does not always trigger. In GA4, a session is initiated when a user either opens your app in the foreground or views a page or screen and no session is currently active (e.g. their previous session has timed out). By default, a session ends (times out) after 30 minutes of user inactivity. However, you can adjust the session timeout period. There is no limit to how long a session can last.

To calculate the session duration, you can use the sessionDuration metric. This metric measures the average amount of time that a user spends on your website or app in a single session. To calculate the session duration, you can use the following formula:

Session duration = (Total session time) / (Total number of sessions)

Total session time = Sum of all session times

Total number of sessions = Number of sessions

Session time = (Start time) - (End time)

Start time = Time of first event in session

End time = Time of last event in session

There is no specific event for the session end. However, you can use the sessionEnd event to track when a session ends. This event is triggered when a user either closes your app or leaves your website for more than 30 minutes.

There may be a discrepancy between the BigQuery raw table and GA4 report. This is because the BigQuery raw table contains all of the data from your website or app, while the GA4 report only contains data that has been processed by Google Analytics. The discrepancy will be most noticeable for sessions that are very short or very long.