Calculating Sessions and Engaged Sessions in GA4 BigQuery
Here is how you can calculate ‘sessions’ and ‘engaged sessions’ in GA4 BigQuery.
First thing first.
Both ‘sessions‘ and ‘engaged sessions’ metrics need to be manually calculated.
They are not available as default fields in the GA4 BigQuery export schema.
You must know the formula (underlying logic) to calculate a particular GA4 dimension/metric in BigQuery.
If you do not understand the underlying logic, you will have a hard time using a particular GA4 dimension/metric in BigQuery, even if I give you the exact SQL code to copy and paste.
There can be ‘N’ use cases, and it is impossible to provide pre-built SQL code for every possible use case.
Note: To find formulas for a particular dimension or metric, refer to the ‘GA4 to BigQuery Mapping Tutorial‘ article.
In addition to knowing the formula, you must be familiar with the GA4 BigQuery export schema so that you can easily refer to a default dimension/metric and identify the data type they use.
If you are new to the schema, refer to the ‘GA4 BigQuery Schema Tutorial‘.
Once you understand the formula and export schema, it will be easier and possible for you to modify the SQL code to meet your unique requirements.
Calculating Sessions in GA4 BigQuery
To calculate the total number of sessions, use ‘Common Table Expressions (CTEs)’ and count each unique combination of ‘user_pseudo_id’ and ‘ga_session_id’.
A Common Table Expression (CTE) is a temporary result set that you define within an SQL statement. It acts like a temporary table that exists only for the duration of the query.
CTEs allow you to break down complex queries into manageable parts, making the SQL easier to read and understand.
This is especially helpful when working with intricate logic or multiple steps in a calculation.
With CTEs, you can define a calculation once and reference it multiple times within the same query.
This avoids duplication of code and reduces the risk of errors.
The ‘user_pseudo_id’ is an event parameter which is extracted as an integer value. It is a unique identifier for a user.
The ‘ga_session_id’ is an array of structures within the ‘event_params’ array of structures.
It is extracted as a string value and is a unique identifier for a session.
Once you have created the required SQL code using the logic mentioned above, you should see an output like the one below:
If you struggle with creating the correct SQL code, message me on LinkedIn, and I will share it with you.
Calculating Engaged Sessions in GA4 BigQuery
To calculate ‘engaged sessions’, use Common Table Expression and count distinct sessions for which the value of the ‘session_engaged’ event parameter is 1.
Needless to say, you need to calculate the ‘sessions’ metric first before you can calculate the ‘Engaged Sessions’ metric.
The ‘session_engaged’ is an array of structures within the ‘event_params’ array of structures.
The ‘session_engaged’ parameter is extracted as an integer value.
Once you have created the required SQL code using the logic mentioned above, you should see an output like the one below:
If you struggle with creating the correct SQL code, message me on LinkedIn, and I will share it with you.
Other articles on GA4 BigQuery
#1 BigQuery Introduction
- How to create a new Google Cloud Platform account.
- How to create a new BigQuery project.
- What is Google BigQuery Sandbox and how to use it.
- Understanding the BigQuery User Interface.
- What is BigQuery Data Transfer Service & how it works.
- How to create data transfer in BigQuery.
- Connect and transfer data from Google Sheets to BigQuery.
- How to access BigQuery Public Data Sets.
- Best Supermetrics Alternative – Dataddo.
#2 GA4 BigQuery Introduction
- Google Analytics 4 BigQuery Tutorial for Beginners to Advanced.
- GA4 Bigquery Export Schema Tutorial.
- GA4 BigQuery – Connect Google Analytics 4 with BigQuery.
- events_ & events_intraday_ tables in BigQuery for GA4 (Google Analytics 4).
- pseudonymous_users_ & users_ data tables in BigQuery for GA4 (Google Analytics 4).
- How to access GA4 Sample Data in BigQuery.
- Advantages of using Google BigQuery for Google Analytics 4.
- Impact of Google Advanced Consent Mode on BigQuery & GDPR.
#3 GA4 BigQuery Data Transfer
- How to Connect and Export Data from GA4 to BigQuery
- How to backfill GA4 data in BigQuery.
- How to overcome GA4 BigQuery Export limit.
- How to Send Custom GA4 Data to BigQuery.
- How to backup Universal Analytics data to BigQuery.
- How to send data from Google Ads to BigQuery.
- How to send data from Google Search Console to BigQuery.
- Sending data from Google Analytics to BigQuery without 360.
- How to send data from Facebook ads to BigQuery.
- How to pull custom data from Google Analytics to BigQuery.
#4 BigQuery Cost Optimization
- Guide to BigQuery Cost Optimization.
- Using Google Cloud pricing calculator for BigQuery.
- Cost of using BigQuery for Google Analytics 4.
#5 Query GA4 BigQuery Data
- How to query Google Analytics data in BigQuery.
- Query GA4 data in BigQuery without understanding SQL.
- Using GA4 BigQuery SQL generator to create SQL queries.
- New vs Returning users in GA4 BigQuery data table.
- GA4 BigQuery Composer Tutorial for ChatGPT.
- How to track GA4 BigQuery Schema Change.
- Calculating Sessions and Engaged Sessions in GA4 BigQuery.
- Calculating Total Users in GA4 BigQuery.
#6 GA4 to BigQuery Dimension/Metric Mapping.
- GA4 to BigQuery Mapping Tutorial.
- GA4 Attribution Dimensions to BigQuery Mapping.
- GA4 Google Ads Dimensions to BigQuery Mapping.
- GA4 Demographic Dimensions to BigQuery Mapping.
- GA4 Ecommerce Dimensions to BigQuery Mapping.
- GA4 Event-Scoped Ecommerce Metrics to BigQuery Mapping.
- GA4 Item-Scoped Ecommerce Metrics to BigQuery Mapping.
- GA4 Revenue Metrics to BigQuery Mapping.
- GA4 Event Dimensions to BigQuery Mapping.
- GA4 Event Metrics to BigQuery Mapping.
- GA4 Geography Dimensions to BigQuery Mapping.
- GA4 Link Dimensions to BigQuery Mapping.
- GA4 Page/Screen Dimensions to BigQuery Mapping.
- GA4 Page/Screen Metrics to BigQuery Mapping.
- GA4 Platform/Device Dimensions to BigQuery Mapping.
- GA4 User-Scoped Traffic Dimensions to BigQuery Mapping.
- GA4 Session-Scoped Traffic Dimensions to BigQuery Mapping.
- GA4 Session Metrics to BigQuery Mapping.
- GA4 User Dimensions to BigQuery Mapping.
- GA4 User Metrics to BigQuery Mapping.
- GA4 Advertising Metrics to BigQuery Mapping.
-
Here is how you can calculate ‘sessions’ and ‘engaged sessions’ in GA4 BigQuery.
First thing first.
Both ‘sessions‘ and ‘engaged sessions’ metrics need to be manually calculated.
They are not available as default fields in the GA4 BigQuery export schema.
You must know the formula (underlying logic) to calculate a particular GA4 dimension/metric in BigQuery.
If you do not understand the underlying logic, you will have a hard time using a particular GA4 dimension/metric in BigQuery, even if I give you the exact SQL code to copy and paste.
There can be ‘N’ use cases, and it is impossible to provide pre-built SQL code for every possible use case.
Note: To find formulas for a particular dimension or metric, refer to the ‘GA4 to BigQuery Mapping Tutorial‘ article.
In addition to knowing the formula, you must be familiar with the GA4 BigQuery export schema so that you can easily refer to a default dimension/metric and identify the data type they use.
If you are new to the schema, refer to the ‘GA4 BigQuery Schema Tutorial‘.
Once you understand the formula and export schema, it will be easier and possible for you to modify the SQL code to meet your unique requirements.
Calculating Sessions in GA4 BigQuery
To calculate the total number of sessions, use ‘Common Table Expressions (CTEs)’ and count each unique combination of ‘user_pseudo_id’ and ‘ga_session_id’.
A Common Table Expression (CTE) is a temporary result set that you define within an SQL statement. It acts like a temporary table that exists only for the duration of the query.
CTEs allow you to break down complex queries into manageable parts, making the SQL easier to read and understand.
This is especially helpful when working with intricate logic or multiple steps in a calculation.
With CTEs, you can define a calculation once and reference it multiple times within the same query.
This avoids duplication of code and reduces the risk of errors.
The ‘user_pseudo_id’ is an event parameter which is extracted as an integer value. It is a unique identifier for a user.
The ‘ga_session_id’ is an array of structures within the ‘event_params’ array of structures.
It is extracted as a string value and is a unique identifier for a session.
Once you have created the required SQL code using the logic mentioned above, you should see an output like the one below:
If you struggle with creating the correct SQL code, message me on LinkedIn, and I will share it with you.
Calculating Engaged Sessions in GA4 BigQuery
To calculate ‘engaged sessions’, use Common Table Expression and count distinct sessions for which the value of the ‘session_engaged’ event parameter is 1.
Needless to say, you need to calculate the ‘sessions’ metric first before you can calculate the ‘Engaged Sessions’ metric.
The ‘session_engaged’ is an array of structures within the ‘event_params’ array of structures.
The ‘session_engaged’ parameter is extracted as an integer value.
Once you have created the required SQL code using the logic mentioned above, you should see an output like the one below:
If you struggle with creating the correct SQL code, message me on LinkedIn, and I will share it with you.
Other articles on GA4 BigQuery
#1 BigQuery Introduction
- How to create a new Google Cloud Platform account.
- How to create a new BigQuery project.
- What is Google BigQuery Sandbox and how to use it.
- Understanding the BigQuery User Interface.
- What is BigQuery Data Transfer Service & how it works.
- How to create data transfer in BigQuery.
- Connect and transfer data from Google Sheets to BigQuery.
- How to access BigQuery Public Data Sets.
- Best Supermetrics Alternative – Dataddo.
#2 GA4 BigQuery Introduction
- Google Analytics 4 BigQuery Tutorial for Beginners to Advanced.
- GA4 Bigquery Export Schema Tutorial.
- GA4 BigQuery – Connect Google Analytics 4 with BigQuery.
- events_ & events_intraday_ tables in BigQuery for GA4 (Google Analytics 4).
- pseudonymous_users_ & users_ data tables in BigQuery for GA4 (Google Analytics 4).
- How to access GA4 Sample Data in BigQuery.
- Advantages of using Google BigQuery for Google Analytics 4.
- Impact of Google Advanced Consent Mode on BigQuery & GDPR.
#3 GA4 BigQuery Data Transfer
- How to Connect and Export Data from GA4 to BigQuery
- How to backfill GA4 data in BigQuery.
- How to overcome GA4 BigQuery Export limit.
- How to Send Custom GA4 Data to BigQuery.
- How to backup Universal Analytics data to BigQuery.
- How to send data from Google Ads to BigQuery.
- How to send data from Google Search Console to BigQuery.
- Sending data from Google Analytics to BigQuery without 360.
- How to send data from Facebook ads to BigQuery.
- How to pull custom data from Google Analytics to BigQuery.
#4 BigQuery Cost Optimization
- Guide to BigQuery Cost Optimization.
- Using Google Cloud pricing calculator for BigQuery.
- Cost of using BigQuery for Google Analytics 4.
#5 Query GA4 BigQuery Data
- How to query Google Analytics data in BigQuery.
- Query GA4 data in BigQuery without understanding SQL.
- Using GA4 BigQuery SQL generator to create SQL queries.
- New vs Returning users in GA4 BigQuery data table.
- GA4 BigQuery Composer Tutorial for ChatGPT.
- How to track GA4 BigQuery Schema Change.
- Calculating Sessions and Engaged Sessions in GA4 BigQuery.
- Calculating Total Users in GA4 BigQuery.
#6 GA4 to BigQuery Dimension/Metric Mapping.
- GA4 to BigQuery Mapping Tutorial.
- GA4 Attribution Dimensions to BigQuery Mapping.
- GA4 Google Ads Dimensions to BigQuery Mapping.
- GA4 Demographic Dimensions to BigQuery Mapping.
- GA4 Ecommerce Dimensions to BigQuery Mapping.
- GA4 Event-Scoped Ecommerce Metrics to BigQuery Mapping.
- GA4 Item-Scoped Ecommerce Metrics to BigQuery Mapping.
- GA4 Revenue Metrics to BigQuery Mapping.
- GA4 Event Dimensions to BigQuery Mapping.
- GA4 Event Metrics to BigQuery Mapping.
- GA4 Geography Dimensions to BigQuery Mapping.
- GA4 Link Dimensions to BigQuery Mapping.
- GA4 Page/Screen Dimensions to BigQuery Mapping.
- GA4 Page/Screen Metrics to BigQuery Mapping.
- GA4 Platform/Device Dimensions to BigQuery Mapping.
- GA4 User-Scoped Traffic Dimensions to BigQuery Mapping.
- GA4 Session-Scoped Traffic Dimensions to BigQuery Mapping.
- GA4 Session Metrics to BigQuery Mapping.
- GA4 User Dimensions to BigQuery Mapping.
- GA4 User Metrics to BigQuery Mapping.
- GA4 Advertising Metrics to BigQuery Mapping.
My best selling books on Digital Analytics and Conversion Optimization
Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.
Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.
Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.