Unpacking event parameters

Most of what you want to know about a GA4 event, such as its page or campaign, is stored in its parameters. You need to read them before most other GA4 queries work.

How it works

Each GA4 event is one row with an array of key and value records for its parameters. UNNEST turns those elements into rows. A correlated scalar subquery pulls out one value and keeps one row per event.

Common mistake

A cross join with UNNEST multiplies each event by its number of parameters. A scalar helper keeps one row per event. It returns NULL when the key is missing or has no string_value. LIMIT 1 picks an arbitrary value when a key repeats, so handle duplicates deliberately if they matter.

Worked example

WITH events AS (
  SELECT 101 AS event_id, [
    STRUCT('page_location' AS key, STRUCT('/docs' AS string_value) AS value),
    STRUCT('campaign' AS key, STRUCT('autumn' AS string_value) AS value)
  ] AS event_params
)
SELECT event_id,
  (SELECT p.value.string_value FROM UNNEST(event_params) AS p WHERE p.key = 'page_location') AS page
FROM events

The raw event has two key and value structs inside event_params.

The correlated UNNEST subquery keeps one row for the event and pulls /docs out of the page_location element.

All BigQuery lessons