Zernio
APIFor you
Zernio
APIFor you
Platforms

Google Analytics

Overview

Set up

Connect

Measure

Reports

Reference

Limits & errors
Dashboard
OverviewPlatformsAPI ReferenceResources
Google Analytics

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:

Terminal
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
  }'
JSON
{
  "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

FieldWhat it does
metrics1 to 10 metric names, such as sessions or screenPageViews. Required.
dimensionsUp to 9 dimension names, such as date or pagePath.
dateRangesUp to 4 ranges of startDate and endDate, each YYYY-MM-DD, today, yesterday or NdaysAgo. Defaults to 28daysAgo to yesterday.
dimensionFilter, metricFilterA filter expression in Google's own shape.
orderBysUp to 10 sort orders in Google's own shape.
limit, offsetRows per page (up to 10,000) and the row to start from. Page with offset until you reach rowCount.
keepEmptyRowsReturn rows whose metrics are all zero.
currencyCodeISO 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:

Terminal
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:

Terminal
curl "https://zernio.com/api/v1/analytics/googleanalytics/metadata?accountId=ACCOUNT_ID" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
JSON
{
  "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. propertyQuota shows 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 limit costs more tokens. A cached response costs none.

If it fails

ErrorCauseFix
400A field is invalid, or Google rejected a dimension or metric name; the message names itCheck the name against the metadata endpoint.
403The Google account lost access to the property, or removed ZernioReconnect Google Analytics.
404The account does not exist, is not a Google Analytics account, or your key cannot reach itList your accounts with GET /v1/accounts?category=analytics.
429 with rate_limitedGoogle's quota for the property is used upRetry after the quota refills, and reuse cached requests where you can.

Related

  • Run a Google Analytics report
  • Run a realtime report
  • List dimensions and metrics
  • Connect
Was this page helpful?

Connect

Connect a GA4 property to a profile with Google sign-in, from the dashboard or with the connect API.

Limits & errors

What the Google Analytics connection does not do, its quotas, and the common errors when connecting a property or running a report.

On this page

Run a reportRequest fieldsRun a realtime reportList dimensions and metricsHow it behavesIf it failsRelated