ga4_batch_run_reports
Google Analytics 4 read low risk
Part of the GA4 Analytics Agent.
What it does
Run up to 5 standard GA4 reports in a single batched request (properties.batchRunReports) against ONE property, returning an ordered list of report responses (each shaped like a ga4_run_report result) so several views — e.g. by-channel, by-device, by-landing-page — are fetched together to economize on round trips and quota tokens. ACCURACY: each sub-report follows runReport semantics (keyEvents canonical; conversions deprecated alias; revenue is a decimal string in property currency, not micros; rates are 0..1 fractions). Each of the 5 reports has its OWN dimensions/metrics/dateRanges/limit and its own 250,000-row cap and per-report '(other)'/truncation behavior — results are positional, so map response[i] back to request[i]. All sub-reports MUST target the same property (the official constraint: all reports must be for the same Google Analytics property); inspect each sub-report's status because a single sub-report error does not necessarily fail the others.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
property_id | string | yes | Single GA4 property numeric id for all reports in the batch; normalize to 'properties/{id}'. Cannot mix properties in one batch; each sub-request's property must be unspecified or identical. |
requests | array<object> | yes | 1..5 report request objects, each {dimensions,metrics,dateRanges,dimensionFilter,metricFilter,orderBys,limit,offset,metricAggregations,keepEmptyRows}. >5 is rejected. Order is preserved in the response. |
Safeguards
Policy
Every batched report runs against the same authorized property under the analytics.readonly scope with per-tenant isolation; use keyEvents over the deprecated conversions alias and keep GA4 figures labeled separately from Google Ads numbers.
Reminder
Batched results are the user's own GA4 data across one property — keep platform labels, don't pool across accounts, don't retain beyond the request.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
TOO_MANY_REPORTS | A batch may contain at most 5 reports; {n} were supplied. | Split into multiple batches of <=5 reports. | no |
PROPERTY_NOT_FOUND | GA4 property {property_id} not found or inaccessible. | Verify property id and access. | no |
PERMISSION_DENIED | Connected account lacks read access to property {property_id} (HTTP 403). | Grant Viewer or re-authorize the analytics.readonly scope. | no |
TOKEN_REVOKED | Analytics OAuth token invalid or revoked (HTTP 401). | needs_reauth: prompt reconnect. | no |
INVALID_ARGUMENT | One or more sub-reports were rejected (HTTP 400): {surfaced per-report message}. | Surface which request index failed and its GA4 message; fix that sub-report's fields (don't guess — validate with ga4_get_metadata) and resubmit. Other sub-reports may have succeeded. | no |
PARTIAL_FAILURE | Some sub-reports succeeded while others returned errors within the batch. | Return the successful reports plus per-index errors; retry only the failed indices after correcting them. | no |
RESOURCE_EXHAUSTED | GA4 Data API quota exhausted (HTTP 429) — a batch consumes tokens for every sub-report. | Back off 5s/10s/20s (cap 60s), retry once; fewer/cheaper sub-reports per batch lowers token spend. | yes |
PLATFORM_UNAVAILABLE | GA4 Data API transient server error (HTTP 500/503). | Retry once with backoff; report if persistent. | yes |
Edge cases
- Empty requests array: reject with a clear 'at least 1 report required' message.
- >5 requests: reject as TOO_MANY_REPORTS before calling the API.
- Mixed properties attempted: reject — batch is single-property only (each sub-request property must be unspecified or equal to the batch property).
- Per-report no-data: that response is success with count:0 while sibling reports return rows.
- One sub-report truncated at its own 250k cap: warn for that index only; siblings unaffected.
- A single sub-report's INVALID_ARGUMENT may not fail the whole batch — always inspect each response's status and map response[i]->request[i].
- Batch token cost is the sum of sub-reports — large batches can trip RESOURCE_EXHAUSTED sooner.
- Caller passes deprecated conversions in any sub-report — use keyEvents instead (Google accepts a deprecated name only while getMetadata lists it in deprecatedApiNames).
- Expired token: refresh once and retry the whole batch transparently.