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. // To find formulas for a particular dimension or metric refer to the 'GA4 to BigQuery Mapping Tutorial' article on my website. . . 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' on my website. . . 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. . . 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'. . . 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 a string 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. The 'ga_session_id' is extracted as a string value and is a unique identifier for a session. . . To calculate 'engaged sessions', use Common Table Expression and count distinct sessions for which the value of the 'session_engaged' event parameter is 1. 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. . . Armed with this knowledge, you now have two options: 1) Manually create and debug SQL code that implements the abovementioned two formulas. 2) Create a text prompt in 'GA4 BigQuery Composer' (a ChatGPT-powered SQL generator) to automatically create the SQL code for you. . . If you want the SQL code for 'sessions' and 'engaged sessions' metrics, comment 'SQL code' and I will send it to you. If we are not connected, make sure to add me first. **** Share and Like this post if you found it useful. ****
Session! Thank you in advance!
Especialista de Digital Analytics @ Livelo
4moSql code