GA4 BigQuery Export — How to Analyze Raw Session Data
Contents
Have you ever looked at a GA4 report and seen a small shield icon saying "60% of data"? That's sampling — GA4 processes only a portion of your data and extrapolates the rest. For a high-traffic store this is a real problem. BigQuery export is the way out — and much more.
What is GA4 BigQuery export?
Google Analytics 4 offers a free export of raw data to Google BigQuery. Instead of viewing aggregated reports in the GA4 interface, you get every single event — every page view, click, purchase — as a SQL table ready for any analysis.
Three reasons it matters:
- Zero sampling — BigQuery contains 100% of your data
- Full query freedom — SQL without GA4's interface limitations
- Join with other sources — combine GA4 with CRM data, orders, ad spend
How much does it cost?
Great news: the export from GA4 to BigQuery is free.
You only pay for BigQuery usage:
- Storage: first 10 GB/month free, then ~$0.02/GB
- Queries (on-demand): first 1 TB/month free, then $5 per TB of data scanned
With properly written queries (date filtering, selecting only needed columns) a typical e-commerce store pays < $5/month.
How to connect BigQuery to GA4
- Go to GA4 → click the gear icon bottom left → Settings
- Under "Product Links" find BigQuery Links → click "Link"
- Select a BigQuery project (or create one at console.cloud.google.com)
- Select region — for European data: EU or europe-west1
- Click "Submit"
Data starts flowing the next day. Important: the export is not retroactive — historical data (before the connection) is not recoverable.
Data structure explained
Each day is a separate table named events_YYYYMMDD. One row = one event.
Key columns:
event_name— what happened (page_view,purchase,add_to_cart)user_pseudo_id— anonymous user identifier (no PII)event_timestamp— time in microseconds (divide by 1,000,000 → seconds)event_params— ARRAY<STRUCT> with event parameterstraffic_source— STRUCT withsource,medium,campaign
Why is event_params so confusing?
The most common frustration for beginners. In a normal SQL table you have columns. In GA4 BigQuery you have event_params — a nested array of key-value pairs.
Instead of a page_url column, you have:
event_params: [
{ key: "page_location", value: { string_value: "https://store.com/product/123" } },
{ key: "ga_session_id", value: { int_value: 9876543210 } }
]To extract a specific parameter, use UNNEST with a subquery:
SELECT
event_date,
event_name,
user_pseudo_id,
(SELECT value.string_value
FROM UNNEST(event_params)
WHERE key = 'page_location') AS page_url,
(SELECT value.int_value
FROM UNNEST(event_params)
WHERE key = 'ga_session_id') AS session_id
FROM `project.dataset.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
AND event_name = 'page_view'The value type (string_value, int_value, float_value) depends on the parameter. If the query returns NULL — check that you're using the correct type.
Building a sessions table
GA4 doesn't export sessions — only events. A session = all events with the same ga_session_id for a given user. You build it with a GROUP BY:
WITH events AS (
SELECT
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params)
WHERE key = 'ga_session_id') AS session_id,
event_name,
event_timestamp,
traffic_source.source AS source,
traffic_source.medium AS medium
FROM `project.dataset.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
)
SELECT
user_pseudo_id,
session_id,
source,
medium,
TIMESTAMP_MICROS(MIN(event_timestamp)) AS session_start,
TIMESTAMP_MICROS(MAX(event_timestamp)) AS session_end,
COUNT(*) AS events_count,
COUNTIF(event_name = 'purchase') AS conversions
FROM events
WHERE session_id IS NOT NULL
GROUP BY user_pseudo_id, session_id, source, mediumCost optimization — 4 rules
- Always use `_TABLE_SUFFIX BETWEEN` — without it BigQuery scans all history
- List columns explicitly — avoid
SELECT *, especially withevent_params - Materialize intermediate results — use
CREATE TABLEinstead of repeating expensive CTEs - Estimate before running — BigQuery shows the bytes to be scanned before execution
TL;DR
- BigQuery export = all GA4 events, zero sampling, SQL access
- Setup: GA4 → Settings → Product Links → BigQuery Links (~5 minutes, data from next day)
- Export cost: free; queries: < $5/month with proper date filtering
event_params= nested array → extract viaUNNEST + WHERE key = '...'user_pseudo_id= anonymous ID per device/browser- Build sessions yourself by grouping on
user_pseudo_idandga_session_id - Always filter
_TABLE_SUFFIX— it's the foundation of cost control
Seeing the same issue in your GA4?
I'll review your setup as part of a GA4 audit. The first call is free.
Book a consultationMore articles about data analytics:
Back to blog