In Google Analytics 4 (GA4), events and their parameters are stored in a structured but nested format in BigQuery. If you want to get all item-related events and their parameters, you typically need to query the events_* tables in your GA4 BigQuery dataset.
🎯 Goal:
Get item-related events (like view_item, select_item, add_to_cart, etc.) and extract all associated parameters, including those related to items.
✅ Sample Query: Get Item Events and Parameters
WITH item_events AS (
SELECT
event_name,
event_timestamp,
event_date,
event_params,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'item_id') AS item_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'item_name') AS item_name,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'item_category') AS item_category,
(SELECT value.float_value FROM UNNEST(event_params) WHERE key = 'price') AS price,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'quantity') AS quantity,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'currency') AS currency,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'item_brand') AS item_brand,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'item_variant') AS item_variant,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'item_list_name') AS item_list_name,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'index') AS index_position
FROM
`your-project-id.your_dataset.events_*`
WHERE
event_name IN ('view_item', 'select_item', 'add_to_cart', 'remove_from_cart', 'begin_checkout', 'view_cart')
)
SELECT * FROM item_events
WHERE item_id IS NOT NULL OR item_name IS NOT NULL;
🔍 Explanation:
event_name IN (...): Filters for common item-related events.
UNNEST(event_params): Flattens the array of parameters so we can extract individual keys.
- Each
SELECT subquery extracts a specific parameter by its key.
- You can add more fields as needed (e.g.,
coupon, location_id, etc.).
📁 Notes:
- Replace
your-project-id.your_dataset with your actual project and dataset names.
- Table name pattern:
events_* matches all partitioned daily tables.
- If you're only interested in a single day, use
_YYYYMMDD suffix (e.g., _20250405).
- Use
value.string_value, value.int_value, or value.float_value depending on the expected type of the parameter.
🧠 Tip: List All Available Event Names
To see what events exist in your dataset:
SELECT DISTINCT event_name
FROM `your-project-id.your_dataset.events_*`
ORDER BY event_name;
Let me know if you'd like to pivot this into a flattened table or export to a new table!