Reports
Run GA4 reports and realtime reports on a connected property, and list the dimensions and metrics it supports.
Every call takes the accountId of a connected Google Analytics account. Zernio passes the request to Google's Data API and returns Google's response as it is, with accountId and propertyId added.
Run a report
Pick 1 to 10 metrics and up to 9 dimensions, using their GA4 API names:
curl -X POST "https://zernio.com/api/v1/analytics/googleanalytics/report" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"accountId": "ACCOUNT_ID",
"metrics": ["sessions", "activeUsers"],
"dimensions": ["sessionSource"],
"dateRanges": [{ "startDate": "7daysAgo", "endDate": "yesterday" }],
"orderBys": [{ "metric": { "metricName": "sessions" }, "desc": true }],
"limit": 10
}'{
"accountId": "ACCOUNT_ID",
"propertyId": "123456789",
"dimensionHeaders": [{ "name": "sessionSource" }],
"metricHeaders": [{ "name": "sessions", "type": "TYPE_INTEGER" }, { "name": "activeUsers", "type": "TYPE_INTEGER" }],
"rows": [
{ "dimensionValues": [{ "value": "google" }], "metricValues": [{ "value": "1840" }, { "value": "1502" }] }
],
"rowCount": 24,
"metadata": { "currencyCode": "USD", "timeZone": "America/Los_Angeles" },
"propertyQuota": { "tokensPerDay": { "consumed": 12, "remaining": 199988 } }
}Every value in rows is a string, even numbers. Convert them using the type in metricHeaders.
Request fields
| Field | What it does |
|---|---|
metrics | 1 to 10 metric names, such as sessions or screenPageViews. Required. |
dimensions | Up to 9 dimension names, such as date or pagePath. |
dateRanges | Up to 4 ranges of startDate and endDate, each YYYY-MM-DD, today, yesterday or NdaysAgo. Defaults to 28daysAgo to yesterday. |
dimensionFilter, metricFilter | A filter expression in Google's own shape. |
orderBys | Up to 10 sort orders in Google's own shape. |
limit, offset | Rows per page (up to 10,000) and the row to start from. Page with offset until you reach rowCount. |
keepEmptyRows | Return rows whose metrics are all zero. |
currencyCode | ISO 4217 code for currency metrics. Defaults to the property's currency. |
Filters and sort orders follow Google's runReport reference.
Run a realtime report
Call POST /v1/analytics/googleanalytics/realtime for activity in the last 30 minutes. It takes the same metrics, dimensions, filters, orderBys and limit, plus optional minuteRanges:
curl -X POST "https://zernio.com/api/v1/analytics/googleanalytics/realtime" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "accountId": "ACCOUNT_ID", "metrics": ["activeUsers"], "dimensions": ["country"] }'Realtime reports take no dateRanges, offset, keepEmptyRows or currencyCode.
List dimensions and metrics
Call GET /v1/analytics/googleanalytics/metadata to see every name the property accepts, custom definitions included:
curl "https://zernio.com/api/v1/analytics/googleanalytics/metadata?accountId=ACCOUNT_ID" \
-H "Authorization: Bearer $ZERNIO_API_KEY"{
"accountId": "ACCOUNT_ID",
"propertyId": "123456789",
"dimensions": [{ "apiName": "sessionSource", "uiName": "Session source", "description": "…", "category": "Traffic source", "customDefinition": false }],
"metrics": [{ "apiName": "sessions", "uiName": "Sessions", "description": "…", "category": "Session", "customDefinition": false, "type": "TYPE_INTEGER" }]
}How it behaves
- Identical report requests on the same property are cached for 10 minutes. Metadata is cached for 1 hour. Realtime reports are never cached.
- Google meters each property. A property gets 200,000 tokens a day and 40,000 an hour, and all Zernio users share 14,000 tokens an hour per property.
propertyQuotashows what is left. - Hourly quotas refill within the hour. Daily quotas refill at midnight Pacific time.
- A larger date range, more dimensions or a higher
limitcosts more tokens. A cached response costs none.
If it fails
| Error | Cause | Fix |
|---|---|---|
400 | A field is invalid, or Google rejected a dimension or metric name; the message names it | Check the name against the metadata endpoint. |
403 | The Google account lost access to the property, or removed Zernio | Reconnect Google Analytics. |
404 | The account does not exist, is not a Google Analytics account, or your key cannot reach it | List your accounts with GET /v1/accounts?category=analytics. |
429 with rate_limited | Google's quota for the property is used up | Retry after the quota refills, and reuse cached requests where you can. |