GA4 in BigQuery · Working with the export
GA4 BigQuery export schema: tables, nested fields and value types
The GA4 export writes one table per day (events_YYYYMMDD) and, with streaming on, events_intraday_YYYYMMDD. Each row is one event. Parameters, user properties and items are repeated records you read with UNNEST. This query lists every event parameter and which value column holds it.
The query
-- Which event parameters exist, and which value column holds them
SELECT
ep.key,
COUNT(*) AS events,
COUNTIF(ep.value.string_value IS NOT NULL) AS string_values,
COUNTIF(ep.value.int_value IS NOT NULL) AS int_values,
COUNTIF(ep.value.double_value IS NOT NULL) AS double_values,
COUNTIF(ep.value.float_value IS NOT NULL) AS float_values
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`,
UNNEST(event_params) AS ep
GROUP BY ep.key
ORDER BY events DESC, ep.key;Result on the sample
| key | events | string_values | int_values | double_values | float_values |
|---|---|---|---|---|---|
| ga_session_id | 4295584 | 0 | 4295584 | 0 | 0 |
| ga_session_number | 4295584 | 0 | 4295584 | 0 | 0 |
| page_location | 4295584 | 4295584 | 0 | 0 | 0 |
| page_title | 4276104 | 4274636 | 0 | 0 | 0 |
| engaged_session_event | 4116237 | 0 | 4116237 | 0 | 0 |
| session_engaged | 3996312 | 3682921 | 313391 | 0 | 0 |
| debug_mode | 3682991 | 0 | 3682991 | 0 | 0 |
| page_referrer | 3206512 | 1127778 | 0 | 0 | 0 |
| all_data | 2828174 | 0 | 0 | 0 | 0 |
| clean_event | 2828040 | 2828040 | 0 | 0 | 0 |
How it works
A GA4 property linked to BigQuery exports into a dataset named analytics_<property_id>. The daily export writes one table per day, events_YYYYMMDD. These are date-sharded tables, not one partitioned table, so you query a date range through the wildcard events_* and limit it with the _TABLE_SUFFIX pseudo-column. The streaming export adds events_intraday_YYYYMMDD, filled continuously during the day and deleted once that day's daily table is complete (see intraday tables).
Every row is one event. Flat columns hold the basics: event_date (STRING, YYYYMMDD), event_timestamp (INT64, microseconds since the epoch in UTC), event_name, user_pseudo_id and user_id. STRUCT columns group related fields, and you read them with a dot: device.category, geo.country, traffic_source.source, ecommerce.purchase_revenue_in_usd, privacy_info.analytics_storage. Three columns are repeated records (arrays of structs): event_params, user_properties and items. To read them you need UNNEST, usually inside a scalar subquery (see unnest event_params).
Each parameter's value is a STRUCT with four slots: string_value, int_value, double_value and float_value. Only one is filled per row, and which one depends on the type the tag sent. The result shows why that matters: in this sample session_engaged arrives as a string on 3,682,921 events and as an integer on 313,391. A query that reads only string_value silently drops the integer rows. Run this inventory once on your own export before you write reports against it.
Current exports have more columns than this sample, which dates from 2020 and 2021. Google's schema now also lists collected_traffic_source (UTM and click IDs collected with each event), session_traffic_source_last_click (the session's last-click campaign, grouped by ad platform), is_active_user, the batch_event_index, batch_page_id and batch_ordering_id ordering fields, and items.item_params. None of these exist in the sample, so the recipes in this cookbook avoid them in runnable SQL and mention them where they would change the answer.
| Column | Meaning |
|---|---|
key | Name of the event parameter, such as page_location or ga_session_id. |
events | Events that carry this parameter. |
string_values / int_values / double_values / float_values | How many of those events store the value in each slot. A parameter with counts in two slots needs COALESCE across both. |
Notes and cost
- Measured on the sample: 92 daily tables from
events_20201101toevents_20210131, all with the same schema, 4,295,584 events and 3,583,657,854 bytes in total. No intraday tables, no partitioning. The busiest day is 2020-12-08 (92,199 events), the quietest 2020-12-25 (21,355). - What the columns cost: of the 3.34 GiB the sample holds,
event_paramsis 1.31 GiB anditemsis 946.5 MiB.user_pseudo_idis 84.7 MiB,event_name53.4 MiB. BigQuery bills the columns you reference, souser_pseudo_idplusevent_nametogether cost about 4% of aSELECT *. - This inventory reads
event_params.keyand all four value slots for the whole sample: 1.31 GiB. The same query on one day costs 23.1 MiB (first variation), and one day is enough to see which slot each parameter uses. event_dateis the event's date in the property's reporting time zone;event_timestampis UTC. Convert withTIMESTAMP_MICROS(event_timestamp)and a time zone before comparing hours with the GA4 interface.- Google keeps writing late events into a daily table for up to three days after its date, so yesterday's table can still grow. Reports that must match should use days older than 72 hours.
- In the sample,
user_idis NULL on every event anduser_propertiesis effectively empty. Some parameters (all_data,gclid,dclid) exist only as keys with every value slot NULL: that is obfuscation, not something to expect in your own export.
Variations
Same inventory on one day
One daily table holds the same keys and types and scans a fraction of the bytes.
SELECT
ep.key,
COUNT(*) AS events,
COUNTIF(ep.value.string_value IS NOT NULL) AS string_values,
COUNTIF(ep.value.int_value IS NOT NULL) AS int_values,
COUNTIF(ep.value.double_value IS NOT NULL) AS double_values
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`,
UNNEST(event_params) AS ep
WHERE _TABLE_SUFFIX = '20201201'
GROUP BY ep.key
ORDER BY events DESC;List every column and nested field path
INFORMATION_SCHEMA.COLUMN_FIELD_PATHS returns one row per field, nested ones included, with its type. It reads metadata, not the events: the dry run reports the 10 MB minimum.
SELECT
field_path,
data_type
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS`
WHERE table_name = 'events_20210131';Look at a few raw events as JSON
TO_JSON_STRING shows the nested layout of real rows. Filter by _TABLE_SUFFIX, because LIMIT alone does not reduce the bytes scanned.
SELECT
event_name,
TO_JSON_STRING(event_params) AS event_params,
TO_JSON_STRING(items) AS items
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX = '20201201'
AND event_name = 'purchase'
LIMIT 3;FAQ
Is the GA4 BigQuery export a partitioned table?
No. It writes one table per day (events_YYYYMMDD), which BigQuery calls date-sharded tables. You select days with _TABLE_SUFFIX; a filter on event_date does not skip any table. If you want partitioning, copy the data into your own partitioned table (see daily summary table).
Why does each event parameter have four value columns?
Parameters can be strings, integers or decimals, and a repeated record needs one fixed schema. GA4 stores each value in the slot that matches the type sent: string_value, int_value or double_value. Google's schema describes float_value as not currently in use.
Where are session source and medium in the export?
Newer exports have session_traffic_source_last_click for the session's last-click campaign and collected_traffic_source for UTM values on each event. Older exports, including this sample, only have source, medium and campaign event parameters and the first-touch traffic_source record (see session source / medium).
What does the GA4 sample dataset contain?
Obfuscated export data from the Google Merchandise Store web stream, 2020-11-01 to 2021-01-31. Google notes that some fields hold placeholders such as <Other>, NULL or empty strings, and that its internal consistency is limited, so it does not match the GA4 demo account.
Related
All GA4 export queries · BigQuery cost queries · The GA4 sample dataset
