The following query is helpful in determining how many purchases in a session included a visit to a specific page on your website.
To get started, update the FROM clause to use your BigQuery Project and Dataset. Then, replace 'https://example.com/example-page' with the page you want to test within this funnel.
-- CTE to identify all unique sessionsWITH all_sessions AS (SELECT DISTINCT event_param.value.int_value AS ga_session_idFROM`PROJECT.DATASET.events_intraday_*`, UNNEST(event_params) AS event_paramWHERE event_param.key ='ga_session_id'),-- CTE to identify sessions with the specified sales page viewsessions_with_sales_page AS (SELECT DISTINCT session_param.value.int_value AS ga_session_idFROM`PROJECT.DATASET.events_intraday_*`, UNNEST(event_params) AS event_param, UNNEST(event_params) AS session_paramWHERE event_name ='page_view'AND event_param.key ='page_location'AND event_param.value.string_value ='https://example.com/example-page'AND session_param.key ='ga_session_id'),-- CTE to identify sessions with a purchasesessions_with_purchase AS (SELECT DISTINCT session_param.value.int_value AS ga_session_idFROM`PROJECT.DATASET.events_intraday_*`, UNNEST(event_params) AS event_param, UNNEST(event_params) AS session_paramWHERE event_name ='purchase'AND session_param.key ='ga_session_id')-- Main query to compute the countsSELECT (SELECTCOUNT(ga_session_id) FROM all_sessions) AS total_unique_sessions, (SELECTCOUNT(ga_session_id) FROM sessions_with_sales_page) AS sessions_with_sales_page, (SELECTCOUNT(ga_session_id) FROM sessions_with_sales_page WHERE ga_session_id IN (SELECT ga_session_id FROM sessions_with_purchase)) AS sessions_with_sales_page_and_purchase;