Mastering Product Analytics with Mixpanel & GA4Lesson 8 of 32
Lesson 8 of 32

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.
Example

Real-World Example: Unpacking Russian Matryoshka Nesting Dolls in SQL

PRACTICAL CONTEXT
  • 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.
Corporate / Tech Term Everyday / Practical Metaphor Operational Meaning
Nested Array (`event_params`) The Russian Nesting Doll / Gift Box A single column holding multiple key-value pairs inside.
`UNNEST()` Function in SQL Scissors opening the gift box Unpacking the nested array into regular flat rows.
BigQuery Raw Export The Full Security Video Recording 100% un-sampled raw log of every single click in your company history.
Core Principle: Never rely solely on the GA4 web UI for multi-million user products; always run BigQuery SQL queries to bypass sampling and thresholding limits!

Visual Infographic: How BigQuery Unnests Event Parameters

SQL INFOGRAPHIC
Stage 1
1. Nested Row in BigQuery

Event: `purchase` -> `event_params: [{key: "value", int_value: 499}, {key: "city", string_value: "Delhi"}]`

Stage 2
2. Apply CROSS JOIN UNNEST

`FROM events_*, UNNEST(event_params) AS param`

Stage 3
3. Flat Result Table

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 FieldData TypeDescriptionSample Value
`event_date`STRINGDate event occurred in YYYYMMDD format`"20261113"`
`event_timestamp`INTEGERTimestamp in microseconds (UTC)`1763032512391000`
`event_name`STRINGName of the tracked action`"purchase"`
`event_params`RECORD REPEATEDNested array of parameter key-value pairs`[key: "value", int_value: 1299]`
`user_pseudo_id`STRINGAnonymous 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 PHASES
1 Product Analyst & Cloud Admin
Link GA4 to BigQuery

In GA4 Admin -> Product Links -> BigQuery Links -> Enable Daily and Streaming Exports.

2 Product Analyst
Locate Dataset in Google Cloud Console

Open BigQuery Console -> Find dataset `analytics_XXXXXXXXX` with table `events_YYYYMMDD`.

3 Product Analyst
Author Unnest Query

Write SQL query using scalar subqueries or `CROSS JOIN UNNEST(event_params)` to pull target metrics.

4 Data Engineer / Analyst
Schedule Recurring Queries

Set up BigQuery scheduled query to materialize daily product summary tables for Looker Studio dashboards.

Google Cloud BigQuery SQL Editor

Step-by-Step UI Tutorial: Linking GA4 to BigQuery & Running Your First Query

Step 1
Step 1: Open GA4 BigQuery Linking

In GA4 Admin -> Scroll to "Product links" -> Click "BigQuery links" -> Click "Link".

Step 2
Step 2: Choose Google Cloud Project

Select your active GCP project -> Choose data location (e.g., `asia-south1` for India) -> Check "Daily" export.

Step 3
Step 3: Open BigQuery SQL Studio

Navigate to `console.cloud.google.com/bigquery` -> Pin your analytics project.

Step 4
Step 4: Execute Flat Unnest Query

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
goalsql Patternexplanation
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

  1. Write a BigQuery SQL query to count total `purchase` events and sum total revenue for yesterday's date shard.
  2. Explain why running `SELECT *` without date filters on a high-traffic GA4 BigQuery table can cost thousands of rupees.