Sub topic 14
Rebuilding Paths from BigQuery Export and the Data API
Assume you understand GA4 events, key events, source and medium, and basic SQL. This chapter uses the GA4 BigQuery export to build a simple session sequence. It also shows how the Data API can provide a report-ready summary.
Two ways to inspect path data
The BigQuery export contains event-level records. You can group those records into sessions and order the sessions before a key event. This gives you a flexible sequence for analysis.
The Data API returns aggregated GA4 report data. It is useful for retrieving the same kinds of dimensions and metrics used in the GA4 interface, but it does not expose every raw event detail.
Build a simple path in BigQuery
The query below finds users who purchased during January 2026. It groups their sessions and joins each session's source and medium into an ordered path.
-- Last few sessions' source/medium for users who purchased.
-- Replace project.dataset with your own export dataset.
WITH purchasers AS (
SELECT DISTINCT user_pseudo_id
FROM `project.dataset.events_*`
WHERE event_name = 'purchase'
AND _TABLE_SUFFIX BETWEEN '20260101' AND '20260131'
),
sessions AS (
SELECT
user_pseudo_id,
(SELECT value.int_value
FROM UNNEST(event_params)
WHERE key = 'ga_session_id') AS session_id,
MIN(event_timestamp) AS session_start_ts,
ANY_VALUE(collected_traffic_source.manual_source) AS source,
ANY_VALUE(collected_traffic_source.manual_medium) AS medium
FROM `project.dataset.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20260101' AND '20260131'
AND user_pseudo_id IN (SELECT user_pseudo_id FROM purchasers)
GROUP BY user_pseudo_id, session_id
)
SELECT
user_pseudo_id,
STRING_AGG(
CONCAT(IFNULL(source, '(direct)'), ' / ',
IFNULL(medium, '(none)')),
' > ' ORDER BY session_start_ts
) AS path
FROM sessions
WHERE session_id IS NOT NULL
GROUP BY user_pseudo_id
LIMIT 100;For example, a result might be:
| user_pseudo_id | path |
|---|---|
| 123 | google / cpc > newsletter / email > (direct) / (none) |
This result says the user had three recorded sessions. It does not say that each session received conversion credit. The query also includes every matching session in the selected date range, not only sessions inside GA4's configured lookback window.
Query aggregated data with the Data API
Use the Google Analytics Data API when you need dimensions and metrics from a GA4 property without processing raw events. This request groups sessions and key events by session default channel group.
{
"dateRanges": [
{
"startDate": "30daysAgo",
"endDate": "yesterday"
}
],
"dimensions": [
{
"name": "sessionDefaultChannelGroup"
}
],
"metrics": [
{
"name": "sessions"
},
{
"name": "keyEvents"
}
],
"orderBys": [
{
"metric": {
"metricName": "keyEvents"
},
"desc": true
}
],
"limit": 10
}The API response is useful for comparing session-scoped activity with attributed results in the Advertising reports. However, a session channel group is not the same as a conversion path. It summarizes sessions by channel and does not return the complete ordered sequence for each user.
Choose the right source
- Use BigQuery for event-level investigation, custom path rules, and joins with business data.
- Use the Data API for scheduled summaries, dashboards, and report dimensions supported by GA4.
- Use the GA4 interface when you need its configured attribution model and presentation of path metrics.
Exercise
A BigQuery path contains “organic / organic” twice before a purchase. Does that mean organic search received two units of conversion credit?
Show answer
No. It means the user had two recorded sessions labeled organic search. Attribution credit depends on the selected model and lookback window.