Sub topic 8
Tying organic landing pages to revenue with BigQuery
Search Console tells you how many clicks a page received. It cannot tell you what those visitors bought. GA4 records the purchases, and its BigQuery export lets you join sessions to revenue at the landing-page level. This chapter builds that join. It then shows how to line it up with the query cohorts from earlier chapters so that revenue can be compared between exposed and comparison pages.
This chapter assumes you can read SQL with UNNEST and LEFT JOIN, and that you have used pandas. It also assumes the GA4 BigQuery export is already running for your property. Exports are not backfilled, so check that your dataset has daily events_YYYYMMDD tables covering both the pre and post periods.
Why revenue needs a separate step
Query-level data and revenue data live in different systems with different keys.
| Source | Grain | Has queries | Has revenue |
|---|---|---|---|
| Search Console | query, page, date | Yes | No |
| GA4 BigQuery export | event, session, user | No | Yes |
The only key the two share is the page. Search Console reports the page URL a searcher clicked. GA4 records the page URL where the session started. So the plan is:
- Compute sessions and revenue per organic landing page from GA4.
- Label each page by how exposed its queries are to AI Overviews, using the cohort work from Search Console.
- Compare revenue per session across page groups and across periods.
How the GA4 export is shaped
Each row in an events_* table is one event. Values you want, such as the page URL or session ID, are not columns. They sit inside the repeated event_params field, one key/value record per parameter. You pull them out with a scalar subquery over UNNEST(event_params).
Two parameters matter here:
ga_session_ididentifies a session. It is only unique within a user, so a session key must combine it withuser_pseudo_id.page_locationis the full URL of the page, including the query string.
The purchase event carries the same ga_session_id, and its revenue is in ecommerce.purchase_revenue.
The base query
This query counts organic sessions and sums revenue per landing page for the first quarter of 2026.
WITH sessions AS (
SELECT
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS session_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location') AS landing_page,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'medium') AS medium
FROM `project.analytics_123456.events_*`
WHERE event_name = 'session_start'
AND _TABLE_SUFFIX BETWEEN '20260101' AND '20260331'
),
purchases AS (
SELECT
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS session_id,
ecommerce.purchase_revenue AS revenue
FROM `project.analytics_123456.events_*`
WHERE event_name = 'purchase'
AND _TABLE_SUFFIX BETWEEN '20260101' AND '20260331'
)
SELECT
s.landing_page,
COUNT(DISTINCT CONCAT(s.user_pseudo_id, '.', CAST(s.session_id AS STRING))) AS sessions,
SUM(p.revenue) AS revenue
FROM sessions AS s
LEFT JOIN purchases AS p
ON s.user_pseudo_id = p.user_pseudo_id AND s.session_id = p.session_id
WHERE s.medium = 'organic'
GROUP BY s.landing_page
ORDER BY revenue DESC;Read it in three parts:
sessionsholds one row per session start, with the landing page and medium.purchasesholds one row per purchase, keyed by the same user and session.- The
LEFT JOINkeeps every session, including those without a purchase. TheirrevenueisNULL, andSUMignoresNULL. An inner join would drop non-buying sessions, and your sessions count would shrink to buyers only.
The _TABLE_SUFFIX filter limits the scan to the study dates. Always set it. BigQuery bills by bytes scanned, and the wildcard table would otherwise read every day of history.
Common errors in this query
The base query runs, but the numbers it returns can still be wrong. These are the failures to check for.
The medium parameter may not be what you think
The medium event parameter is only populated when the event carries campaign information. Depending on your property and export version, organic sessions may not have 'organic' in that parameter on session_start. Newer exports include session-level traffic source fields, such as collected_traffic_source and session_traffic_source_last_click. Inspect a sample of rows before trusting the filter:
SELECT
collected_traffic_source.manual_medium AS manual_medium,
session_traffic_source_last_click.manual_campaign.medium AS last_click_medium,
COUNT(*) AS events
FROM `project.analytics_123456.events_20260115`
WHERE event_name = 'session_start'
GROUP BY manual_medium, last_click_medium
ORDER BY events DESC;If these columns do not exist in your tables, your export predates them. In that case, keep the parameter approach and reconcile its totals against the GA4 interface.
Landing pages are fragmented by URL noise
page_location contains the protocol, host, query string and fragment. The same article can appear as /guide, /guide?utm_source=x and /guide?ref=home. Revenue per page then spreads over many rows, and it will not match the Search Console URLs. Reduce each URL to a path before grouping:
REGEXP_EXTRACT(page_location, r'^https?://[^/]+(/[^?#]*)') AS landing_pathApply the same normalization to the Search Console page values in pandas, including trailing-slash handling. A mismatch here is the most common reason a merge silently loses half its rows.
Revenue can be double counted
Two things inflate revenue:
- Some implementations send a
purchaseevent more than once for the same transaction. Deduplicate onecommerce.transaction_idbefore joining. - If
session_startappears twice for a session, the join fans out and each purchase is counted twice.COUNT(DISTINCT ...)protects the session count, butSUM(revenue)has no such protection.
Deduplicating both sides first fixes both problems:
WITH sessions AS (
SELECT
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS session_id,
ANY_VALUE(REGEXP_EXTRACT(
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location'),
r'^https?://[^/]+(/[^?#]*)')) AS landing_path,
ANY_VALUE(IF(event_date < '20260201', 'pre', 'post')) AS period
FROM `project.analytics_123456.events_*`
WHERE event_name = 'session_start'
AND _TABLE_SUFFIX BETWEEN '20260101' AND '20260331'
GROUP BY user_pseudo_id, session_id
),
purchases AS (
SELECT
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS session_id,
ecommerce.transaction_id AS transaction_id,
ANY_VALUE(ecommerce.purchase_revenue) AS revenue
FROM `project.analytics_123456.events_*`
WHERE event_name = 'purchase'
AND _TABLE_SUFFIX BETWEEN '20260101' AND '20260331'
GROUP BY user_pseudo_id, session_id, transaction_id
)
SELECT
s.landing_path,
s.period,
COUNT(*) AS sessions,
COALESCE(SUM(p.revenue), 0) AS revenue
FROM sessions AS s
LEFT JOIN purchases AS p
ON s.user_pseudo_id = p.user_pseudo_id AND s.session_id = p.session_id
GROUP BY s.landing_path, s.period;Here the GROUP BY in sessions guarantees one row per session, so COUNT(*) is a safe session count. The period column splits the quarter at 1 February, the same change date used in the CTR analysis. This version omits the organic filter so you can add whichever medium field your inspection query showed to be reliable.
Attribution is last-touch at the session level
A purchase is credited to the landing page of the session in which it happened. A visitor who found you through an AI Overview citation on Monday, left, and bought on Thursday through a direct visit counts as direct revenue. Organic revenue per page therefore understates the value of search. If AI Overviews shift research behaviour earlier in the journey, that shift will not show up in this query.
Connecting revenue to exposure
Search Console data has a query column. GA4 does not. To say anything about exposed queries, you convert the query cohorts into a page-level measure: the share of each page's Search Console clicks that come from exposed queries. Pages above a threshold form the "high exposure" group, and the rest form the comparison group.
This example uses small inline data, so it runs as shown. In practice, gsc comes from your API export and ga4 from the query above.
import pandas as pd
gsc = pd.DataFrame({
"page": ["https://example.com/guide", "https://example.com/guide",
"https://example.com/pricing", "https://example.com/pricing"],
"cohort": ["exposed", "comparison", "exposed", "comparison"],
"clicks": [900, 100, 50, 450],
})
ga4 = pd.DataFrame({
"landing_path": ["/guide", "/guide", "/pricing", "/pricing"],
"period": ["pre", "post", "pre", "post"],
"sessions": [1000, 700, 500, 490],
"revenue": [5000.0, 3300.0, 6000.0, 5800.0],
})
gsc["path"] = gsc["page"].str.replace(r"^https?://[^/]+", "", regex=True).str.rstrip("/")
share = (
gsc.pivot_table(index="path", columns="cohort", values="clicks", aggfunc="sum", fill_value=0)
)
share["exposed_share"] = share["exposed"] / (share["exposed"] + share["comparison"])
share["group"] = (share["exposed_share"] >= 0.5).map({True: "high_exposure", False: "low_exposure"})
merged = ga4.merge(share[["group"]], left_on="landing_path", right_index=True, how="left")
out = merged.groupby(["group", "period"])[["sessions", "revenue"]].sum()
out["revenue_per_session"] = out["revenue"] / out["sessions"]
print(out)Group by revenue per session as well as total revenue. Total revenue mixes two effects: fewer visits and less revenue per visit. Sessions answer the traffic question. Revenue per session shows whether the visitors who still arrive are worth less or more than before. If AI Overviews remove low-intent clicks, sessions may fall while revenue per session rises.
The final step is the same difference-in-differences logic used for CTR. Compute the change in revenue per session for the high-exposure group, subtract the change for the low-exposure group, and report the result with the caveats from the confounders chapter.
Limits specific to this join
- Page-level exposure is a blend. A page with a 60% exposed share still receives 40% of its clicks from other queries. The group label is an approximation, so choose the threshold before you look at results and test a second threshold.
- Pages with few purchases are noisy. A single large order can swing a page's revenue. Aggregate to groups before comparing, and consider median order value alongside totals.
- New or removed pages break the comparison. Pages that exist in only one period distort the groups. Restrict the analysis to pages present in both.
- Consent and ad blockers remove sessions. If the share of consented traffic changed during the study window, GA4 sessions and Search Console clicks will drift apart. Track the ratio of GA4 organic sessions to Search Console clicks per period as a sanity check.
Exercise
Your revenue query reports 1,200 sessions and 18,400 in revenue for a landing page, but the finance team's order system shows 15,900 for the same organic orders. You find that some purchases fire the GA4 purchase event twice. Which change to the query addresses this, and why does COUNT(DISTINCT ...) on sessions not already protect the revenue number?
Show answer
Deduplicate the purchases CTE on ecommerce.transaction_id (group by user, session and transaction ID and take one revenue value per group) before the join. COUNT(DISTINCT ...) only removes repeated session keys from the session count. SUM(p.revenue) still adds every joined purchase row, so a duplicated purchase event adds its revenue twice.
Exercise
A page has 80% of its Search Console clicks from exposed queries, so it is placed in the high-exposure group. A colleague proposes also putting a page with 55% exposed clicks in that group. What should you decide before looking at results, and what check follows?
Show answer
Fix the exposure threshold in advance, so the grouping is not chosen to produce a preferred result. Then repeat the analysis with a different threshold, such as 70% or 40%, and confirm the revenue-per-session difference does not change direction or size materially.