Skip to main content

Google Analytics ExecModule

Overview

GoogleAnalyticsModule connects ValkyrAI workflows to the Google Analytics Data API through the native map I/O ExecModule ABI. It runs bounded GA4 standard, realtime, pivot, and batch reports, retrieves property metadata, and checks dimension and metric compatibility without exposing OAuth credentials to workflow data.

The connector uses only analyticsdata.googleapis.com. Every exposed operation is read-only at the provider, so transient HTTP and network failures may receive bounded retries. The module does not create properties, change account settings, manage audiences, send Measurement Protocol events, or mutate Analytics data.

Usage

  1. Enable the Google Analytics Data API in the Google Cloud project that owns the OAuth client.
  2. Authorize a dedicated Google principal with https://www.googleapis.com/auth/analytics.readonly and access to the target GA4 property.
  3. Store the numeric GA4 property ID in IntegrationAccount.accountId and a short-lived OAuth access token in the encrypted apiKey SecureField.
  4. Set the IntegrationAccount to READY and bind it through ExecModuleConfig.authConfig.integrationAccount.
  5. Start with get_metadata, then build reports using returned dimension and metric API names.
  6. Use limit, offset, filters, and date ranges to keep reports bounded and composable.

Workflow input cannot provide an authorization header, arbitrary API host, refresh token, service-account private key, account administration operation, or data mutation.

Inputs

NameTypeRequirementDefaultDescription and constraints
operationstringRequiredNoneOne of the seven documented operations.
propertyIdstringOptionalIntegrationAccount.accountIdNumeric GA4 property ID, 1–20 digits.
dateRangesarrayStandard and pivot reportsNone1–4 {startDate,endDate,name?} objects. Dates accept ISO YYYY-MM-DD, today, yesterday, or NdaysAgo.
dimensionsarrayReport dependentNoneUp to 9 {name} definitions using GA4 API names.
metricsarrayReport dependentNoneUp to 10 {name} definitions using GA4 API names.
dimensionFilterobjectOptionalNoneProvider-shaped dimension filter expression, capped at 128 KiB.
metricFilterobjectOptionalNoneProvider-shaped metric filter expression, capped at 128 KiB.
orderBysarrayOptionalNoneUp to 10 provider ordering definitions.
pivotsarrayPivot reportsNone1–2 pivot definitions; each requires non-empty fieldNames.
requestsarrayBatch reportsNone1–5 provider-shaped report requests. Each request is independently bounded.
metricAggregationsarrayOptionalNoneAny of TOTAL, MINIMUM, MAXIMUM, or COUNT.
currencyCodestringOptionalProperty defaultThree-letter ISO-4217 currency code.
limitintegerOptional1000Maximum requested and normalized rows, 1–100,000.
offsetintegerOptional0Provider row offset, 0–100,000,000.
simplifybooleanOptionaltrueMaps standard, realtime, and pivot rows by returned header name.
keepEmptyRowsbooleanOptionalfalseAsks GA4 to retain rows whose metrics are all zero.
returnPropertyQuotabooleanOptionalfalseIncludes provider quota state when supported.
maxAttemptsintegerOptional3Maximum attempts for logically read-only requests, 1–10.
timeoutMsintegerOptional30000HTTP timeout, 100–300,000 ms.

Outputs

NameTypeWhen presentDescription
statusstringAlwayssuccess or error.
operationstringAlwaysNormalized operation.
httpStatus / attemptsintegerProvider requestHTTP status and attempts consumed.
items / countarray / integerSimplified single reportRows mapped by returned dimension and metric header names.
rowCountintegerSingle reportProvider count before local output bounding.
propertyQuotaobjectRequested and returnedGA4 property quota details.
dataobjectRaw, batch, metadata, or compatibility resultProvider-shaped response when simplification does not apply.
errorobjectFailureSafe {code,message,httpStatus?,retryable} details.

OAuth tokens and authorization values are redacted from errors, logs, outputs, and workflow events.

IntegrationAccount Requirements

SettingRequirement
ProviderGoogle OAuth principal with Google Analytics Data API access
accountNameHuman-readable automation identity
accountIdNumeric GA4 property ID, for example 123456789
apiKeyEncrypted SecureField containing a short-lived OAuth access token
OAuth scopehttps://www.googleapis.com/auth/analytics.readonly
statusExactly READY

Grant the principal Viewer access only to the required Analytics account or property. Token issuance, rotation, revocation, and refresh remain IntegrationAccount lifecycle responsibilities.

Configuration

{
"version": "1.0.0",
"authConfig": {
"authStrategy": 1,
"integrationAccount": "integration-account:google-analytics-production"
},
"retryPolicy": {
"maxAttempts": 3,
"backoffStrategy": "EXPONENTIAL",
"initialDelayMs": 1000,
"maxDelayMs": 60000
},
"payloadConfig": {
"parameters": "{\"operation\":\"run_report\",\"limit\":1000,\"simplify\":true}"
}
}

The integration-account reference is symbolic. Persisted workflows use the generated relationship and never plaintext access tokens.

Operations

