SCALIX help

← All tools

ga4_run_report

Google Analytics 4 read low risk

Part of the GA4 Analytics Agent.

What it does

Run a standard GA4 report via the Analytics Data API (properties.runReport) to cross-reference site/app behavior against ad spend: sessions, totalUsers, newUsers, screenPageViews, engagementRate, averageSessionDuration, bounceRate, eventCount, keyEvents (the canonical conversion metric since the 2024-25 rename; 'conversions' is a deprecated alias), and totalRevenue, grouped by dimensions such as date, sessionDefaultChannelGroup, eventName, country, city, pagePath, and (when GA4 is linked to Google Ads) googleAdsCampaignName/googleAdsCreativeId. Returns rows of dimensionValues + metricValues plus rowCount and metadata. ACCURACY: totalRevenue and other currency metrics arrive as plain decimal strings already in account currency (NOT micros — do NOT divide by 1e6; that division applies only to Google Ads cost_micros/value_micros). Rates (engagementRate, bounceRate) are 0..1 fractions — present as percentages by x100. averageSessionDuration is seconds. Row totals can differ from the sum of returned rows because of (a) sampling on high-cardinality queries, (b) the row 'limit' truncating results, and (c) '(other)' bucketing when cardinality exceeds the per-property cap; request metricAggregations TOTAL to get the true total and surface any (other) row. When multiple high-cardinality dimensions are combined, row counts multiply (one row per dimension-value combination). For prior-period deltas, pass two dateRanges and label each by its index; never blend GA4 numbers with Google Ads numbers in a single figure without labeling which platform each came from.

Inputs

NameTypeRequiredDescription
property_idstringyesGA4 property numeric id. Normalize: strip any 'properties/' prefix and non-digits; the server formats as 'properties/{id}'. Distinct from a Google Ads CID (do not strip dashes from a CID and pass it here).
dimensionsarray<string>noDimension API names (e.g. date, sessionDefaultChannelGroup, eventName, country, pagePath). Max 9 per request. Validate against getMetadata; default [] (totals-only report).
metricsarray<string>yesMetric API names. Prefer keyEvents over the deprecated 'conversions' alias (and advertiserAdCostPerKeyEvent over advertiserAdCostPerConversion); Google accepts a deprecated name only while ga4_get_metadata lists it in deprecatedApiNames. At least 1 required; max 10 per request.
date_rangesarray<object>yes1+ objects {startDate,endDate} as YYYY-MM-DD or relative (today, yesterday, NdaysAgo). Two ranges => prior-period comparison; each output row carries a dateRange index. Max 4 date ranges.
dimension_filterobjectnoFilterExpression on dimensions (andGroup/orGroup/notExpression/filter). Enum-normalize string values; matchType and case-sensitivity match GA4 semantics.
metric_filterobjectnoFilterExpression on metrics (numericFilter/betweenFilter).
order_bysarray<object>noSort spec: metric {metric:{metricName},desc} or dimension {dimension:{dimensionName,orderType}}.
limitintegernoRows to return, default 10000, hard cap 250000 per request (must be positive). Use offset to page; combine with metric_aggregations to keep totals correct under truncation.
offsetintegernoZero-based row offset for pagination within the 250k-per-request cap; page beyond 250k by repeated offset requests.
metric_aggregationsarray<string>noTOTAL | MINIMUM | MAXIMUM. Request TOTAL when limit may truncate so the true total and any '(other)' bucket are returned.
keep_empty_rowsbooleannoIf true, return rows whose every metric is 0. Default false.
currency_codestringnoISO-4217 override for revenue metrics; defaults to property currency. Does NOT convert revenue to micros.

Safeguards

Policy

GA4 is a separate Google product, scope, and property from Google Ads — only query properties the connected user is authorized to access (analytics.readonly scope), enforce per-tenant isolation, and never merge GA4 metrics with Google Ads metrics in one figure without labeling which platform each number came from. Use the canonical 'keyEvents' metric (the 'conversions' alias is deprecated per the GA4 key-events rename) so figures reconcile to the GA4 UI within +/-1%.

Reminder

GA4 data is the user's own property data under a separate read scope; do not blend it with Ads numbers unlabeled and do not retain GA4 rows beyond the request's purpose.

Errors

Error classMeansWhat to doRetry
PROPERTY_NOT_FOUNDGA4 property {property_id} was not found or is not accessible by the connected account.Confirm the property id and that the signed-in user has Analytics access; re-list properties.no
PERMISSION_DENIEDThe connected account lacks read access to GA4 property {property_id} (HTTP 403).Have the user grant at least Viewer on the property or re-authorize the analytics.readonly scope.no
TOKEN_REVOKEDThe Google Analytics OAuth token is invalid or revoked (HTTP 401).needs_reauth: prompt the user to reconnect their Google account.no
INVALID_ARGUMENTGA4 rejected the request (HTTP 400): {surfaced platform message, e.g. unknown metric name, >9 dimensions, or >10 metrics}.Surface the exact GA4 message; fix the dimension/metric name or reduce dimensions to <=9 / metrics to <=10. Do not guess names — validate with ga4_get_metadata.no
INCOMPATIBLE_FIELDSRequested dimensions/metrics are not compatible in one report.Run ga4_check_compatibility, drop the incompatible field, and retry.no
RESOURCE_EXHAUSTEDGA4 Data API quota exhausted (HTTP 429): Tokens Per Project Per Property Per Hour / Per Day or concurrent-request limit reached.Back off exponentially 5s/10s/20s (cap 60s) then retry once; reduce query cost (fewer dimensions, narrower date range) to spend fewer tokens.yes
PLATFORM_UNAVAILABLEGA4 Data API returned a transient server error (HTTP 500/503).Retry once with backoff; if it persists report the outage rather than fail silently.yes

Edge cases

  • No matching data: return success with count:0 and rows:[] (not an error).
  • Results truncated by limit: include a warning telling the user to narrow the date range/filters or page via offset, and request metric_aggregations TOTAL so the true total is still shown.
  • High-cardinality dimensions produce an '(other)' row that bundles the tail; flag it so the user knows the breakdown is incomplete.
  • Sampling can occur on large/high-cardinality queries; if the response metadata indicates sampling, warn that figures are estimates.
  • Multiple high-cardinality dimensions multiply row count — warn before requesting near the 250k cap.
  • Caller passes deprecated 'conversions'/'isConversionEvent'/'advertiserAdCostPerConversion' — use keyEvents/isKeyEvent/advertiserAdCostPerKeyEvent instead (Google accepts a deprecated name only while getMetadata lists it in deprecatedApiNames).
  • Expired access token: refresh once and retry transparently; only surface TOKEN_REVOKED if refresh fails.
  • Revenue returned as a decimal string in property currency — parse as decimal, never divide by 1e6.
  • Two dateRanges request: each output row carries a dateRange index; label period A vs B for the prior-period delta.
  • limit <= 0 is rejected by the API as INVALID_ARGUMENT — coerce to a positive value or default 10000.