> For the complete documentation index, see [llms.txt](https://learn.fueled.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.fueled.io/learning-center/recipes-and-open-source/working-with-ga4-data-in-bigquery/simple-page-view-to-purchase-funnel-analysis.md).

# Simple 'Page View to Purchase' Funnel Analysis

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.

```sql
-- CTE to identify all unique sessions
WITH all_sessions AS (
    SELECT DISTINCT
        event_param.value.int_value AS ga_session_id
    FROM 
        `PROJECT.DATASET.events_intraday_*`,
        UNNEST(event_params) AS event_param
    WHERE 
        event_param.key = 'ga_session_id'
),

-- CTE to identify sessions with the specified sales page view
sessions_with_sales_page AS (
    SELECT DISTINCT
        session_param.value.int_value AS ga_session_id
    FROM 
        `PROJECT.DATASET.events_intraday_*`,
        UNNEST(event_params) AS event_param,
        UNNEST(event_params) AS session_param
    WHERE 
        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 purchase
sessions_with_purchase AS (
    SELECT DISTINCT
        session_param.value.int_value AS ga_session_id
    FROM 
        `PROJECT.DATASET.events_intraday_*`,
        UNNEST(event_params) AS event_param,
        UNNEST(event_params) AS session_param
    WHERE 
        event_name = 'purchase'
        AND session_param.key = 'ga_session_id'
)

-- Main query to compute the counts
SELECT
    (SELECT COUNT(ga_session_id) FROM all_sessions) AS total_unique_sessions,
    (SELECT COUNT(ga_session_id) FROM sessions_with_sales_page) AS sessions_with_sales_page,
    (SELECT COUNT(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;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.fueled.io/learning-center/recipes-and-open-source/working-with-ga4-data-in-bigquery/simple-page-view-to-purchase-funnel-analysis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
