Sub topic 16
Analyzing acquisition in BigQuery
This chapter assumes you know the GA4 interface, have a property collecting data, and can read basic SQL. You also need a GA4 property linked to BigQuery. BigQuery is Google's cloud data warehouse. The GA4 export writes event-level rows to tables such as events_20260131.
The export is useful when the standard reports cannot answer a detailed question. You can filter exact dates, combine dimensions, inspect raw events, and save repeatable queries. The export does not contain every report field in exactly the same form, so always identify the scope of a field before interpreting it.
Understand the exported acquisition fields
Each exported row represents an event, such as a page view, purchase, or session start. Many values are nested inside records. The traffic_source record describes the user's first known acquisition source:
| Field | Scope | Example meaning |
|---|---|---|
| `traffic_source.source` | User | The source that first acquired the user |
| `traffic_source.medium` | User | The medium that first acquired the user |
| `traffic_source.name` | User | The first campaign name |
| `user_pseudo_id` | Device or browser | An identifier used to count returning activity |
This is similar to the user-scoped view in the User acquisition report. It is not a session-by-session source. A returning user may arrive through a new campaign while retaining the original traffic_source values.
Query first-user acquisition
The following query counts distinct users by their first-user source and medium for January 2026:
SELECT
traffic_source.source AS first_user_source,
traffic_source.medium AS first_user_medium,
COUNT(DISTINCT user_pseudo_id) AS users
FROM `my_project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20260101' AND '20260131'
GROUP BY first_user_source, first_user_medium
ORDER BY users DESC
LIMIT 20;Replace the project and dataset with your own values. The wildcard selects daily event tables. _TABLE_SUFFIX limits which tables BigQuery scans, which reduces cost and improves query speed.
A null or empty source can appear when GA4 has no first-user attribution for the row. Treat missing values separately from a literal value such as (direct) when investigating data quality.
Match the question to the scope
Use traffic_source when the question is, “Which sources first brought these users to the site?” For session-level questions, inspect the session attribution fields available in your export schema, such as session_traffic_source_last_click, or build a session-level transformation from exported event data. Do not group session questions by traffic_source, because that assigns every event from a user to the user's original source.
The export also differs from the interface because the interface applies reporting identity, consent settings, attribution rules, and processing logic. Small differences are normal. Compare the same date range, property, timezone, identity settings, and scope before treating a difference as an error.
Trace the analysis workflow
Exercise
Why would grouping by traffic_source.source give the wrong answer to “Which campaign generated this session?”
Show answer
traffic_source is first-user scoped. It records how the user was originally acquired, not necessarily how the current session began. Use session-scoped attribution fields for that question.