ga4_get_metadata
Google Analytics 4 read low risk
Part of the GA4 Analytics Agent.
What it does
Fetch the dimension and metric metadata catalog for a GA4 property (properties.getMetadata) — the authoritative, property-specific list of valid dimensions and metrics including custom dimensions/metrics and any deprecation info. Returns DimensionMetadata and MetricMetadata entries with apiName, uiName, description, category, type/expression, and crucially the deprecatedApiNames list — which now flags 'conversions' (use 'keyEvents'), 'isConversionEvent' (use 'isKeyEvent'), and 'advertiserAdCostPerConversion' (use 'advertiserAdCostPerKeyEvent') as deprecated aliases. Use this to validate field names BEFORE running any report (preventing INVALID_ARGUMENT guesses), to discover custom dimensions, and to map deprecated names to their canonical keyEvents-era replacements. Passing the literal property id returns property-specific custom fields; the special id 'properties/0' returns only the universal/standard catalog without customs. Read-only and very cheap on quota.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
property_id | string | yes | GA4 property numeric id to get property-specific metadata (includes custom dimensions/metrics). Normalize to the resource name 'properties/{id}/metadata'. Use '0' to retrieve only the universal standard catalog without custom fields. |
Safeguards
Policy
Metadata is read under the analytics.readonly scope for the user's authorized property only; surface deprecated->canonical mappings (conversions->keyEvents, isConversionEvent->isKeyEvent, advertiserAdCostPerConversion->advertiserAdCostPerKeyEvent) so downstream reports use the current metric and reconcile to the GA4 UI. Respect per-tenant isolation when caching the catalog.
Reminder
Metadata describes the user's own property schema (incl. custom fields) — keep it tenant-scoped and don't expose one property's custom fields to another account.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
PROPERTY_NOT_FOUND | GA4 property {property_id} not found or inaccessible. | Verify the property id; use '0' for the universal catalog if you only need standard fields. | 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 | Malformed property resource name (HTTP 400): {surfaced message}. | Format as 'properties/{id}/metadata'; do not include extra path segments. | no |
RESOURCE_EXHAUSTED | GA4 Data API quota exhausted (HTTP 429). | Back off 5s/10s/20s (cap 60s), retry once; cache metadata to avoid repeat fetches. | yes |
PLATFORM_UNAVAILABLE | GA4 Data API transient server error (HTTP 500/503). | Retry once with backoff; report if persistent. | yes |
Edge cases
- Property has no custom dimensions/metrics: success returning only standard fields (count of customs = 0).
- Caller wants only the universal catalog: pass id '0' to skip property-specific customs.
- deprecatedApiNames present: include the mapping (conversions->keyEvents, isConversionEvent->isKeyEvent, advertiserAdCostPerConversion->advertiserAdCostPerKeyEvent) in the result so reports use the canonical name.
- Custom dimension/metric scope (event vs user) matters for compatibility — expose category/scope so callers pick valid combinations.
- Metadata is property-specific and changes when admins add custom fields — refresh cache periodically rather than assuming staleness.
- Expired token: refresh once and retry transparently.