ga4_check_compatibility
Google Analytics 4 read low risk
Part of the GA4 Analytics Agent.
What it does
Check which GA4 dimensions and metrics can be combined in a single report (properties.checkCompatibility) BEFORE running it, so report requests don't fail with INVALID_ARGUMENT/incompatibility at query time. Given a candidate set of dimensions and metrics (and optional filters), it returns per-field compatibility (COMPATIBLE / INCOMPATIBLE) for each dimension and metric, letting the agent prune the incompatible field and retry. Use compatibilityFilter=COMPATIBLE to return only fields that work together. This pairs with ga4_get_metadata (which lists valid names) — metadata answers 'does the field exist', checkCompatibility answers 'can these fields coexist in one report'. Honors the keyEvents-era naming (validate keyEvents, not the deprecated conversions alias). Read-only and cheap on quota.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
property_id | string | yes | GA4 property numeric id; normalize to 'properties/{id}'. |
dimensions | array<string> | no | Candidate dimension API names to test together (max 9). Validate names via ga4_get_metadata first. |
metrics | array<string> | no | Candidate metric API names to test together; prefer keyEvents over the deprecated conversions alias. |
dimension_filter | object | no | Optional FilterExpression on dimensions; its fields are included in the compatibility evaluation. |
metric_filter | object | no | Optional FilterExpression on metrics; included in the evaluation. |
compatibility_filter | string | no | COMPATIBLE => return only fields compatible with the rest of the set; COMPATIBILITY_UNSPECIFIED => return all with their compatibility status. |
Safeguards
Policy
Compatibility checks run under the analytics.readonly scope for the user's authorized property only (per-tenant isolation). Validate against keyEvents (the deprecated conversions alias should be mapped first) so the eventual report reconciles to the GA4 UI.
Reminder
This only inspects the user's own property schema compatibility — keep it tenant-scoped and don't leak one property's field set to another account.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
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 | GA4 rejected the compatibility check (HTTP 400): {surfaced message} — typically an unknown field name or >9 dimensions. | Surface the GA4 message; fix/remove the unknown field (validate via ga4_get_metadata) and keep dimensions <=9. Do not guess names. | no |
RESOURCE_EXHAUSTED | GA4 Data API quota exhausted (HTTP 429). | Back off 5s/10s/20s (cap 60s), retry once. | yes |
PLATFORM_UNAVAILABLE | GA4 Data API transient server error (HTTP 500/503). | Retry once with backoff; report if persistent. | yes |
Edge cases
- All requested fields compatible: return success listing each as COMPATIBLE.
- Some fields incompatible: return per-field status so the caller can drop the offending field and retry the report.
- compatibility_filter=COMPATIBLE: response returns only the subset that coexists — use it to auto-prune.
- Empty dimensions and empty metrics: nothing to evaluate — return a clear validation message.
- Unknown field name: 400 (vs an incompatibility result) — distinguish 'does not exist' (use ga4_get_metadata) from 'exists but incompatible'.
- Caller passes deprecated conversions/isConversionEvent — check keyEvents/isKeyEvent instead (Google accepts a deprecated name only while getMetadata lists it in deprecatedApiNames).
- Custom dimension scope mismatches (event vs user) commonly drive incompatibility — surface that reason when available.
- Expired token: refresh once and retry transparently.