# BigQuery worksheet notes

Field behaviour, run limits, where to classify, and the no-export fallback for [../assets/ga4-bigquery-worksheet.sql](../assets/ga4-bigquery-worksheet.sql). Every vendor fact here was checked on 2026-10-17 against the pages listed in `sources.yaml`. Re-check the schema page before relying on a field.

## Export fields the worksheet uses

- `event_date`: the date in the property's reporting time zone, `YYYYMMDD`.
- `event_timestamp`: microseconds, UTC. The worksheet converts it to the order side's clock before comparing dates.
- `ecommerce.transaction_id`: the transaction ID of the purchase. The worksheet treats null, empty and the literal `(not set)` as missing, and then falls back to the `transaction_id` event parameter, including an integer value, because an ID sent as a number can land in `int_value`.
- `value` and `currency` event parameters: what the site actually sent. The worksheet compares these, not `ecommerce.purchase_revenue`. Google describes `purchase_revenue` as the event's revenue in local currency and `purchase_revenue_in_usd` as the USD version; confirm on three known orders which currency your rows use before comparing either.
- `value` can arrive in `double_value`, `float_value`, `int_value` or, when sent as text, `string_value`. The worksheet reads all four and flags text.
- `ecommerce.tax_value` and `ecommerce.shipping_value`: the tax and shipping sent with the event.
- `items`: `price`, `quantity` (set to 1 when not sent), `item_revenue` (price times quantity, purchase events only).
- `stream_id` and `platform`: which stream sent the row. Map streams to stores before joining.
- `batch_event_index` (order of the event within a batch), `batch_page_id` (sequential per page within an engagement) and `batch_ordering_id` (incremented per network request from a page): used to separate identical transport repeats from real second purchases.
- `user_pseudo_id`, the session ID event parameter, `session_traffic_source_last_click.cross_channel_campaign.source` and `.medium`: used only in aggregate, for the sender and attribution checks.
  - Browser tags send `ga_session_id`. Measurement Protocol senders pass `session_id` in the event parameters; Google does not document which key it lands under in the export, so the worksheet reads both, as integer or text. Confirm on one known server-sent order before trusting `rows_without_session` or the sender label.
  - `session_traffic_source_last_click` was added to the export after launch and Google's pages do not date it, so older daily tables can lack it. The schema check counts the tables that have it. If any table in the window lacks it, remove the two columns.
- `privacy_info.analytics_storage`, `privacy_info.ads_storage`, `privacy_info.uses_transient_token`: values `Yes`, `No` or `Unset`. `uses_transient_token` marks web users who denied analytics storage while measurement without cookies is enabled.
- Consent mode: Google states cookieless pings are present in the BigQuery export, and its export comparison article says each session of such a user gets a different `user_pseudo_id`. Community reports show null identifiers on denied rows. Do not infer consent from `user_pseudo_id`; read `privacy_info`.

## Reading the schema

- `INFORMATION_SCHEMA.COLUMNS` lists top-level columns only; nested fields such as `ecommerce.transaction_id` appear only inside a STRUCT type string.
- `INFORMATION_SCHEMA.COLUMN_FIELD_PATHS` returns one row per top-level or nested column with `table_name`, `column_name`, `field_path` and `data_type`. It is a dataset-level view and runs in the dataset's location. The worksheet's schema check uses it.
- Alternatively, `get_table_info` from the BigQuery MCP server on one daily table, then the schema check for the whole window.

## Export behaviour that changes the comparison

- Daily tables `events_YYYYMMDD` are created after GA4 collects all of the day's events. Google updates them for up to 2 calendar days plus today beyond the table date, and occasionally later when data is reprocessed.
- The scan window runs 3 days past the period, so its last tables are still open when the period itself is complete. Run only when the last scan-window day ended at least 3 days ago: with the default window, 6 days after the period ended.
- Intraday tables `events_intraday_YYYYMMDD` are best effort, may not include all data, lack some user attribution fields for new users, and are deleted when the daily table is complete. The worksheet excludes them by requiring an 8-digit suffix.
- The export contains no modelled data and excludes the value Google adds in reports; Google describes it as the raw event data GA4 receives. Expect export counts and report counts to differ, and reconcile against the export.
- Repeated transaction IDs (checked 2026-10-17):
  - Google says reports deduplicate purchases with a repeated transaction ID from the same user, on web streams only.
  - Google does not mention deduplication in the export. Practitioners observe that the export keeps every repeated row; this is not documented.
  - Two senders using different `client_id` values, or a revisit from another device, are different users and may not be deduplicated in reports either.
  - Before relying on either side, check one known reloaded order: two export rows with its `transaction_id`, and how many purchases the Data API shows for it.
- Active data filters remove events before processing; filtered data never reaches GA4 or BigQuery.
- Export event exclusions and unlinked streams remove purchases from the export only.
- Standard properties have a daily export limit of 1 million events. If a property consistently exceeds it, the daily export is paused and earlier days are not reprocessed.
- GA4 ignores events that arrive more than 2 calendar days plus today after they were triggered, and some data can arrive up to 7 days late.

