ga4_run_realtime_report
Google Analytics 4 read low risk
Part of the GA4 Analytics Agent.
What it does
Run a GA4 real-time report (properties.runRealtimeReport) over the last 30 minutes of event activity for live monitoring — e.g. activeUsers, screenPageViews, eventCount, keyEvents (conversions is the deprecated alias) in the moment — grouped by realtime dimensions such as country, deviceCategory, unifiedScreenName, eventName, minutesAgo, and audienceName. Returns rows of dimensionValues + metricValues with rowCount. ACCURACY/SCOPE: this is a DISTINCT surface from the standard report — it has NO dateRanges (the window is fixed to roughly the last 30 minutes and is selected via minuteRanges 0..29 minutesAgo), a RESTRICTED dimension/metric set (no totalRevenue, no session-scoped historical metrics, no pagePath/sessionDefaultChannelGroup), and figures are inherently provisional and will not match finalized historical reports. Numbers here are live snapshots, not reconciled totals; never present realtime activeUsers as a final period metric. Use minuteRanges to compare two sub-windows (e.g. 0-4 vs 5-9 minutesAgo) for an in-session trend.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
property_id | string | yes | GA4 property numeric id; strip 'properties/' prefix and non-digits, server formats as 'properties/{id}'. |
dimensions | array<string> | no | Realtime dimension names only (country, deviceCategory, unifiedScreenName, eventName, minutesAgo, audienceName, ...). Max 9. Standard-report-only dimensions (e.g. pagePath, sessionDefaultChannelGroup) are rejected with INVALID_ARGUMENT. |
metrics | array<string> | yes | Realtime metric names (activeUsers, screenPageViews, eventCount, keyEvents). totalRevenue and session-scope metrics are NOT available in realtime. Use keyEvents, not the deprecated conversions alias. At least 1 required. |
minute_ranges | array<object> | no | Up to 2 windows within the last 30 min: {name, startMinutesAgo (0..29), endMinutesAgo (0..29)}. There is NO dateRanges field for realtime. |
dimension_filter | object | no | FilterExpression over realtime dimensions; enum-normalize values. |
metric_filter | object | no | FilterExpression over realtime metrics. |
order_bys | array<object> | no | Sort by metric or dimension. |
limit | integer | no | Max rows; realtime returns far fewer rows than standard reports. Default 10000, must be positive. |
metric_aggregations | array<string> | no | TOTAL | MINIMUM | MAXIMUM for the realtime window. |
Safeguards
Policy
Realtime reporting is restricted to the user's authorized property under the analytics.readonly scope; respect per-tenant isolation. Present realtime figures explicitly as provisional last-30-minute snapshots, never as reconciled/final metrics, so users do not mistake them for UI-final numbers, and never blend them with Ads data unlabeled.
Reminder
Realtime numbers are provisional, visitor-level live activity — label them as last-30-min estimates and never persist or cross-account pool them.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
PROPERTY_NOT_FOUND | GA4 property {property_id} not found or inaccessible. | Verify the property id and the user's 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 realtime request (HTTP 400): {surfaced message} — likely a non-realtime dimension/metric or dateRanges supplied. | Surface the GA4 message; remove dateRanges (use minuteRanges) and restrict to realtime-compatible fields. Do not guess field names — validate with ga4_get_metadata. | no |
RESOURCE_EXHAUSTED | Realtime quota exhausted (HTTP 429) — Realtime Tokens / concurrent-request limit reached. | Back off 5s/10s/20s (cap 60s), retry once; realtime has its own quota bucket so reduce polling frequency. | yes |
PLATFORM_UNAVAILABLE | GA4 Data API transient server error (HTTP 500/503). | Retry once with backoff; report if persistent. | yes |
Edge cases
- No live activity in the window: return success with count:0 — a quiet property is normal, not an error.
- Caller supplies dateRanges or a standard-only dimension: reject with a clear message that realtime uses minuteRanges and a restricted field set.
- More than 2 minuteRanges requested: trim to 2 and warn (API allows at most 2).
- Realtime keyEvents lag and will not equal finalized historical keyEvents — always warn they are provisional.
- Realtime data has higher latency thresholds and a small fixed cardinality cap; large limit values still return few rows.
- Expired token: refresh once and retry transparently.
- Polling too frequently burns the realtime quota — surface RESOURCE_EXHAUSTED guidance to slow the cadence.
- Caller passes deprecated conversions metric — use keyEvents instead (Google accepts a deprecated name only while getMetadata lists it in deprecatedApiNames).