GA4 + BigQuery: Customer-Intelligence Pipeline Patterns
Jun 2026 · Data EngineeringThe Google Analytics 4 to BigQuery export is the most useful asset in a modern analytics stack, and one of the most underused. The reporting screens inside GA4 are built for aggregate dashboards. They're sampled, limited in cardinality and locked to a fixed set of dimensions. The BigQuery export gives you every raw event, unsampled, as data you own and can join to anything. Customer intelligence needs exactly that.
This is a hands-on guide to the patterns I use when I build customer-intelligence pipelines on GA4 + BigQuery for enterprise clients. It covers the parts of the export schema that trip people up, the staging models that turn raw events into something you can query, and the analytical marts the pipeline exists to produce: sessionization, identity stitching, RFM, lifetime value and cohorts. No client data appears here. The patterns are general and the SQL is illustrative.
Quick answer: Turn on the native GA4 BigQuery export, then build three layers on top of the raw events_* tables: a staging layer that flattens nested event parameters and rebuilds sessions, an identity layer that stitches user_pseudo_id to a stable user_id, and a marts layer that produces per-customer RFM, LTV, and cohort tables. Schedule it with dbt or scheduled queries and you have customer intelligence the GA4 UI can't give you.
Why GA4 + BigQuery for Customer Intelligence
GA4 was rebuilt around an event model. Every interaction is an event with parameters, instead of the session-and-hit model of Universal Analytics. That event model is awkward in the reporting UI but ideal in a warehouse. Three things make the BigQuery export the right foundation:
- You get raw, unsampled rows. The export delivers every event, with no sampling and no cardinality collapse. Customer intelligence is built on per-user analysis, and you can't do that on sampled aggregates.
- Once events live in BigQuery, you can join them to everything: CRM records, order tables, product catalogs and support tickets. Customer intelligence starts when you put behavioral data next to transactional data.
- You own the modeling. Sessions, identity, segments and metrics are defined in SQL you control and can audit, instead of in a vendor's hidden reporting logic. When someone questions a number, you can trace it to the row.
The export itself is free for standard properties, including both the daily batch table and the streaming intraday table. Once the data lands, you only pay normal BigQuery storage and query costs, and partition pruning keeps those low if you model carefully.
The Pipeline in Four Layers
A layered design holds up best over time. Each layer has one job and feeds the next. Don't write one giant query against the raw export. It becomes impossible to maintain the first time the schema surprises you.
1. Raw / source
The untouched GA4 export: events_YYYYMMDD daily tables plus events_intraday_*. Never edited. This is your replayable source of truth.
2. Staging
Flatten event_params and user_properties, cast timestamps, rebuild sessions. One clean, typed row-per-event model the rest of the pipeline can trust.
3. Identity
Resolve devices to people. Map every user_pseudo_id to a stable customer key, stitching in user_id wherever a login event provides one.
4. Marts
The analytical outputs: sessions, funnels, RFM segments, lifetime value and cohort retention. All of them are keyed on the resolved customer and ready for BI and activation.
GA4 Export Schema: The Parts That Matter
The export lands in a dataset named analytics_<property_id>, with one partitioned table per day (events_YYYYMMDD) and a streaming table (events_intraday_YYYYMMDD) when streaming export is enabled. Each row is a single event. The fields that drive every downstream model:
| Field | Type | What it is |
|---|---|---|
event_name |
STRING | The event: page_view, session_start, purchase, and your custom events. |
event_timestamp |
INT64 | Event time in microseconds since the Unix epoch. Divide by 1e6 before casting to a timestamp. |
event_params |
RECORD, REPEATED | Key/value array. The value sits in one of string_value, int_value, float_value, double_value. Holds ga_session_id, page_location, and more. |
user_pseudo_id |
STRING | Device/client identifier from the GA client_id cookie. Always present; resets on cookie clear or device switch. |
user_id |
STRING | The stable identifier you set on login. Present only when your site/app assigns it. The anchor for identity stitching. |
user_properties |
RECORD, REPEATED | Sticky user-scoped attributes (plan tier, lifecycle stage). Same nested key/value shape as event_params. |
items |
RECORD, REPEATED | Ecommerce line items on purchase/cart events: item id, name, price, quantity. The source of monetary value. |
traffic_source / collected_traffic_source |
RECORD | Acquisition attribution: source, medium, campaign. First-touch vs. event-level depending on the field. |
Two facts cause the most confusion: timestamps are in microseconds, and there is no session table. GA4 doesn't store sessions as rows, so you rebuild them from events. The staging layer below handles both.
Staging: Flatten Events and Rebuild Sessions
Because event_params is a repeated record, you pull a single parameter by unnesting it and selecting the typed value. You'll use this subquery pattern all over the pipeline:
SELECT
event_date,
TIMESTAMP_MICROS(event_timestamp) AS event_ts,
event_name,
user_pseudo_id,
user_id,
-- pull the session id out of the nested params
(SELECT value.int_value FROM UNNEST(event_params)
WHERE key = 'ga_session_id') AS ga_session_id,
(SELECT value.string_value FROM UNNEST(event_params)
WHERE key = 'page_location') AS page_location,
-- a globally-unique session key: device + session number
CONCAT(
user_pseudo_id, '.',
CAST((SELECT value.int_value FROM UNNEST(event_params)
WHERE key = 'ga_session_id') AS STRING)
) AS session_key
FROM `project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20260101' AND '20260131'
Two habits keep this layer solid. The first is about cost:
_TABLE_SUFFIX (the date sharded into the table name) so BigQuery only reads the days you need. Querying events_* without a suffix filter scans your entire history, and it's the number-one cause of surprise bills.
The second is the session key: user_pseudo_id concatenated with ga_session_id. GA4 itself uses it internally to count sessions, and it's globally unique. Group by it to rebuild sessions. The first and last event timestamps give you session start, end and duration. The count of page_view events gives you depth. A purchase event marks a converting session. That one sessions model feeds funnels, engagement metrics and attribution downstream.
Identity Resolution: Devices to People
This layer is what separates real customer intelligence from page-view reporting. user_pseudo_id answers "which browser?" Customer intelligence needs "which person?" The mapping is rarely one-to-one. One customer shows up as many pseudo-ids across devices and cookie resets, and one shared device can have several people on it.
To stitch them, take every user_pseudo_id that ever appears with a known user_id (because the user logged in during at least one event), and copy that user_id to all of that device's events. Build a crosswalk table:
-- one row per device, resolved to a stable customer key where known
SELECT
user_pseudo_id,
-- the most recent non-null user_id seen on this device
ARRAY_AGG(user_id IGNORE NULLS ORDER BY event_timestamp DESC LIMIT 1)[SAFE_OFFSET(0)]
AS resolved_user_id
FROM `project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20260101' AND '20260131'
GROUP BY user_pseudo_id
Downstream, the customer key is COALESCE(resolved_user_id, user_pseudo_id). Use the real person when you know it, and fall back to the device when you don't. Every per-customer metric keys on that. Tell stakeholders up front that stitching is an estimate. Anonymous behavior before login only attaches to a person after the fact, and cross-device coverage is only as good as your login rate. Name those limits in the deliverable so nobody assumes the resolution is perfect.
The Marts: What Customer Intelligence Produces
With clean sessions and resolved customers, the analytical marts are simple to write. I build these same four on almost every client project.
RFM Segments
Start hereRecency, Frequency and Monetary value per customer, scored into quintiles. It turns raw purchase events into named segments (champions, loyal, at-risk, lapsed), and it's the fastest way to get from data to action.
Lifetime Value
Revenue lensTotal purchase value per resolved customer, with an optional forward projection. It ties acquisition spend and retention priorities to real revenue instead of proxies.
Cohort Retention
Trend lensGroup customers by first-seen week or month, then track return/purchase rate over subsequent periods. Shows whether product and lifecycle changes move retention.
Funnel / Conversion
Behavior lensOrdered event sequences (view → add-to-cart → checkout → purchase) measured per session and per customer. Shows which step people drop off at.
RFM is the best place to start, because it's cheap to compute and you can act on it right away. From the resolved purchase events:
WITH purchases AS (
SELECT
COALESCE(resolved_user_id, user_pseudo_id) AS customer_key,
TIMESTAMP_MICROS(event_timestamp) AS purchase_ts,
(SELECT value.double_value FROM UNNEST(event_params)
WHERE key = 'value') AS purchase_value
FROM staged_events
WHERE event_name = 'purchase'
)
SELECT
customer_key,
DATE_DIFF(CURRENT_DATE(), DATE(MAX(purchase_ts)), DAY) AS recency_days,
COUNT(*) AS frequency,
SUM(purchase_value) AS monetary
FROM purchases
GROUP BY customer_key
Wrap each of recency, frequency, and monetary in NTILE(5) OVER (...) to score quintiles, then map the score triples to segment names. That one table drives lifecycle email, paid-audience exclusions and win-back campaigns, which is the activation side of customer intelligence.
Scheduling and Orchestration
The export refreshes daily (intraday if streaming is on), so the pipeline should refresh on the same schedule. Here are the common approaches:
| Approach | Best for | Trade-off |
|---|---|---|
| dbt | Teams wanting version-controlled models, tests, lineage, and documentation | More setup; needs a runner (dbt Cloud, Cloud Run, or scheduled CI) |
| BigQuery scheduled queries | Small pipelines, fast start, no extra tooling | No tests or lineage; logic lives in the console, harder to review |
| Incremental tables | Large histories where full refresh is wasteful | Cheapest at scale; only process yesterday's partition each run |
For anything beyond a couple of models, dbt with incremental materializations is the pattern that scales. Each run processes only the newest daily partition, the models are tested, and the lineage from raw export to RFM mart is documented and reviewable. That pays off the first time a stakeholder questions a number, because "here's the model and the test that guards it" is a much better answer than "the dashboard says so."
Common Dead Ends to Avoid
- Never query
events_*without a date filter. The wildcard scans every day you've ever exported. Always constrain_TABLE_SUFFIX, because that's the difference between cents and hundreds of dollars per query. - Don't treat
user_pseudo_idas a person. It's a device, so customer counts built on it overstate unique users and understate loyalty. Build the identity layer before any per-customer metric. - Read the right value field. Each
event_paramsentry stores its value in exactly one typed field. If you pullint_valuefor a string param, you'll get nulls. Match the field to the parameter. - Don't try to match the GA4 UI to the decimal. The export and the interface process data differently (late hits, identity, modeling), so the numbers will be close but not identical. Chasing an exact match wastes days. Document the expected variance instead.
- Don't skip the privacy boundary. Raw event data is sensitive. Decide up front what you keep, what you hash and who can query it, especially in regulated industries. Build it into the staging layer from the start.
Frequently Asked Questions
Building a customer-intelligence stack?
I run a free community for people building real data and AI pipelines: warehouse modeling, analytics, and AI-augmented workflows. There's no course and no paywall. It's people who build and ship real work.
Join the free AI community →Related reading: AI in Enterprise Data Work — What Actually Ships: the patterns that deliver value versus the ones that stall. AI as an Operations Layer: scheduled analysis and DataOps opportunity discovery. LLMs Explained: why private, first-party data is where enterprise AI gets interesting. For the hardware side of running AI locally, see Blendlogic Tech.
Get the build notes
My AI experiments: what worked, what didn’t, and how I set them up. Sent to your inbox.
No spam, unsubscribe anytime · Privacy
You're in. Check your inbox for a welcome note.