Sub topic 13
Seeing the GA4 Data Model in the BigQuery Export
Prerequisites
This chapter assumes that you understand basic GA4 events and can read simple SQL. You should also know that a GA4 property can receive data from web or app data streams.
The BigQuery export gives you the event-level data behind many GA4 measurements. It does not export one row per user or one row per session. Each row represents one event. Users and sessions are calculated by grouping event rows.
The export’s basic structure
GA4 creates date-sharded tables with names such as:
events_20240131for completed daily dataevents_intraday_20240131for data from the current day
The exact fields depend on the stream type and the enabled export options, but the main event record usually includes these fields:
| Field | Meaning |
|---|---|
| `event_date` | The date assigned to the event in the property’s reporting time zone |
| `event_timestamp` | The event time in microseconds since the Unix epoch |
| `event_name` | The name of the event, such as `page_view` |
| `user_pseudo_id` | An anonymous identifier for a browser or app instance |
| `user_id` | An optional identifier that your business assigns to a signed-in user |
| `event_params` | A repeated collection of parameters attached to the event |
| `user_properties` | A repeated collection describing the user |
| `items` | A repeated collection of products for ecommerce events |
Repeated collections are BigQuery records that can contain multiple values. To read one parameter, use UNNEST.
For example, this expression extracts the session ID from event_params:
(
SELECT value.int_value
FROM UNNEST(event_params)
WHERE key = 'ga_session_id'
)The parameter value can have different typed fields, including string_value, int_value, double_value, and float_value. Select the field that matches the value’s stored type.
Relating events, users, and sessions
The following query counts event rows, pseudo-identified users, and sessions for each day:
SELECT
event_date,
COUNT(*) AS event_count,
COUNT(DISTINCT user_pseudo_id) AS users,
COUNT(DISTINCT CONCAT(
user_pseudo_id,
'.',
CAST((
SELECT value.int_value
FROM UNNEST(event_params)
WHERE key = 'ga_session_id'
) AS STRING)
)) AS sessions
FROM `my-project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
GROUP BY event_date
ORDER BY event_date;The session key combines user_pseudo_id and ga_session_id. The session ID alone is not globally unique. Two different users can have the same numeric session ID.
This query is useful for learning the data model, but production queries should handle missing identifiers. For example, some events may not contain a session parameter, and a missing value can make a session count inaccurate. Filter or label those rows according to your reporting goal.
Export data is not always identical to reports
The BigQuery export is rawer than the standard GA4 interface. The interface may apply reporting logic, identity settings, thresholds, modeled data, or attribution rules that are not reproduced by a simple COUNT(DISTINCT user_pseudo_id).
The export also does not automatically create a permanent user row or session row. You derive those entities from event fields. This design lets you choose the grouping logic, but it also makes mistakes possible.
Exercise
Why should a session query combine userpseudoid with gasessionid instead of counting gasessionid alone?
Show answer
The numeric session ID is not globally unique. Combining it with the userpseudoid creates a session key scoped to the user.