Sub topic 14
Querying Recent Activity with the Realtime Reporting API
This chapter assumes that you know how GA4 events and event parameters work, have a GA4 property, and can obtain an OAuth 2.0 access token. It also assumes that you can identify your numeric property ID. The Realtime Reporting API lets you query activity from the recent Realtime window without opening the GA4 interface.
What the API returns
The Realtime Reporting API is a Google Analytics Data API method. Its endpoint is:
POST https://analyticsdata.googleapis.com/v1beta/properties/PROPERTY_ID:runRealtimeReportA request contains dimensions, metrics, and optional filters. A dimension groups results, such as eventName. A metric contains a measurement, such as eventCount.
For example, grouping by eventName and requesting eventCount produces one row for each event name received recently.
| Request field | Example | Purpose |
|---|---|---|
| `dimensions` | `eventName` | Groups the returned rows |
| `metrics` | `eventCount` | Reports a number for each row |
| `property` | `properties/123456789` | Selects the GA4 property |
| `dimensionFilter` | Event name equals `sign_up` | Limits the rows |
The response includes dimensionValues and metricValues. Values are returned as strings, so convert them to numbers before calculations.
Send a Realtime report request
Replace PROPERTY_ID with your numeric property ID and ACCESS_TOKEN with a valid OAuth access token.
curl -X POST "https://analyticsdata.googleapis.com/v1beta/properties/PROPERTY_ID:runRealtimeReport" \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dimensions": [{ "name": "eventName" }],
"metrics": [{ "name": "eventCount" }]
}'A successful response contains rows similar to this:
{
"dimensionHeaders": [
{ "name": "eventName" }
],
"metricHeaders": [
{ "name": "eventCount", "type": "TYPE_INTEGER" }
],
"rows": [
{
"dimensionValues": [{ "value": "page_view" }],
"metricValues": [{ "value": "18" }]
},
{
"dimensionValues": [{ "value": "sign_up" }],
"metricValues": [{ "value": "2" }]
}
]
}The API reports aggregated activity. It does not show the exact event sequence from one browser or the parameter values attached to one event. Use DebugView for that level of inspection.
Filter the query
A dimension filter can make a large result easier to read. This request asks only for the sign_up event:
{
"dimensions": [{ "name": "eventName" }],
"metrics": [{ "name": "eventCount" }],
"dimensionFilter": {
"filter": {
"fieldName": "eventName",
"stringFilter": {
"matchType": "EXACT",
"value": "sign_up"
}
}
}
}You can also group activity by supported dimensions such as country or device category. Check the current Data API schema before building an automated query because available dimensions and compatibility rules can change.
Choose the right verification tool
Use the API when a script must answer, “Did this event arrive recently, and how many times?” Use the GA4 Realtime report when you want interactive cards and dimensions. Use DebugView when you need to inspect the event payload from a debug device.
Exercise
Your deployment test must check whether purchase events arrived in the recent window. Which API query is the simplest starting point?
Show answer
Query runRealtimeReport with the eventName dimension and eventCount metric, then filter the results for purchase.