GA4 in BigQuery · Users, sessions and traffic
Landing pages in GA4 BigQuery
A landing page is the first page_view of a session. Group page views by user_pseudo_id and ga_session_id, take the page_location of the earliest one with ARRAY_AGG ORDER BY event_timestamp LIMIT 1, then count sessions per landing page.
The query
WITH page_views AS (
SELECT
user_pseudo_id,
event_timestamp,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS ga_session_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location') AS page_location
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
AND event_name = 'page_view'
),
landings AS (
SELECT
user_pseudo_id,
ga_session_id,
ARRAY_AGG(page_location IGNORE NULLS ORDER BY event_timestamp LIMIT 1)[SAFE_OFFSET(0)] AS landing_page
FROM page_views
GROUP BY user_pseudo_id, ga_session_id
)
SELECT
REGEXP_REPLACE(landing_page, r'[?#].*$', '') AS landing_page,
COUNT(*) AS sessions
FROM landings
GROUP BY landing_page
ORDER BY sessions DESC
LIMIT 20;How it works
The export has no landing page column. You derive it: the landing page of a session is the page_location of its first page_view. The query keeps page views only, groups them by session (user_pseudo_id + ga_session_id), and uses ARRAY_AGG(... ORDER BY event_timestamp LIMIT 1) to pick the earliest URL. IGNORE NULLS avoids the NULL element error if a page view lacks page_location, and SAFE_OFFSET(0) returns NULL instead of failing for an empty array.
Sessions without any page view (a session that only fired user_engagement after midnight, for example) have no landing page here. GA4 reports show those as (not set).
The sample also carries an integer entrances parameter (332,179 events have it; on 2020-12-01 every value is 1). The second variation counts page views where it is set, which avoids the per-session grouping, but it depends on the parameter being present in your export.
| Column | Meaning |
|---|---|
landing_page | URL of the first page view of the session, without query string. |
sessions | Sessions that started on this page. |
Notes and cost
- Cost: reads
event_params.key,int_valueandstring_value, plusevent_timestampanduser_pseudo_id: 585.6 MiB for one month. - Sessions that started before the first day of your range keep their real landing page out of view: their first page view sits in an earlier table. Read one extra day before the range if that matters.
- Add the landing page to a daily summary table once, instead of rebuilding it in every dashboard query.
Variations
Landing pages with engagement rate
Adds the engaged flag per session, so you see which entry pages keep people.
WITH events AS (
SELECT
user_pseudo_id,
event_timestamp,
event_name,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS ga_session_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location') AS page_location,
(SELECT COALESCE(value.string_value, CAST(value.int_value AS STRING))
FROM UNNEST(event_params) WHERE key = 'session_engaged') AS session_engaged
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
),
sessions AS (
SELECT
ARRAY_AGG(IF(event_name = 'page_view', page_location, NULL) IGNORE NULLS
ORDER BY event_timestamp LIMIT 1)[SAFE_OFFSET(0)] AS landing_page,
LOGICAL_OR(session_engaged = '1') AS is_engaged
FROM events
GROUP BY user_pseudo_id, ga_session_id
)
SELECT
REGEXP_REPLACE(landing_page, r'[?#].*$', '') AS landing_page,
COUNT(*) AS sessions,
ROUND(COUNTIF(is_engaged) / COUNT(*), 3) AS engagement_rate
FROM sessions
GROUP BY landing_page
HAVING sessions >= 100
ORDER BY sessions DESC
LIMIT 20;Using the entrances parameter
SELECT
REGEXP_REPLACE(
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'),
r'[?#].*$', '') AS landing_page,
COUNT(*) AS entrances
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20201201' AND '20201231'
AND event_name = 'page_view'
AND (SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'entrances') = 1
GROUP BY landing_page
ORDER BY entrances DESC
LIMIT 20;FAQ
Is there a landing page field in the GA4 BigQuery export?
No. Derive it as the page_location of the first page_view in each session, ordered by event_timestamp.
Why do some sessions have no landing page?
They have no page_view event inside your date range: the session started earlier, or it only sent other events. GA4 reports show such sessions as (not set).
Related
All GA4 export queries · BigQuery cost queries · The GA4 sample dataset
