New vs Returning users in GA4 BigQuery data table
Here is how you can calculate ‘New’ and ‘Returning users in GA4 BigQuery.
First thing first.
Both ‘New’ and ‘Returning’ users metrics need to be manually calculated.
They are not available as default fields in the GA4 BigQuery export schema.
Here is how you can find if a user is new or returning.
If the value of ‘ga_session_number’ event parameter is 1, classify the user as a ‘New User’.
If the value of ‘ga_session_number’ event parameter is greater than 1, classify the user as a ‘Returning User’.
The ‘ga_session_number’ event parameter is an array of structures within the ‘event_params’ array of structures. It is extracted as an integer value:
Calculating New Users in GA4 BigQuery for each day in the time range.
Let us suppose you want to calculate ‘New Users’ for each day in the date range Jan 1 to Jan 31, 2024
To calculate ‘New Users’ for each day in the date range, use ‘Common Table Expressions’ and classify a user as ‘New User’ if the value of the ‘ga_session_number’ event parameter is 1.
You can use the following SQL code:
WITH NewUserData AS (
SELECT
event_date,
user_pseudo_id,
CASE
WHEN (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) = 1 THEN ‘New User’
ELSE NULL
END AS user_type
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
_TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
AND event_name = ‘session_start’
)
SELECT
event_date,
COUNTIF(user_type = ‘New User’) AS new_users
FROM
NewUserData
GROUP BY
event_date
ORDER BY
event_date;
Note: Make sure to use your own Table ID. Otherwise, the SQL won’t work.
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating the total number of new users in a particular date range.
Let us suppose you want to calculate the total number of ‘New Users’ in the date range Jan 1 to Jan 31, 2024
You can use the following SQL code:
WITH NewUserCTE AS (
SELECT
user_pseudo_id,
COUNTIF(
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) = 1
) AS is_new_user
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
event_name = ‘session_start’
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
GROUP BY
user_pseudo_id
)
SELECT
SUM(is_new_user) AS new_users
FROM
NewUserCTE
WHERE
is_new_user = 1;
Note: Make sure to use your own Table ID. Otherwise, the SQL won’t work.
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating Returning Users in GA4 BigQuery for each day in the time range.
Let us suppose you want to calculate ‘Returning Users’ for each day in the date range Jan 1 to Jan 31, 2024
To calculate ‘Returning Users’ for each day in the date range, use ‘Common Table Expressions’ and classify a user as ‘Returning User’ if the value of the ‘ga_session_number’ event parameter is greater than 1.
You can use the following SQL code:
WITH cte_returning_users AS (
SELECT
event_date,
COUNT(DISTINCT user_pseudo_id) AS returning_users
FROM
`dbrt-ga4.analytics_207472454.events_*`,
UNNEST(event_params) AS ep
WHERE
event_name = ‘session_start’
AND (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) > 1
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
GROUP BY
event_date
)
SELECT
event_date,
returning_users
FROM
cte_returning_users
ORDER BY
event_date;
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating the total number of returning users in a particular date range.
Let us suppose you want to calculate the total number of ‘Returning Users’ in the date range Jan 1 to Jan 31, 2024
You can use the following SQL code:
WITH returning_users AS (
SELECT
user_pseudo_id,
COUNTIF(
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) > 1
) AS is_returning_user
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
event_name = ‘session_start’
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
GROUP BY
user_pseudo_id
),
total_returning_users AS (
SELECT
COUNT(user_pseudo_id) AS returning_users
FROM
returning_users
WHERE
is_returning_user > 0
)
SELECT
returning_users
FROM
total_returning_users;
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating New Vs Returning Users in GA4 BigQuery in a particular date range.
Let us suppose you want to calculate new vs returning users in the date range Jan 1 to Jan 31, 2024
You can use the following SQL code:
WITH UserClassification AS (
SELECT
user_pseudo_id,
CASE
WHEN (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) = 1 THEN ‘New Users’
WHEN (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) > 1 THEN ‘Returning Users’
ELSE NULL
END AS user_type_calc
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
event_name = ‘session_start’
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
)
SELECT
user_type_calc,
COUNT(DISTINCT user_pseudo_id) AS users
FROM
UserClassification
WHERE
user_type_calc IS NOT NULL
GROUP BY
user_type_calc
ORDER BY
users DESC;
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
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 ‘New’ and ‘Returning users in GA4 BigQuery.
First thing first.
Both ‘New’ and ‘Returning’ users metrics need to be manually calculated.
They are not available as default fields in the GA4 BigQuery export schema.
Here is how you can find if a user is new or returning.
If the value of ‘ga_session_number’ event parameter is 1, classify the user as a ‘New User’.
If the value of ‘ga_session_number’ event parameter is greater than 1, classify the user as a ‘Returning User’.
The ‘ga_session_number’ event parameter is an array of structures within the ‘event_params’ array of structures. It is extracted as an integer value:
Calculating New Users in GA4 BigQuery for each day in the time range.
Let us suppose you want to calculate ‘New Users’ for each day in the date range Jan 1 to Jan 31, 2024
To calculate ‘New Users’ for each day in the date range, use ‘Common Table Expressions’ and classify a user as ‘New User’ if the value of the ‘ga_session_number’ event parameter is 1.
You can use the following SQL code:
WITH NewUserData AS (
SELECT
event_date,
user_pseudo_id,
CASE
WHEN (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) = 1 THEN ‘New User’
ELSE NULL
END AS user_type
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
_TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
AND event_name = ‘session_start’
)
SELECT
event_date,
COUNTIF(user_type = ‘New User’) AS new_users
FROM
NewUserData
GROUP BY
event_date
ORDER BY
event_date;
Note: Make sure to use your own Table ID. Otherwise, the SQL won’t work.
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating the total number of new users in a particular date range.
Let us suppose you want to calculate the total number of ‘New Users’ in the date range Jan 1 to Jan 31, 2024
You can use the following SQL code:
WITH NewUserCTE AS (
SELECT
user_pseudo_id,
COUNTIF(
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) = 1
) AS is_new_user
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
event_name = ‘session_start’
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
GROUP BY
user_pseudo_id
)
SELECT
SUM(is_new_user) AS new_users
FROM
NewUserCTE
WHERE
is_new_user = 1;
Note: Make sure to use your own Table ID. Otherwise, the SQL won’t work.
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating Returning Users in GA4 BigQuery for each day in the time range.
Let us suppose you want to calculate ‘Returning Users’ for each day in the date range Jan 1 to Jan 31, 2024
To calculate ‘Returning Users’ for each day in the date range, use ‘Common Table Expressions’ and classify a user as ‘Returning User’ if the value of the ‘ga_session_number’ event parameter is greater than 1.
You can use the following SQL code:
WITH cte_returning_users AS (
SELECT
event_date,
COUNT(DISTINCT user_pseudo_id) AS returning_users
FROM
`dbrt-ga4.analytics_207472454.events_*`,
UNNEST(event_params) AS ep
WHERE
event_name = ‘session_start’
AND (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) > 1
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
GROUP BY
event_date
)
SELECT
event_date,
returning_users
FROM
cte_returning_users
ORDER BY
event_date;
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating the total number of returning users in a particular date range.
Let us suppose you want to calculate the total number of ‘Returning Users’ in the date range Jan 1 to Jan 31, 2024
You can use the following SQL code:
WITH returning_users AS (
SELECT
user_pseudo_id,
COUNTIF(
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) > 1
) AS is_returning_user
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
event_name = ‘session_start’
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
GROUP BY
user_pseudo_id
),
total_returning_users AS (
SELECT
COUNT(user_pseudo_id) AS returning_users
FROM
returning_users
WHERE
is_returning_user > 0
)
SELECT
returning_users
FROM
total_returning_users;
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
Calculating New Vs Returning Users in GA4 BigQuery in a particular date range.
Let us suppose you want to calculate new vs returning users in the date range Jan 1 to Jan 31, 2024
You can use the following SQL code:
WITH UserClassification AS (
SELECT
user_pseudo_id,
CASE
WHEN (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) = 1 THEN ‘New Users’
WHEN (SELECT value.int_value FROM UNNEST(event_params) WHERE key = ‘ga_session_number’) > 1 THEN ‘Returning Users’
ELSE NULL
END AS user_type_calc
FROM
`dbrt-ga4.analytics_207472454.events_*`
WHERE
event_name = ‘session_start’
AND _TABLE_SUFFIX BETWEEN ‘20240101’ AND ‘20240131’
)
SELECT
user_type_calc,
COUNT(DISTINCT user_pseudo_id) AS users
FROM
UserClassification
WHERE
user_type_calc IS NOT NULL
GROUP BY
user_type_calc
ORDER BY
users DESC;
Copy-paste the SQL code into the SQL editor of your GA4 BigQuery project and then click on the ‘Run’ button.
You should now see the query result like the one below:
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.