GA4 BigQuery Export: Raw Event Schema & Flattening Unnested Event Parameters
Overview & Learning Objectives
While the GA4 user interface is great for quick charts, serious enterprise product analysts write SQL queries directly against raw GA4 data stored in Google BigQuery. GA4 exports every single raw event into BigQuery every day for free! But there is a twist: because every event has dozens of custom parameters, BigQuery stores them inside a special nested array called `event_params`. In this lesson, you will master the SQL `UNNEST()` function to flatten nested parameters and calculate complex analytics metrics.
- Understand why GA4 stores event parameters as repeated nested records (`RECORD REPEATED`) in BigQuery.
- Write SQL queries using `CROSS JOIN UNNEST(event_params)` to extract parameter keys and values.
- Calculate custom session metrics, un-sampled user conversion rates, and multi-day retention cohorts in BigQuery.
Real-World Example: Unpacking Russian Matryoshka Nesting Dolls in SQL
- Scenario: Opening nested Russian Matryoshka dolls to inspect the smallest hidden figurine.
- BigQuery Export: Raw event streams store custom attributes inside repeated `event_params` record arrays.
- SQL Technique: Use `CROSS JOIN UNNEST(event_params)` to flatten nested keys into clean, queryable SQL columns.
Visual Infographic: How BigQuery Unnests Event Parameters
SQL INFOGRAPHICEvent: `purchase` -> `event_params: [{key: "value", int_value: 499}, {key: "city", string_value: "Delhi"}]`
`FROM events_*, UNNEST(event_params) AS param`
Row 1: Key = "value", Int = 499 | Row 2: Key = "city", String = "Delhi"
Industry Standard & Framework
Standard: Google Cloud BigQuery GA4 Export Schema Specifications.
Real-World Business Application: Nykaa E-Commerce BigQuery Raw Event Schema Audit
Nykaa data team queries raw BigQuery GA4 event tables to calculate true gross merchandise value (GMV) by beauty brand.
| BigQuery Field | Data Type | Description | Sample Value |
|---|---|---|---|
| `event_date` | STRING | Date event occurred in YYYYMMDD format | `"20261113"` |
| `event_timestamp` | INTEGER | Timestamp in microseconds (UTC) | `1763032512391000` |
| `event_name` | STRING | Name of the tracked action | `"purchase"` |
| `event_params` | RECORD REPEATED | Nested array of parameter key-value pairs | `[key: "value", int_value: 1299]` |
| `user_pseudo_id` | STRING | Anonymous client ID stored in browser cookie | `"8823192.17630321"` |
Step-by-Step UI Tutorial & Visual Workflow Guide
Below is the practical, non-technical walkthrough showing how Product Analysts design, review, and execute this capability inside real-world tools like Mixpanel, Google Analytics 4, BigQuery, and Google Tag Manager.
Step-by-Step Execution Workflow
EXECUTION PHASESIn GA4 Admin -> Product Links -> BigQuery Links -> Enable Daily and Streaming Exports.
Open BigQuery Console -> Find dataset `analytics_XXXXXXXXX` with table `events_YYYYMMDD`.
Write SQL query using scalar subqueries or `CROSS JOIN UNNEST(event_params)` to pull target metrics.
Set up BigQuery scheduled query to materialize daily product summary tables for Looker Studio dashboards.
Step-by-Step UI Tutorial: Linking GA4 to BigQuery & Running Your First Query
In GA4 Admin -> Scroll to "Product links" -> Click "BigQuery links" -> Click "Link".
Select your active GCP project -> Choose data location (e.g., `asia-south1` for India) -> Check "Daily" export.
Navigate to `console.cloud.google.com/bigquery` -> Pin your analytics project.
Run query: `SELECT event_name, (SELECT value.string_value FROM UNNEST(event_params) WHERE key = "page_title") AS title FROM `analytics_XXXX.events_*` LIMIT 20;`
Essential GA4 BigQuery SQL Patterns Cheat Sheet
SQL QUERY BLUEPRINT| goal | sql Pattern | explanation |
|---|---|---|
| Extract String Parameter | `(SELECT value.string_value FROM UNNEST(event_params) WHERE key = "category")` | Pulls text values like category or page path |
| Extract Numeric Parameter | `(SELECT COALESCE(value.int_value, value.float_value, value.double_value) FROM UNNEST(event_params) WHERE key = "value")` | Safely extracts integers or decimal currency amounts |
| Convert Microsecond Timestamp | `TIMESTAMP_MICROS(event_timestamp)` | Converts raw integer into readable UTC timestamp |
Implementation Guidelines for Product Analysts
- Always query wildcard date shards `events_202611*` with date filters (`_TABLE_SUFFIX BETWEEN "1101" AND "1115"`) to avoid scanning the entire multi-year database.
- Use scalar subqueries `(SELECT value.string_value FROM UNNEST(...) WHERE key = "...")` instead of multiple CROSS JOINs to keep query execution fast and cost-effective.
- Remember that `user_pseudo_id` is the browser client ID, while `user_id` is only populated when users log in.
Practical Hands-On Exercises
- Write a BigQuery SQL query to count total `purchase` events and sum total revenue for yesterday's date shard.
- Explain why running `SELECT *` without date filters on a high-traffic GA4 BigQuery table can cost thousands of rupees.