GA4 Analytics Pipeline: Event Taxonomy & dbt Modeling
A deep dive into designing event taxonomies, building 3-layer dbt models, and implementing funnel & retention SQL patterns for GA4 data in BigQuery.
GA4 Analytics Pipeline
Event tracking & measurement planning Instrumentation
Before any analysis, someone has to decide what gets tracked. A measurement plan answers: what business questions do we have, and what events need to fire to answer them?
In GA4, an "event" is any action a user takes: page_view, scroll, button_click, purchase. The key skill is designing the taxonomy, a consistent naming convention so events make sense months later and across teams.
Good taxonomy
- add_to_cart (not AddCart)
- checkout_started
- purchase_completed
- Consistent: verb_noun pattern
Bad taxonomy
- click1, click2, click3
- btn_checkout_v2_new
- Mixed naming styles
- No documentation
When measurement planning matters most
- Launching a new product or feature
- Redesigning a funnel or checkout flow
- Before any A/B test
- Any time a new team inherits analytics data
dbt and data modeling Analytics Engineering
Raw GA4 data in BigQuery is a mess: one row per event, with everything crammed into nested JSON fields. dbt is a tool that lets you write SQL to transform raw data into clean, analysis-ready tables. Think of it as version control for SQL transformations.
The three-layer pattern we used:
-- Layer 1: Staging (stg_events) -- Just rename and cast. No logic. select event_timestamp as event_time, user_pseudo_id as user_id, event_name from raw_ga4_events -- Layer 2: Intermediate / Facts (fct_sessions) -- Build business logic: sessions, funnels, retention select user_id, session_id, count(distinct event_name) as events_per_session from stg_events group by 1, 2 -- Layer 3: Marts (dim_users) -- Final tables for dashboards and reporting
Why this matters: Without dbt, analysts write the same transformations multiple times in different dashboards. When the logic changes, someone has to hunt down every place it was used. dbt centralizes logic: change it once, and it propagates everywhere.
Alternatives to dbt
Use dbt when
- Multiple analysts query the same transformed data
- Business logic needs to be documented and tested
- Your data warehouse is BigQuery, Snowflake, or Redshift
- You want data quality tests (not null, uniqueness)
Funnel analysis & retention SQL SQL Patterns
Two core SQL patterns that come up constantly in analytics work:
Funnel analysis counts how many users completed each stage of a sequence. The key is using conditional aggregation, counting only the rows where a specific event happened.
select count(distinct user_id) as visitors, count(distinct case when viewed_product then user_id end) as product_views, count(distinct case when started_checkout then user_id end) as checkout_starts, count(distinct case when purchased then user_id end) as purchases from fct_sessions
Retention analysis tracks whether users who joined on day 0 came back on day 1, 7, or 30. The pattern uses a self-join or window function to find users active on multiple dates.
-- Classic retention pattern: join users back to themselves select d0.cohort_date, count(distinct d0.user_id) as cohort_size, count(distinct d1.user_id) / count(distinct d0.user_id) as day1_retention from user_first_seen d0 left join user_active_days d1 on d0.user_id = d1.user_id and date_diff(d1.active_date, d0.first_seen, day) = 1 group by 1
Common mistake
Using COUNT(*) instead of COUNT(DISTINCT user_id) in funnels. If a user triggers
the same event twice, they get double-counted. Always deduplicate users at each funnel stage.
Resources: Analytics Engineering
Start with the "Getting started" tutorial. The core concepts section is excellent.
Free. The canonical course. 5 hours. Covers everything you need.
Best free resource for analytical SQL patterns including funnels, cohorts, and window functions.
Decision framework
Choosing the right technique for Analytics Engineering.
Simplicity vs robustness
A simple SQL script beats a complex dbt project for a one-off task. But for production systems that multiple people rely on, the robustness of dbt (testing, docs, version control) is worth the overhead.