# GA4 BigQuery Export: SQL Queries for Sessions, Users, Events and Revenue | Masthead

28 SQL recipes for the GA4 BigQuery export: unnest event_params, sessions, users, traffic sources, engagement, ecommerce, retention, and how to keep the queries cheap. Every one runs on Google's public GA4 sample.

> For the index of this section of the site, see [llms.txt](https://mastheadata.com/llms.txt)

GA4 in BigQuery

# GA4 BigQuery export: the SQL cookbook

Ready-to-run queries for the Google Analytics 4 export, from unnesting event\_params to sessions, attribution, funnels and cohorts. Each one runs on Google's public GA4 sample, shows what it scans, and how to scan less as your own export grows.

No recipe matches. Try the [UNNEST reference](https://mastheadata.com/bigquery/functions/unnest.md).

## Working with the export

How the GA4 export is laid out, and how to query it without scanning everything.

*   [Build GA4 sessions in BigQuery from ga\session\idA GA4 session is identified by user\pseudo\id plus the ga\session\id event parameter.](https://mastheadata.com/bigquery/ga4/session-id.md)
*   [GA4 BigQuery export schema: tables, nested fields and value typesThe GA4 export writes one table per day (events\YYYYMMDD) and, with streaming on, events\intraday\YYYYMMDD.](https://mastheadata.com/bigquery/ga4/ga4-export-schema.md)
*   [GA4 user\id vs user\pseudo\id in BigQueryuser\pseudo\id identifies a browser or app instance; user\id is the login ID you set yourself, NULL until you send it.](https://mastheadata.com/bigquery/ga4/user-id-vs-pseudo-id.md)
*   [Query GA4 intraday tables together with daily tablesWith streaming export on, GA4 writes today's events to events\intraday\YYYYMMDD and deletes it once the daily table is complete.](https://mastheadata.com/bigquery/ga4/intraday-tables.md)
*   [Query GA4 user properties in BigQueryGA4 exports user properties in the repeated user\properties record on each event, with key, value slots and set\timestamp\micros.](https://mastheadata.com/bigquery/ga4/user-properties.md)
*   [Unnest GA4 event\params in BigQueryRead a GA4 event parameter with a scalar subquery over UNNEST(event\params): (SELECT value.string\value FROM UNNEST(event\params) WHERE key = 'page\location').](https://mastheadata.com/bigquery/ga4/unnest-event-params.md)
*   [Why GA4 BigQuery numbers differ from the GA4 interfaceBigQuery holds raw events, while GA4 reports estimate users and sessions with HyperLogLog++, may apply thresholds, sampling and consent-mode modeling, use the reporting identity and time zone, and show active users.](https://mastheadata.com/bigquery/ga4/ga4-vs-ui-differences.md)

## Users, sessions and traffic

Users, sessions, page views and where visitors come from.

*   [Count GA4 sessions in BigQueryCount GA4 sessions as distinct user\pseudo\id plus ga\session\id, the way GA4 does.](https://mastheadata.com/bigquery/ga4/sessions.md)
*   [Count total, active and new users in GA4 BigQueryTotal users in GA4 BigQuery is COUNT(DISTINCT user\pseudo\id).](https://mastheadata.com/bigquery/ga4/users.md)
*   [First user source, medium and campaign in GA4 BigQueryThe traffic\source record in the GA4 export is first-touch acquisition: the source, medium and campaign that first brought the user, the same on every later event.](https://mastheadata.com/bigquery/ga4/traffic-source.md)
*   [Landing pages in GA4 BigQueryA landing page is the first page\view of a session.](https://mastheadata.com/bigquery/ga4/landing-pages.md)
*   [New vs returning users in GA4 BigQueryIn the GA4 export a new user is one who logged first\visit (first\open in apps) in the period; everyone else active in the period is returning.](https://mastheadata.com/bigquery/ga4/new-vs-returning-users.md)
*   [Page views by page in GA4 BigQueryPage views in the GA4 export are page\view events.](https://mastheadata.com/bigquery/ga4/page-views.md)
*   [Session source / medium in GA4 BigQueryOlder GA4 exports, including the public sample, carry source, medium and campaign as event parameters.](https://mastheadata.com/bigquery/ga4/session-source-medium.md)
*   [Users and sessions by country and city in GA4 BigQueryThe geo record in the GA4 export holds continent, sub\continent, country, region, city and metro, derived from the user's IP address.](https://mastheadata.com/bigquery/ga4/geo-country-city.md)
*   [Users and sessions by device and browser in GA4 BigQueryThe device record in the GA4 export holds category (desktop, mobile, tablet), operating\system and web\info.browser.](https://mastheadata.com/bigquery/ga4/device-and-browser.md)

## Engagement and events

Engagement time, engaged sessions, events and their parameters.

*   [Bounce rate by landing page in GA4 BigQueryIn GA4, bounce rate is the share of sessions that were not engaged: 1 minus engagement rate.](https://mastheadata.com/bigquery/ga4/bounce-rate.md)
*   [Count GA4 events by name in BigQueryCount GA4 events with COUNT() grouped by event\name.](https://mastheadata.com/bigquery/ga4/events-count.md)
*   [Engagement rate and engaged sessions in GA4 BigQueryEngagement rate in GA4 is engaged sessions divided by sessions.](https://mastheadata.com/bigquery/ga4/engagement-rate.md)
*   [Engagement time from engagement\time\msec in GA4 BigQueryGA4 engagement time is the sum of the engagement\time\msec parameter across events.](https://mastheadata.com/bigquery/ga4/engagement-time.md)
*   [Scroll depth by page in GA4 BigQueryGA4 enhanced measurement sends one scroll event per page the first time 90% of its height becomes visible.](https://mastheadata.com/bigquery/ga4/scroll-depth.md)

## Ecommerce and conversions

Purchases, revenue, items and funnels.

*   [Ecommerce funnel from view\item to purchase in GA4 BigQueryBuild a GA4 checkout funnel by flagging, per user, which of view\item, add\to\cart, begin\checkout, add\shipping\info, add\payment\info and purchase they reached, each step requiring the previous ones.](https://mastheadata.com/bigquery/ga4/ecommerce-funnel.md)
*   [Item revenue and units sold in GA4 BigQueryItem-level ecommerce data in the GA4 export is the repeated items record.](https://mastheadata.com/bigquery/ga4/items-revenue.md)
*   [Key events (conversions) and conversion rate in GA4 BigQueryThe GA4 export has no flag for key events (formerly conversions): you list your key event names in SQL.](https://mastheadata.com/bigquery/ga4/key-events-conversions.md)
*   [Purchases, revenue and average order value in GA4 BigQueryGA4 purchase revenue is in ecommerce.purchase\revenue\in\usd (and purchase\revenue in your currency) on purchase events.](https://mastheadata.com/bigquery/ga4/purchases-and-revenue.md)

## Retention and cohorts

Who comes back, and when.

*   [Weekly user retention cohorts in GA4 BigQueryAssign each user to the week of their first\visit, find the weeks they were active afterwards, and count users per cohort and week offset.](https://mastheadata.com/bigquery/ga4/user-retention-cohorts.md)

## Cost and performance

Keep GA4 queries cheap as the export grows.

*   [Make GA4 BigQuery queries cheaper: \TABLE\SUFFIX, columns, maximum bytes billedOn-demand BigQuery bills the columns a query reads in every table it touches.](https://mastheadata.com/bigquery/ga4/query-cost-control.md)
*   [Materialize GA4 sessions into a partitioned daily tableTurn the GA4 export into a session table partitioned by date and clustered by source and medium, then refresh only the last three days every morning.](https://mastheadata.com/bigquery/ga4/daily-summary-table.md)
---

## Other pages in BigQuery Reference

> For the full index of this section, see [BigQuery Reference](https://mastheadata.com/llms/llms-bigquery-reference.txt).

- [BigQuery Aggregate Functions: COUNT, SUM, STRING_AGG and More | Masthead](https://mastheadata.com/bigquery/aggregate-functions.md): Aggregate functions collapse many rows into one value per group. 16 aggregate functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Array Functions: UNNEST, ARRAY_AGG and More | Masthead](https://mastheadata.com/bigquery/array-functions.md): ARRAY is a first-class type in BigQuery: nested and repeated fields are how BigQuery avoids joins. 11 array functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conditional Expressions: CASE, IF, COALESCE, IFNULL | Masthead](https://mastheadata.com/bigquery/conditional-expressions.md): Conditional expressions choose a value based on a condition or on NULLs. 5 conditional expressions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conversion Functions: CAST and SAFE_CAST | Masthead](https://mastheadata.com/bigquery/conversion-functions.md): Conversion functions change a value from one type to another. 3 conversion functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Cost Queries: SQL to Find and Cut BigQuery Spend | Masthead](https://mastheadata.com/bigquery/cost-queries.md): 20 ready-to-run SQL queries for BigQuery cost: the most expensive queries, cost by user, project, label, dbt model and dashboard, slot usage, storage cost, unused and dead-end tables.
- [BigQuery Date Functions: Syntax, Examples and Gotchas | Masthead](https://mastheadata.com/bigquery/date-functions.md): DATE functions in BigQuery (GoogleSQL) build, shift, truncate, compare and format calendar dates. 14 date functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Datetime Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/datetime-functions.md): DATETIME is a civil date and time with no time zone: what a wall clock shows. 8 datetime functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DDL: CREATE TABLE, Partitioning, Clustering and Views | Masthead](https://mastheadata.com/bigquery/ddl.md): Data definition language creates and changes tables, views, materialized views and functions. 8 DDL statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DML: INSERT, UPDATE, DELETE and MERGE | Masthead](https://mastheadata.com/bigquery/dml.md): Data manipulation language changes table rows. 5 DML statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Error Messages: Causes and Fixes | Masthead](https://mastheadata.com/bigquery/errors.md): 51 BigQuery error messages explained: what each one means, why it happens and how to fix it, from "Resources exceeded" and quota errors to permissions, DML conflicts and failed loads.
- [BigQuery Functions List: Syntax and Examples for Every Function | Masthead](https://mastheadata.com/bigquery/functions.md): All 143 BigQuery SQL functions we cover, by category: date, timestamp, string, array, JSON, aggregate, window and more. Each with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery INFORMATION_SCHEMA: Jobs, Tables, Storage and Costs | Masthead](https://mastheadata.com/bigquery/information-schema-views.md): INFORMATION_SCHEMA views expose BigQuery metadata as tables you can query: jobs, slots, bytes billed, tables, columns and storage. 2 INFORMATION_SCHEMA with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery JSON Functions: JSON_VALUE, JSON_QUERY and More | Masthead](https://mastheadata.com/bigquery/json-functions.md): BigQuery reads JSON stored as STRING or as the native JSON type. 14 JSON functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Math Functions: ROUND, SAFE_DIVIDE, MOD and More | Masthead](https://mastheadata.com/bigquery/math-functions.md): Mathematical functions round, divide, bucket and transform numbers. 15 mathematical functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Pricing Calculator: On-Demand vs Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing-calculator.md): Free BigQuery pricing calculator: compare on-demand ($6.25 per TiB) with Standard, Enterprise and Enterprise Plus editions per slot-hour, and logical vs physical storage billing, using your own numbers from INFORMATION_SCHEMA.
- [BigQuery Pricing Explained (2026): On-Demand, Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing.md): BigQuery bills compute and storage separately. Compute is on-demand at $6.25 per TiB scanned (the first 1 TiB a month is free) or capacity-based with editions from $0.04 per slot-hour. Storage costs $0.02 per GiB a month for active data and $0.01 for data unchanged for 90 days (US, logical).
- [BigQuery Public Datasets: Sizes, Tables and What They Cost to Query | Masthead](https://mastheadata.com/bigquery/public-datasets.md): 40 BigQuery public datasets with their real table sizes and what querying them costs: GitHub, Stack Overflow, Wikipedia, Google Trends, GA4 sample, NOAA weather, taxi trips, crypto and more, with cheap example queries.
- [BigQuery Query Syntax: QUALIFY, PIVOT, CTEs, JOINs and More | Masthead](https://mastheadata.com/bigquery/query-syntax.md): The clauses that shape a GoogleSQL query in BigQuery: CTEs, joins, set operations, PIVOT, QUALIFY and SELECT * EXCEPT. 11 query syntax with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Scripting: Variables, Loops, Dynamic SQL, LOAD and EXPORT | Masthead](https://mastheadata.com/bigquery/scripting.md): Multi-statement queries let you declare variables, loop, branch and build SQL at run time, and LOAD DATA and EXPORT DATA move data in and out of BigQuery from SQL.. 5 scripting and data movement with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery SQL Syntax: Statements, Clauses, DDL and DML | Masthead](https://mastheadata.com/bigquery/sql.md): BigQuery SQL syntax reference: QUALIFY, PIVOT, MERGE, CTEs, partitioned and clustered tables, scripting and INFORMATION_SCHEMA. 31 statements and clauses with examples and cost notes.
- [BigQuery String Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/string-functions.md): String functions in BigQuery split, search, replace, pad and format STRING values, and most also accept BYTES. 28 string functions with syntax, runnable examples, common mistakes and cost notes.
- [The Bill Is Right: Guess Your BigQuery Bill | Masthead](https://mastheadata.com/bigquery/the-bill-is-right.md): A free game show for data teams. Guess the monthly BigQuery bill from real Google Cloud list prices: three tries, land within 15% to win.
- [BigQuery Timestamp Functions: Syntax, Time Zones and Examples | Masthead](https://mastheadata.com/bigquery/timestamp-functions.md): TIMESTAMP is an absolute point in time with microsecond precision, stored in UTC. 12 timestamp functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Hash and Utility Functions: FARM_FINGERPRINT, UUID, SHA256 | Masthead](https://mastheadata.com/bigquery/utility-functions.md): Hashing, unique IDs and a few utility functions that show up in pipelines: deterministic sampling, surrogate keys, deduplication and raising your own errors.. 6 hash and utility functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Window Functions: ROW_NUMBER, LAG, RANK and More | Masthead](https://mastheadata.com/bigquery/window-functions.md): Window (analytic) functions compute a value for every row from a window of related rows, defined with OVER (PARTITION BY ... 11 window functions with syntax, runnable examples, common mistakes and cost notes.