OperationGoogle Analytics behaviorSide effect
run_reportRuns one standard GA4 report with date ranges, dimensions, metrics, filters, ordering, aggregation, offset, and limit.Read-only.
run_realtime_reportRuns one realtime report without date ranges.Read-only.
batch_run_reportsRuns 1–5 standard reports for the same property.Read-only.
run_pivot_reportRuns one standard-date pivot report with 1–2 pivot definitions.Read-only.
batch_run_pivot_reportsRuns 1–5 pivot reports for the same property.Read-only.
get_metadataRetrieves dimension and metric metadata for the property.Read-only.
check_compatibilityChecks whether selected dimensions and metrics can be combined.Read-only.

Errors and Failure Modes

CodeTypical causeRetryableResolution
VALIDATION_ERRORMissing property, malformed date range, invalid field name, oversized filter/payload, or absent report requirement.NoCorrect the named input; no request was sent.
UNSUPPORTED_OPERATIONUnknown operation.NoSelect a documented operation.
INTEGRATION_ACCOUNT_REQUIREDNo bound account.NoBind a Google Analytics IntegrationAccount.
INTEGRATION_ACCOUNT_NOT_READYAccount is not READY.NoRepair or reconnect the account.
GOOGLE_ANALYTICS_UNAUTHENTICATED / GOOGLE_ANALYTICS_HTTP_401Expired, revoked, or invalid OAuth access token.NoRefresh the IntegrationAccount token.
GOOGLE_ANALYTICS_PERMISSION_DENIED / GOOGLE_ANALYTICS_HTTP_403The principal lacks property access or required scope.NoGrant the minimum missing property permission or scope.
GOOGLE_ANALYTICS_NOT_FOUND / GOOGLE_ANALYTICS_HTTP_404Property ID is wrong or unavailable to the principal.NoVerify the numeric property ID and access assignment.
GOOGLE_ANALYTICS_RESOURCE_EXHAUSTED / GOOGLE_ANALYTICS_HTTP_429Property or project quota is exhausted.YesHonor Retry-After, reduce concurrency, and inspect property quota output.
GOOGLE_ANALYTICS_HTTP_5xxTransient provider failure.YesRetry with bounded backoff.
NETWORK_ERRORTimeout, DNS, TLS, or connectivity failure.YesVerify connectivity and retry later.
RESPONSE_TOO_LARGEProvider response exceeded 10 MiB.NoLower limit, narrow filters, or continue with a larger offset.

Example

Report active users by country for the last seven days:

{
"operation": "run_report",
"dateRanges": [
{"startDate": "7daysAgo", "endDate": "today", "name": "current"}
],
"dimensions": [
{"name": "country"}
],
"metrics": [
{"name": "activeUsers"},
{"name": "sessions"}
],
"orderBys": [
{"metric": {"metricName": "activeUsers"}, "desc": true}
],
"limit": 100,
"simplify": true
}

Expected result:

{
"status": "success",
"operation": "run_report",
"httpStatus": 200,
"rowCount": 2,
"count": 2,
"items": [
{"country": "United States", "activeUsers": "42", "sessions": "51"},
{"country": "Canada", "activeUsers": "17", "sessions": "22"}
],
"attempts": 1
}

Notes

  • Pagination: the Data API uses limit and offset, not an opaque page token. Continue with offset + count while holding property, dates, dimensions, metrics, filters, ordering, and currency constant. The connector returns one bounded page per invocation.
  • Rate limits: every operation is provider read-only, including report POST calls. HTTP 408, 429, 500, 502, 503, and 504 and network failures may retry up to maxAttempts, honoring numeric or RFC-1123 Retry-After values and bounded exponential backoff.
  • API limits: requests are capped at 512 KiB, responses at 10 MiB, standard reports at 4 date ranges, 9 dimensions, 10 metrics, 10 orderings, 100,000 rows, pivot reports at 2 pivots, and batches at 5 reports.
  • Idempotency: all exposed calls are read-only and deterministic for a fixed property, request, and underlying Analytics state. Repeated realtime reports may naturally differ as new events arrive.
  • Destructive behavior: none is exposed. Property/account administration, audience changes, data deletion, event ingestion, user-data collection, OAuth management, and Measurement Protocol writes are intentionally deferred.
  • Privacy: report output can contain confidential analytics dimensions and metrics. Keep downstream workflows within the same access boundary, avoid unnecessary user-level dimensions, and apply Google Analytics data retention and consent requirements.
  • API behavior: provider filters, pivots, comparisons, cohorts, sampling metadata, thresholding metadata, and quota objects remain provider-shaped. Use get_metadata and check_compatibility before constructing dynamic reports.
  • External verification: local tests cover fixed-host routing, OAuth headers, report shapes, date and field validation, normalized rows, batch/pivot bounds, retry, redaction, credential failures, and metadata discovery. Live property permissions, OAuth refresh, quotas, thresholding, cardinality, attribution, freshness, and report values require separately authorized Google Analytics credentials and are not exercised in repository tests.
  • Functional references: n8n Google Analytics integration, Google Analytics Data API v1beta, and Data API schema reference.