Skip to content

GA4 dbt & GCP Foundations

An in-progress GA4 foundation built on the Velir package, with separate event, session, user and page models and GCP resources.

The Problem

GA4 exports organize events by date, but sessions can cross midnight. Replacing a daily partition must preserve session-wide first and last events, while event, session, user and page models keep different grains.

How It Works

  1. 01Use the Velir GA4 package for staging, parameter extraction, and URL extraction. Materialize daily export shards with event_date-partitioned insert_overwrite.
  2. 02Calculate session row numbers and first/last event flags in staging above the incremental table. These windows use retained session history, not only the replaced day's input.
  3. 03Prefer user_id, then user_pseudo_id, for user identity. Combine stream, user, and GA session ID for session context. Build separate event, session, user, and page rollups; page rows group by date, hour, path, title, and key.
  4. 04Maintain separate Terraform definitions for GCP projects, BigQuery datasets and service-account access.

Engineering Decisions

  • Separate incremental loading from session windows

    Staging assigns row numbers and first/last event flags across stored session events. Limiting the window to one replaced date partition can drop the first event when a session crosses midnight.

    Ordering uses event_timestamp alone. Ties, late events and missing or changing user identity still need validation; the key definitions do not prove stable identifiers.

  • Declare each aggregate's grain

    Session rows group by user and session. User rows retain first/last observations and lifetime totals. Page rows group by date, hour, path, title, and page key.

    One page path can produce several rows. Adding their distinct-user or distinct-session counts can count the same person or session more than once.

  • Keep infrastructure definitions separate

    Project, dataset and access resources describe a different change from a SQL model.

    Configuration is not a deployment receipt or proof of a completed client handoff.

Outcome

The artifacts separate daily event loading, session context and user/page rollups. The project builds on the Velir GA4 package and remains in progress, with GCP resource definitions separate from SQL models.