## Running it read-only

- Google's remote BigQuery MCP server exposes `execute_sql` (read-write) and `execute_sql_readonly`, plus `list_dataset_ids`, `list_table_ids`, `get_dataset_info`, `get_table_info`, `get_query_results` and `get_job`. `cancel_job` is not read-only either, so leave it out.
- `execute_sql_readonly` rejects DML, DDL, Python UDFs and graph queries. Both SQL tools stop queries after 3 minutes and return at most 3,000 rows. That is why the worksheet avoids temporary tables and repeats the BASE block.
- A deny policy can block the read-write tool. Ask the project admin for one before connecting an agent to a live project.
- Required roles for the agent's identity: MCP Tool User, BigQuery Job User and BigQuery Data Viewer.

## Where to classify

The classification needs the order side and the analytics side in one query. In order of preference:

1. BigQuery, saved order table: save the order-side output in the same location as the export and run the ORDERS block as written. Saving is a write and needs approval.
2. BigQuery, inline literal: paste the order-side rows into the ORDERS block as `UNNEST([STRUCT(...), ...])` (option b in the file). Read-only, and fine for a few thousand orders. The literal counts toward BigQuery's maximum query length, which includes comments and whitespace; check the current limit on the quotas page before pasting a long list.
3. Order warehouse: page Query 3 out of BigQuery, load it as `analytics_tx_export` next to the orders (a write there, needing approval) and run [../assets/classify-on-order-side.sql](../assets/classify-on-order-side.sql). Same flags, precedence, control and recoverable share, written in portable SQL with dialect notes for BigQuery, Snowflake and PostgreSQL.

Record the choice in the contract (`classification_runs_in`).

## Cost and speed

- Only a constant `_TABLE_SUFFIX` filter limits the tables scanned. A date taken from a subquery or a joined CTE scans every table. Keep the literal dates.
- Wildcard queries are never served from cache, so each run of the BASE block is billed again. Run the schema check and Query 0, then Query 1, then decide which of Queries 2 to 8 you need.
- Columns cost, rows do not: `LIMIT` does not reduce bytes scanned. The BASE block selects only the fields it needs.
- If the same base will be queried many times, propose a saved table of `analytics_tx` for the frozen period. That is a write and needs approval.

## Locations

- A query cannot freely mix datasets from different locations. BigQuery returns an error when the job's location does not match its datasets, and joins across a region and a multi-region behave differently. Check the location of the GA4 export dataset and of the order table before writing the join.
- If several export datasets sit in different locations, run one query per location rather than one union.
- When the order table cannot move, use option 2 or 3 above.

## Sender labels

The worksheet labels rows `browser`, `server_with_session` or `likely_server` from two signals: a page location and a session ID. Browser tags send both. Measurement Protocol events usually have no page location unless the sender adds one, and carry a session only when the sender supplies `session_id`. A server container that forwards browser requests usually keeps the page, so its rows show as `browser`.

This is a heuristic. Before trusting it, find one order you know the server sent and one the browser sent, and check their labels and whether the server row's session ID was read.

## Attribution check

For each sender, Query 1 counts distinct users, rows without a session and distinct session source and medium.

- One constant value is the tell. A sender whose rows all share one user and one source and medium carries no attribution, even when the columns are filled. A null-rate check passes it; a cardinality check does not.
- The same pattern appears when a sender uses a placeholder `client_id`: every purchase lands on one user.
- Report attribution per sender before anyone removes a sender. Removing a sender with no attribution loses counts, not channel data; removing the browser sender loses channel data.

## No BigQuery export: Data API fallback

- `runReport` with dimension `transactionId` and metrics `ecommercePurchases` (counts `purchase` events) and `grossPurchaseRevenue`. Do not use `purchaseRevenue` for this: it subtracts refunded revenue. `transactions` also counts refund events.
- The default page size is 10,000 rows and the maximum is 250,000 rows per request.
- Read the response metadata before trusting the list:
  - `dataLossFromOtherRow` true: some transactions were rolled into an `(other)` row. Narrow the date range and re-run.
  - `subjectToThresholding` true: the report may be incomplete. Google says a report can be subject to thresholding and still miss nothing, when all data is above the thresholds. Google's thresholds article names demographics, search query data and low user or event counts in a narrow date range as causes, and says thresholds cannot be adjusted. Compare the API's purchase count with the order side before treating gaps as tracking loss.
  - `samplingMetadatas` present: the result is sampled; shorten the date range until it is not.
  - `schemaRestrictionResponse` with active metric restrictions: revenue metrics are hidden by the user's role. Use an identity allowed to read revenue.
- Use metadata `timeZone` and `currencyCode` to align with the order side.
- Limits of the fallback: reports already deduplicate repeated transaction IDs for the same user on web streams, there is no sender label and no `privacy_info`, and under advanced consent mode denied purchases are absent unless modelled. Duplicates with the same ID and the attribution check need the export; consent-denied orders count in `X` from consent evidence.
- Google's GA4 MCP server runs these reports read-only through `run_report` (scope `analytics.readonly`, started without `--allow-write`).
