Unlock the power of Google Analytics with Big Query

How to Calculate GA4 Sessions in BigQuery: A Simple Step-by-Step Guide

How to Calculate GA4 Sessions in BigQuery: A Simple Step-by-Step Guide

Google Analytics 4 (GA4) stores event-based data in BigQuery, where sessions are derived from event timestamps and session identifiers. Below are the steps to calculate the number of sessions from GA4 BigQuery exports, including an example SQL query.


Step 1: Understanding Sessions in GA4


Step 2: Writing the SQL Query

Use the following SQL query to count sessions from your GA4 export:

WITH session_data AS (
    SELECT
        event_bundle_sequence_id,
        user_pseudo_id,
        session_id,
        TIMESTAMP_MICROS(event_bundle_sequence_id) AS event_time
    FROM `your_project.analytics_XXXXXXXX.events_YYYYMMDD`
    WHERE event_name = 'session_start'
)
SELECT
    COUNT(DISTINCT CONCAT(user_pseudo_id, session_id)) AS total_sessions
FROM session_data;

Explanation of the Query:


Step 3: Verifying the Data in BigQuery

  1. Navigate to BigQuery Console.
  2. Open your GA4 dataset (e.g., analytics_XXXXXXXX).
  3. Paste the above SQL query and run it.
  4. Check the results for total session count.


Things to Keep in Mind:


Notes:

By following these steps and considerations, you can accurately calculate and analyze GA4 sessions in BigQuery.

Discover more from GA4 BigQuery

Subscribe now to keep reading and get access to the full archive.

Continue reading