What are _ga4 cookies? _ga versus _gid and its bigquery export mapping; ga4 cookies explained

GA4 uses first-party cookies set by Google Analytics, and the raw event data is exported into Google BigQuery.

Below is the practical mapping you need for analysis.


1. _ga Cookie → user_pseudo_id

Example: _ga=GA1.1.123456789.1699999999

The important part is the Client ID:

123456789.1699999999

In BigQuery

It maps to: user_pseudo_id

This is GA4’s device-level identifier

Equivalent to the Client ID

Used to identify unique users (per browser/device)


Example Query

SELECT
  user_pseudo_id,
  COUNT(*) as events
FROM `project.dataset.events_*`
GROUP BY user_pseudo_id

That’s essentially grouping by _ga client ID.


2. _ga_<measurement-id> Cookie → Session Info

GA4 also sets cookies like:

_ga_ABC123XYZ

This stores session-related info including:

  • session_id
  • session_number

In BigQuery, these map to:

Cookie ConceptBigQuery Field
Session IDga_session_id (inside event_params)
Session Numberga_session_number (inside event_params)

Extracting Session ID

SELECT
  user_pseudo_id,
  (SELECT value.int_value
   FROM UNNEST(event_params)
   WHERE key = 'ga_session_id') AS session_id
FROM `project.dataset.events_*`

This equals the session stored in the _ga_<measurement-id> cookie.


3. _gid Cookie → NOT Directly Exported in GA4

_gid is used for short-term user differentiation (24 hours).

Important:

It does NOT have a dedicated field in BigQuery
It is not exported directly

Instead:

  • Its logic is absorbed into sessionization
  • GA4 event processing handles session grouping internally

Full Identity Mapping in GA4 + BigQuery

Identity LayerCookieBigQuery FieldNotes
Device/User_gauser_pseudo_idMain user identifier
Session_ga_<measurement-id>ga_session_idSession grouping
Logged-in Usernone (unless set)user_idOnly if you pass/implement user_id

Important Real-World Notes

1. Consent Mode Impact

If consent is denied:

  • _ga may not persist
  • user_pseudo_id may reset
  • BigQuery will show more fragmented users

2. Cross-Device Reality

user_pseudo_id ≠ real user
It’s device/browser specific.

If you implement:

user_id

Then you can stitch users across devices.


3. Rebuilding Sessions in BigQuery

To truly match GA4 UI sessions:

You need:

CONCAT(user_pseudo_id, ga_session_id)

That equals one session.


Exact Matching Formula

Unique Users (GA4 UI equivalent)

COUNT(DISTINCT user_pseudo_id)

Sessions (GA4 UI equivalent)

COUNT(DISTINCT CONCAT(
  user_pseudo_id,
  (SELECT value.int_value
   FROM UNNEST(event_params)
   WHERE key = 'ga_session_id')
))


Architecture Flow

Browser
_ga cookie (client id)
→ GA4 collects event
→ user_pseudo_id generated
→ Event exported
→ BigQuery stores raw event rows



Discover more from

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from

Subscribe now to keep reading and get access to the full archive.

Continue reading