Request a demo

GA4 in BigQuery · Working with the export

GA4 user_id vs user_pseudo_id in BigQuery

user_pseudo_id identifies a browser or app instance; user_id is the login ID you set yourself, NULL until you send it. Count people by mapping each user_pseudo_id to the user_id seen on any of its events, then counting COALESCE(user_id, user_pseudo_id).

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

The query

WITH ids AS (
  -- One row per browser: the login ID seen on any of its events, if any
  SELECT
    user_pseudo_id,
    MAX(user_id) AS user_id
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
  GROUP BY user_pseudo_id
)
SELECT
  COUNT(*)                                          AS pseudo_ids,
  COUNTIF(user_id IS NOT NULL)                      AS pseudo_ids_with_login,
  COUNT(DISTINCT user_id)                           AS user_ids,
  COUNT(DISTINCT COALESCE(user_id, user_pseudo_id)) AS people
FROM ids;

How it works

user_pseudo_id is the pseudonymous ID GA4 assigns on first visit; on the web it comes from the Analytics cookie, so one person on a laptop and a phone is two user_pseudo_id values, and clearing cookies creates a new one. user_id is the ID you send when someone logs in. It is NULL on events where you did not set it, including the events before login in the same visit.

Counting DISTINCT user_pseudo_id gives browsers, not people. Counting DISTINCT user_id ignores everyone who never logged in. The query stitches the two: every browser that ever carried a user_id inherits it for all its events, and everything else falls back to the pseudo ID. A person who logged in on two devices then counts once.

The GA4 interface goes further. With Google signals and a blended reporting identity it can deduplicate devices that never logged in, and none of that is in the export. Google also states that only device-ID based data is exported, so user counts from BigQuery are usually higher than in reports (see GA4 vs BigQuery differences).

In the sample, user_id is NULL on every one of the 4,295,584 events, and there are 270,154 distinct user_pseudo_id values across the three months. The query runs, but pseudo_ids_with_login and user_ids come back as 0.

ColumnMeaning
pseudo_idsDistinct browsers or app instances in the range.
pseudo_ids_with_loginBrowsers that carried a user_id on at least one event.
user_idsDistinct logged-in people.
peopleDistinct people after stitching: user_id where known, otherwise the browser.

Notes and cost

  • Cost: only user_pseudo_id and user_id for one month, 31.8 MiB. Identity questions rarely need event_params; keep it out of these queries.
  • MAX(user_id) picks one ID when a shared device saw several logins. If that matters, count COUNT(DISTINCT user_id) per user_pseudo_id first and decide how to treat shared devices.
  • The stitch is only as good as the date range. A browser that logged in last month but not this month stays anonymous here; for a stable mapping, keep a small user_pseudo_id to user_id table that you update daily.
  • Under consent mode, Google's guidance notes that cookieless pings arrive with a different user_pseudo_id per session, which inflates distinct counts. user_id is exported regardless of consent state.

Variations

Attach the stitched person ID to every event

WITH ids AS (
  SELECT user_pseudo_id, MAX(user_id) AS user_id
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
  GROUP BY user_pseudo_id
)
SELECT
  e.event_timestamp,
  e.event_name,
  COALESCE(ids.user_id, e.user_pseudo_id) AS person_id
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*` AS e
JOIN ids USING (user_pseudo_id)
WHERE e._TABLE_SUFFIX BETWEEN '20201201' AND '20201231';

Browsers per logged-in user

How many devices or browsers each user_id uses. Empty on the sample.

SELECT
  user_id,
  COUNT(DISTINCT user_pseudo_id) AS browsers
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
  AND user_id IS NOT NULL
GROUP BY user_id
ORDER BY browsers DESC
LIMIT 100;

FAQ

What is user_pseudo_id in GA4 BigQuery?

A pseudonymous ID for a browser or app instance, assigned on first visit or first open. On the web it is based on the Analytics cookie, so it changes when cookies are cleared and differs across devices.

Why is user_id NULL in my GA4 export?

GA4 only fills user_id on events where your site or app sent it, usually after login. Events before login, and every event in the public sample, have NULL.

Why does BigQuery show more users than the GA4 interface?

The interface can deduplicate users with Google signals and modeling, and reports active users by default. Google exports only device-ID based data, so distinct user_pseudo_id counts are usually higher.

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.