Understanding Users and New Users Metrics in Google Analytics 4

Google Analytics is a powerful tool for understanding how visitors interact with your website. For those just starting out, two of the most important metrics to grasp are “Users” and “New Users.” In this blog post, we’ll break down these metrics and show you how to retrieve them using BigQuery.

What are “Users” and “New Users”?

Users: This metric represents the total number of individuals who have visited your site within a given timeframe. Each user is counted once, regardless of how many times they visit your site.

New Users: This metric indicates the number of first-time visitors to your site during the specified timeframe. These are users who have never visited your site before.

How to Access These Metrics in BigQuery

BigQuery is a powerful tool that allows you to run complex queries on your Google Analytics data. To get started, you’ll need to set up a project in the Google Cloud Console and link your Google Analytics account to BigQuery.

Here is a sample BigQuery SQL query to retrieve Users and New Users metrics:

WITH
  UserInfo AS (
    SELECT
      user_pseudo_id,
      MAX(IF(event_name IN ('first_visit', 'first_open'), 1, 0)) AS is_new_user
    -- Replace table name.
    FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
    -- Replace date range.
    WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240130'
    GROUP BY 1
  )
SELECT
  COUNT(*) AS user_count,
  SUM(is_new_user) AS new_user_count
FROM UserInfo;

Explanation of the Query

  • Common Table Expression (CTE) – UserInfo:
    • This part of the query creates a temporary result set named UserInfo.
    • user_pseudo_id: This field uniquely identifies each user.
    • MAX(IF(event_name IN (‘first_visit’, ‘first_open’), 1, 0)) AS is_new_user: This line checks if an event is either ‘first_visit’ or ‘first_open’. If it is, it assigns a value of 1, indicating a new user. The MAX function ensures that even if there are multiple events for the same user, it only returns 1 if the user is new.
    • The GROUP BY 1 groups the results by user_pseudo_id, ensuring each user is considered only once.
  • Main Query:
    • COUNT(*) AS user_count: This line counts the total number of users.
    • SUM(is_new_user) AS new_user_count: This line sums up the is_new_user values. Since is_new_user is 1 for new users and 0 for others, this sum gives the total count of new users.
Share your love

Leave a Reply

Your email address will not be published. Required fields are marked *