Request a demo

GA4 in BigQuery · Users, sessions and traffic

New vs returning users in GA4 BigQuery

In the GA4 export a new user is one who logged first_visit (first_open in apps) in the period; everyone else active in the period is returning. Flag first_visit per user and day with LOGICAL_OR, then split the daily user count.

Runs on Google's public sample bigquery-public-data.ga4_obfuscated_sample_ecommerce · Scans 67.3 MiB, under $0.01 on-demand · Checked in November 2026

The query

WITH daily AS (
  SELECT
    PARSE_DATE('%Y%m%d', event_date)       AS day,
    user_pseudo_id,
    LOGICAL_OR(event_name = 'first_visit') AS is_new
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
  GROUP BY day, user_pseudo_id
)
SELECT
  day,
  COUNT(*)                   AS users,
  COUNTIF(is_new)            AS new_users,
  COUNTIF(NOT is_new)        AS returning_users,
  ROUND(COUNTIF(is_new) / COUNT(*), 3) AS new_user_share
FROM daily
GROUP BY day
ORDER BY day;

How it works

GA4 marks a user's first visit with the first_visit event (web) or first_open (apps). Google's guide to matching the interface computes new users exactly that way, MAX(IF(event_name IN ('first_visit', 'first_open'), 1, 0)) per user, and returning users as the remaining users. The query does the same per day.

Returning, in this split, means "seen before this day", not "came back after a previous session in this range". Google's Returning users metric is defined as users who initiated at least one previous session, so a user whose first_visit was last month counts as returning today even if this is their first event in your range.

The split counts total users (any event). GA4 reports use active users; to match them, add the active-user flag from users, which needs event_params and costs more. The sample has no is_active_user column.

Per-day rows are fine to chart, but new and returning are not additive across days: a user can be new on Monday and returning on Tuesday. For a period total, group by user over the whole range instead of by day.

ColumnMeaning
usersDistinct users with any event that day.
new_usersUsers whose first_visit happened that day.
returning_usersUsers with events that day and no first_visit that day.
new_user_shareNew users as a share of the day's users.

Notes and cost

  • Cost: only event_date, event_name and user_pseudo_id, 67.3 MiB for one month. No event_params, so this stays cheap even on large exports.
  • If your site sends first_visit twice for a user (cookies cleared, consent changes), that user counts as new again with a new user_pseudo_id. The export cannot tell the difference.
  • On apps, add 'first_open' to the condition: event_name IN ('first_visit', 'first_open').

Variations

New vs returning sessions with ga_session_number

ga_session_number = 1 marks the user's first session. This splits sessions, not users, and needs event_params.

WITH sessions AS (
  SELECT
    user_pseudo_id,
    (SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS ga_session_id,
    MAX((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_number')) AS ga_session_number
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
  GROUP BY user_pseudo_id, ga_session_id
)
SELECT
  IF(ga_session_number = 1, 'new', 'returning') AS session_type,
  COUNT(*)                                     AS sessions
FROM sessions
GROUP BY session_type;

Returning users by first-touch date

Uses user_first_touch_timestamp (microseconds, UTC) to separate users acquired before the month from users acquired during it.

WITH users AS (
  SELECT
    user_pseudo_id,
    MIN(user_first_touch_timestamp) AS first_touch
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
  GROUP BY user_pseudo_id
)
SELECT
  CASE
    WHEN first_touch IS NULL THEN 'unknown'
    WHEN first_touch < UNIX_MICROS(TIMESTAMP '2020-12-01') THEN 'acquired before December'
    ELSE 'acquired in December'
  END      AS user_type,
  COUNT(*) AS users
FROM users
GROUP BY user_type;

FAQ

How does GA4 define a new user in BigQuery?

A user who logged the first_visit event (web) or first_open (apps) in the date range. Count them with COUNT(DISTINCT IF(event_name = 'first_visit', user_pseudo_id, NULL)).

Why do new plus returning users not equal total users for a month?

If you sum daily rows, a user who is new on one day and returning on later days is counted on every day. Compute the split once per user over the whole month.

All GA4 export queries · BigQuery cost queries · The GA4 sample dataset

Cut BigQuery spend without guessing

Masthead attributes compute and storage cost to every project, user, pipeline and table, finds unused and dead-end tables, and shows where editions or on-demand pricing is cheaper. Mnemonic cut its BigQuery compute cost by 20% within 24 hours of onboarding.