| name | ga4-realtime-api |
| description | Pull current-session / active-user data from the GA4 Realtime endpoint —
a separate API surface from runReport with different metrics, dimensions, and
freshness guarantees (~30 min rolling window instead of T-48h). Trigger with
"GA4 realtime", "active users right now", "GA4 current sessions",
"who's on my site now".
|
| allowed-tools | Bash(python3:*), Bash(curl:*) |
| version | 1.2.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","analytics","google-analytics","ga4","realtime"] |
| compatibility | Designed for Claude Code |
GA4 Realtime API
The Realtime API is GA4's "what's happening right now" endpoint. Different from runReport:
| runReport (Data API) | runRealtimeReport (Realtime) |
|---|
| Freshness | ~24-48h lag, stable | Last ~30 min, rolling |
| Window | Any date range | Implicit — last 30 min |
| Metrics | ~50 supported | ~10 supported (subset) |
| Dimensions | ~150 supported | ~15 supported (subset) |
| Quota | Per-property daily | Separate Realtime quota |
| Use case | Reports, dashboards, trend analysis | Live dashboards, monitoring, "are we down?" |
Don't try to use runReport for now-data — its freshest data point is yesterday. Use runRealtimeReport.
Minimum viable call
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
RunRealtimeReportRequest, Metric, Dimension,
)
client = BetaAnalyticsDataClient()
resp = client.run_realtime_report(RunRealtimeReportRequest(
property="properties/123456789",
metrics=[Metric(name="activeUsers")],
))
total = int(resp.rows[0].metric_values[0].value) if resp.rows else 0
print(f"Active users right now: {total}")
No date_ranges block — the implicit window is the last 30 min. Adding one will error.
Realtime metrics (the full list)