Journey analysis with the GA4 export: rebuilding page sequences in SQL
GA4 path analysis in BigQuery rebuilds each session's page sequence from the raw export. Every page_view is a row, so ROW_NUMBER() numbers the steps and LEAD() pairs each page with the next. On the public sample, January 2021 gives 276,615 steps across 111,200 sessions. It is the first method of our guide to GA4 journeys, baskets, and repeat buyers.
What doesn't GA4 path exploration tell you?
GA4 path exploration shows the most frequent next steps from one node, not each full session sequence. Each step shows the top 5 nodes by default, and up to 20 with "+ More". Every other page falls into an "Others" node. A breakdown keeps only the top 5 values of its dimension. A path has a starting point or an ending point, never both. And explorations are sampled once a query exceeds 10 million events on a standard property.
None of these limits is a defect. Path exploration is built to browse, not to count. Some questions have no exact answer there. How many sessions went from the cart back to a product page, on mobile, over a quarter? The raw GA4 export answers it. Each page_view is a row with a timestamp, so the sequence is a query.
| Question | Path exploration | SQL on the export |
|---|---|---|
| Pages shown per step | Top 5, up to 20, then "Others" | Every page |
| Sampling | Over 10 million events per query on a standard property | None |
| Start and end point together | No, one or the other | Any condition on the sequence |
| Repeated views of a page | Merged only when consecutive ("View unique nodes only") | Your rule, written once |
| Output | A tree on screen | A table for Power BI or any visual |
Page sequences are not channel sequences. The order of marketing touchpoints before an order is a separate analysis: conversion paths, the channel sequences that end in a purchase.
How do you number the pages of a session in SQL?
ROW_NUMBER() over each session, ordered by event_timestamp, gives every page view its step number. The session key is user_pseudo_id plus the ga_session_id parameter. The page comes from the page_location parameter, without domain or query string. Both parameters sit in the event_params array, described in the GA4 export schema: events, event_params, and items explained.
A session step is one distinct page in the ordered sequence of a session, after consecutive views of the same page are merged, numbered from 1 by ROW_NUMBER() in event timestamp order, so that step 3 is the third page the visitor actually moved to.
Merge the repeats before numbering. A reload, a back button, or a single-page update fires page_view again. Left in place, they make the home page its own most frequent next page. The query uses LAG() to drop any view whose previous page is identical.
WITH views AS (
SELECT
CONCAT(user_pseudo_id, '-', CAST((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS STRING)) AS session_id,
event_timestamp,
REGEXP_EXTRACT((SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'), r'^https?://[^/]+(/[^?#]*)') AS page_path
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20210101' AND '20210131'
AND event_name = 'page_view'
),
collapsed AS (
SELECT session_id, page_path,
ROW_NUMBER() OVER (PARTITION BY session_id ORDER BY event_timestamp) AS step
FROM (
SELECT session_id, event_timestamp, page_path,
LAG(page_path) OVER (PARTITION BY session_id ORDER BY event_timestamp) AS prev_page
FROM views
)
WHERE prev_page IS NULL OR page_path != prev_page
),
sessions AS (
SELECT session_id, MAX(step) AS steps, COUNT(*) - COUNT(DISTINCT page_path) AS revisits
FROM collapsed
GROUP BY session_id
)
SELECT
(SELECT COUNT(*) FROM views) AS page_views,
SUM(steps) AS steps_after_collapse,
COUNT(*) AS sessions,
COUNTIF(steps = 1) AS one_step_sessions,
COUNTIF(steps >= 3) AS sessions_3_steps_plus,
COUNTIF(revisits > 0) AS sessions_with_revisit
FROM sessions
| Measure, January 2021 | Value |
|---|---|
page_view events | 419,004 |
| Session steps after merging repeats | 276,615 |
| Sessions with a page view | 111,200 |
| Sessions with one step | 79,508 |
| Sessions with three steps or more | 22,069 |
| Sessions that revisit a page | 13,074 |
Computed on 2026-10-15 on the public sample bigquery-public-data.ga4_obfuscated_sample_ecommerce (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).
Merging removed 142,389 rows, 34.0% of page views. Ties are the other trap. Events sent in one request can share a timestamp, and ROW_NUMBER() then orders them arbitrarily. On the sample, no session has two page views on one timestamp. Where your export has batch_page_id and batch_event_index, add them to the ORDER BY.
How does LEAD turn steps into transitions, and what is a loop?
LEAD(page_path) over the same window returns the next step of the session, so each row becomes a transition. The last step of a session gets NULL, which marks the exit. With an offset of 2, LEAD(page_path, 2) looks two steps ahead, and that is how loops appear.
A page transition is a pair of consecutive, distinct pages viewed in one session, ordered by event timestamp, where a reload or a repeated view of the same page does not count as a move, and the last page of a session has no transition out.
A loop is a return to the page a visitor left two steps before, in the same session, such as a category page, a product page, then the same category page again; it signals comparison or hesitation rather than a new direction.
On the sample, 13,074 sessions revisit a page: 59.2% of the 22,069 sessions with three steps or more. The query lists the most frequent loops by URL.
WITH views AS (
SELECT
CONCAT(user_pseudo_id, '-', CAST((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS STRING)) AS session_id,
event_timestamp,
REGEXP_EXTRACT((SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'), r'^https?://[^/]+(/[^?#]*)') AS page_path
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20210101' AND '20210131'
AND event_name = 'page_view'
),
collapsed AS (
SELECT session_id, event_timestamp, page_path
FROM (
SELECT session_id, event_timestamp, page_path,
LAG(page_path) OVER (PARTITION BY session_id ORDER BY event_timestamp) AS prev_page
FROM views
)
WHERE prev_page IS NULL OR page_path != prev_page
),
moves AS (
SELECT session_id, page_path,
LEAD(page_path) OVER w AS next_page,
LEAD(page_path, 2) OVER w AS page_after_next
FROM collapsed
WINDOW w AS (PARTITION BY session_id ORDER BY event_timestamp)
)
SELECT page_path AS page, next_page AS detour, COUNT(*) AS loops, COUNT(DISTINCT session_id) AS sessions
FROM moves
WHERE page_after_next = page_path
GROUP BY page, detour
ORDER BY loops DESC
LIMIT 6
| Page | Detour | Loops | Sessions |
|---|---|---|---|
/ | /asearch.html | 386 | 365 |
/ | /Google+Redesign/New | 322 | 314 |
/Google+Redesign/Apparel | /asearch.html | 247 | 245 |
/basket.html | /signin.html | 231 | 210 |
/ | /Google+Redesign/Apparel | 226 | 221 |
/yourinfo.html | /payment.html | 219 | 181 |
Computed on 2026-10-15 on the public sample bigquery-public-data.ga4_obfuscated_sample_ecommerce (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).
Two loops deserve a look. Cart, sign-in, cart: 231 times, visitors went to log in and came back to the cart. Checkout information, payment, information: 219 times, visitors went back to edit the form. The others are searches and section visits that end back on the home page. Product loops are missing from this list. Each product has its own URL, so their signal is split across hundreds of rows.
Why aggregate by page type rather than by URL?
Aggregating by page type turns 1,323 distinct URLs into eight nodes, and makes flows and loops countable. At URL level, the most frequent first move on the sample is home to the men's apparel page. As the pillar guide shows, it covers 1,759 sessions in January 2021. That is one branch among hundreds. At type level, home to any category page covers 13,491 first moves.
The classification is a CASE on the path and the page title. On this store, listing pages carry "Section | Google Merchandise Store" as their title. Product pages carry only the product name. The rule misreads one page. The Lifestyle section has no separator in its title, so it counts as a product. On your site, a page-type parameter sent with each page_view is more reliable.
WITH views AS (
SELECT
CONCAT(user_pseudo_id, '-', CAST((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS STRING)) AS session_id,
event_timestamp,
REGEXP_EXTRACT((SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'), r'^https?://[^/]+(/[^?#]*)') AS page_path,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_title') AS page_title
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20210101' AND '20210131' AND event_name = 'page_view'
),
steps AS (
SELECT session_id, event_timestamp, page_path,
CASE
WHEN page_path IN ('/', '/store.html') THEN 'Home'
WHEN page_path = '/basket.html' THEN 'Cart'
WHEN REGEXP_CONTAINS(page_path, r'yourinfo|payment|ordercompleted') THEN 'Checkout'
WHEN REGEXP_CONTAINS(page_path, r'signin|register|myaccount') THEN 'Account'
WHEN page_path = '/asearch.html' THEN 'Search'
WHEN NOT STARTS_WITH(LOWER(page_path), '/google+redesign') OR page_title = 'Page Unavailable' THEN 'Other'
WHEN STRPOS(page_title, '|') > 0 THEN 'Category'
ELSE 'Product'
END AS page_type
FROM (SELECT *, LAG(page_path) OVER (PARTITION BY session_id ORDER BY event_timestamp) AS prev_page FROM views)
WHERE prev_page IS NULL OR page_path != prev_page
),
moves AS (
SELECT page_type, page_path,
LEAD(page_type) OVER w AS next_type,
LEAD(page_path, 2) OVER w AS page_after_next
FROM steps
WINDOW w AS (PARTITION BY session_id ORDER BY event_timestamp)
)
SELECT page_type, COUNT(DISTINCT page_path) AS urls, COUNT(*) AS steps,
COUNTIF(page_after_next = page_path) AS loops,
COUNTIF(page_after_next = page_path AND next_type = 'Product') AS loops_via_product
FROM moves
GROUP BY page_type
ORDER BY steps DESC
| Page type | URLs | Steps | Loops back to the same page | Of which via a product page |
|---|---|---|---|---|
| Category | 46 | 116,601 | 11,724 | 7,741 |
| Home | 2 | 72,570 | 5,327 | 954 |
| Product | 469 | 41,889 | 1,364 | 495 |
| Cart | 1 | 12,769 | 1,947 | 654 |
| Account | 9 | 10,625 | 555 | 4 |
| Other | 787 | 9,207 | 359 | 80 |
| Checkout | 8 | 6,611 | 527 | 0 |
| Search | 1 | 6,343 | 754 | 389 |
Computed on 2026-10-15 on the public sample bigquery-public-data.ga4_obfuscated_sample_ecommerce (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).
The product loop now shows. 7,741 times, a visitor left a category page for a product, then returned to the same list. That is comparison shopping, and it is the largest loop on the sample. The cart tells another story: 654 times, a visitor opened a product from the cart and came back.
How do you build an edge table for a Sankey visual?
An edge table gives one row per source node, target node, and session count. A Sankey visual reads exactly that. Microsoft's Sankey visual for Power BI needs a Source and a Destination field, plus an optional Weight. The difficulty is cycles. Category to category, or cart to product to cart, are cycles in a graph of page types. The visual then draws a duplicated node to break each cycle.
An edge table is a table of flows with one row per source node, target node, and count, the format a Sankey or network visual reads; in a journey analysis, each node also carries its step number, so that every edge points forward and the graph has no cycle.
Prefixing each node with its step number removes cycles by construction. "2. Category" and "3. Category" are different nodes, so every edge moves forward. Exits become nodes too, and the visual shows where flows stop. Add the device or the channel to the first CTE to get one Sankey per segment. The same edge format, with products in place of pages, draws products bought together as an affinity network.
WITH views AS (
SELECT
CONCAT(user_pseudo_id, '-', CAST((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS STRING)) AS session_id,
event_timestamp,
REGEXP_EXTRACT((SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'), r'^https?://[^/]+(/[^?#]*)') AS page_path,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_title') AS page_title
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20210101' AND '20210131' AND event_name = 'page_view'
),
steps AS (
SELECT session_id, event_timestamp, page_path,
CASE
WHEN page_path IN ('/', '/store.html') THEN 'Home'
WHEN page_path = '/basket.html' THEN 'Cart'
WHEN REGEXP_CONTAINS(page_path, r'yourinfo|payment|ordercompleted') THEN 'Checkout'
WHEN REGEXP_CONTAINS(page_path, r'signin|register|myaccount') THEN 'Account'
WHEN page_path = '/asearch.html' THEN 'Search'
WHEN NOT STARTS_WITH(LOWER(page_path), '/google+redesign') OR page_title = 'Page Unavailable' THEN 'Other'
WHEN STRPOS(page_title, '|') > 0 THEN 'Category'
ELSE 'Product'
END AS page_type
FROM (SELECT *, LAG(page_path) OVER (PARTITION BY session_id ORDER BY event_timestamp) AS prev_page FROM views)
WHERE prev_page IS NULL OR page_path != prev_page
),
edges AS (
SELECT ROW_NUMBER() OVER (PARTITION BY session_id ORDER BY event_timestamp) AS step,
page_type AS source,
IFNULL(LEAD(page_type) OVER (PARTITION BY session_id ORDER BY event_timestamp), '(exit)') AS target
FROM steps
)
SELECT CONCAT(CAST(step AS STRING), '. ', source) AS source_node,
CONCAT(CAST(step + 1 AS STRING), '. ', target) AS target_node,
COUNT(*) AS sessions
FROM edges
WHERE step <= 5
GROUP BY source_node, target_node
ORDER BY sessions DESC
LIMIT 8
| Source node | Target node | Sessions |
|---|---|---|
| 1. Home | 2. (exit) | 35,707 |
| 1. Category | 2. (exit) | 29,084 |
| 1. Home | 2. Category | 13,491 |
| 1. Product | 2. (exit) | 11,730 |
| 2. Category | 3. Category | 6,576 |
| 2. Category | 3. (exit) | 5,091 |
| 3. Category | 4. Category | 4,169 |
| 4. Category | 5. Category | 3,690 |
Computed on 2026-10-15 on the public sample bigquery-public-data.ga4_obfuscated_sample_ecommerce (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).
Four of the eight largest edges are exits, and three are moves between category pages. Remove LIMIT 8 and the query returns every edge of the first five steps, ready for the visual.
What do the first five steps look like on the public sample?
On the public sample in January 2021, 71.5% of sessions with a page view end at step one. The exit rate then falls, to 20.4% at step five. The query summarizes the edge table by step. It returns the sessions reaching each step, the share that exits, and the main page types.
WITH views AS (
SELECT
CONCAT(user_pseudo_id, '-', CAST((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS STRING)) AS session_id,
event_timestamp,
REGEXP_EXTRACT((SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'), r'^https?://[^/]+(/[^?#]*)') AS page_path,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_title') AS page_title
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20210101' AND '20210131' AND event_name = 'page_view'
),
steps AS (
SELECT session_id, event_timestamp, page_path,
CASE
WHEN page_path IN ('/', '/store.html') THEN 'Home'
WHEN page_path = '/basket.html' THEN 'Cart'
WHEN REGEXP_CONTAINS(page_path, r'yourinfo|payment|ordercompleted') THEN 'Checkout'
WHEN REGEXP_CONTAINS(page_path, r'signin|register|myaccount') THEN 'Account'
WHEN page_path = '/asearch.html' THEN 'Search'
WHEN NOT STARTS_WITH(LOWER(page_path), '/google+redesign') OR page_title = 'Page Unavailable' THEN 'Other'
WHEN STRPOS(page_title, '|') > 0 THEN 'Category'
ELSE 'Product'
END AS page_type
FROM (SELECT *, LAG(page_path) OVER (PARTITION BY session_id ORDER BY event_timestamp) AS prev_page FROM views)
WHERE prev_page IS NULL OR page_path != prev_page
),
edges AS (
SELECT ROW_NUMBER() OVER (PARTITION BY session_id ORDER BY event_timestamp) AS step,
page_type AS source,
IFNULL(LEAD(page_type) OVER (PARTITION BY session_id ORDER BY event_timestamp), '(exit)') AS target
FROM steps
)
SELECT step, COUNT(*) AS sessions,
ROUND(100 * COUNTIF(target = '(exit)') / COUNT(*), 1) AS exit_pct,
ROUND(100 * COUNTIF(source = 'Home') / COUNT(*), 1) AS home_pct,
ROUND(100 * COUNTIF(source = 'Category') / COUNT(*), 1) AS category_pct,
ROUND(100 * COUNTIF(source = 'Product') / COUNT(*), 1) AS product_pct
FROM edges
WHERE step <= 5
GROUP BY step
ORDER BY step
| Step | Sessions | Exit after the step | Home | Category | Product |
|---|---|---|---|---|---|
| 1 | 111,200 | 71.5% | 48.2% | 34.3% | 12.6% |
| 2 | 31,692 | 30.4% | 8.0% | 58.8% | 8.9% |
| 3 | 22,069 | 27.9% | 21.0% | 45.0% | 17.0% |
| 4 | 15,903 | 21.0% | 12.2% | 53.3% | 14.4% |
| 5 | 12,563 | 20.4% | 13.4% | 49.5% | 17.2% |
Computed on 2026-10-15 on the public sample bigquery-public-data.ga4_obfuscated_sample_ecommerce (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).
Three readings come out of the table. The first step decides most sessions: 79,508 end there. Category pages carry the middle of the journey, about half of steps two to five. And the home page comes back at step three, at 21.0%, a sign of visitors starting over. Product pages never exceed 17.2% of a step: many visitors browse lists without opening a product.
These exits are not drop-off points yet. A drop-off is measured against an expected path, as in drop-off points on expected paths: where visitors are lost. The sample is obfuscated and dates from 2021: read these shares as a method, not a benchmark.
FAQ
Can I export a GA4 path exploration to BigQuery?
No, a GA4 path exploration cannot be exported to BigQuery. The export holds raw events, not explorations or reports. A path exploration is computed on demand in the interface. To get the same flows in BigQuery, you rebuild them from page_view rows with ROW_NUMBER() and LEAD(). The SQL version also covers every page, with no "Others" node and no sampling.
Should a path analysis use page_location or page_title?
Use the path from page_location as the node key. It stays stable when a title is translated, renamed, or truncated. Titles are useful as a second input, to classify pages into types. On the public sample, listing pages and product pages differ only by their title. Strip the domain and the query string, or campaign tags will split one page into many.
How do I find the exit page of each session in BigQuery?
The exit page is the last step of the session after repeats are merged. In SQL, it is the row where LEAD(page_path) returns NULL. You can also number steps in descending timestamp order and keep step 1. Count exits per page, then divide by sessions viewing that page to get an exit rate.
How many steps should a path analysis keep?
Keep enough steps to cover the journeys you want to change, usually five to ten. On the public sample in January 2021, 12,563 sessions reached a fifth step. That is 11.3% of the 111,200 sessions with a page view. Beyond that, edges get thin and the visual gets noisy. Group later steps into one node if you need them.
Every method of this cocoon rests on the same page sequence, and Journeys, baskets, and repeat buyers: the e-commerce analyses GA4 doesn't show puts them side by side. To receive the next ones: Get new analyses as they ship.
Sources
- GA4 path exploration (opens in a new tab) - Google, consulted 2026-10-15
- About data sampling in GA4 (opens in a new tab) - Google, consulted 2026-10-15
- BigQuery export schema for Google Analytics 4 (opens in a new tab) - Google, consulted 2026-10-15
- BigQuery navigation functions: LEAD and LAG (opens in a new tab) - Google Cloud, consulted 2026-10-15
- BigQuery numbering functions: ROW_NUMBER (opens in a new tab) - Google Cloud, consulted 2026-10-15
- Sankey visual for Power BI, documentation (opens in a new tab) - Microsoft, consulted 2026-10-15