Skip to content
Scalekit Docs
Talk to an Engineer Dashboard

Connect AI agents to Google Analytics

Scalekit connector
Open markdown

The Google Analytics connector lets your AI agent act in each user's Google Analytics account. Each user signs in to Google Analytics once, and Scalekit stores and refreshes their tokens, so your agent never handles credentials. It comes with 66 tools.

Tools
66
What they doRead · write · destructive
33 · 23 · 1033 read23 write10 destructive
Users sign in with
OAuth app
Your own Google app

Setup

  1. Install the SDK

    Terminal window
    npm install @scalekit-sdk/node dotenv
  2. Set your credentials

    Add your Scalekit credentials to your .env file. Find values in app.scalekit.com > Developers > API Credentials.

    .env
    SCALEKIT_ENVIRONMENT_URL=<your-environment-url>
    SCALEKIT_CLIENT_ID=<your-client-id>
    SCALEKIT_CLIENT_SECRET=<your-client-secret>
  3. Create the Google Analytics connection

    In AgentKit > Connections, create a Google Analytics connection and copy its redirect URI. The name you give it is the connection_name your code passes. See Configure connections.

  4. Register a Google OAuth app

    Google Analytics connections use your own OAuth app. Register one with Google and add the redirect URI you copied.

    Then enter the app's Client ID and Client Secret on the Google Analytics connection.

    Console steps with screenshots

    Register your Scalekit environment with the Google Analytics connector so Scalekit handles the OAuth flow and token lifecycle for you. The connection name you create will be used to identify and invoke the connection programmatically. Then complete the configuration in your application as follows:

    1. Set up auth redirects

      • In Scalekit dashboard, go to AgentKit > Connections > Create Connection. Find Google Analytics and click Create. Click Use your own credentials and copy the redirect URI. It looks like https://<SCALEKIT_ENVIRONMENT_URL>/sso/v1/oauth/<CONNECTION_ID>/callback.

      • Navigate to Google Cloud Console → APIs & Services → Credentials.

        Google Cloud Console Credentials page listing API keys, OAuth 2.0 client IDs, and service accounts

      • Click + Create Credentials, then OAuth client ID.

        Create credentials menu showing API key, OAuth client ID, and Service account options

      • Choose Web application from the Application type menu and give the client a name, for example Agent Auth.

        Application type dropdown with Web application, Android, Chrome Extension, iOS, TVs, and Desktop app options

      • Under Authorized redirect URIs, click + Add URI, paste the redirect URI you copied from Scalekit, and click Create.

        Create OAuth client ID form with Web application type and Authorized redirect URIs section

    2. Enable the Google Analytics Admin API

      • In Google Cloud Console, go to APIs & Services → Library. Search for “Google Analytics Admin API” and click Enable.

        Google Analytics Admin API product page showing the Enable button and API Enabled status

    3. Get client credentials

      • Open the OAuth client you created in step 1. Google shows the Client ID under Additional information, and lets you generate a Client secret from the same page.

        OAuth client detail page showing Client ID and Authorized redirect URIs

    4. Add credentials in Scalekit

      • In Scalekit dashboard, go to AgentKit > Connections and open the connection you created.
      • Copy the Connection name shown on that connection and use that exact value in your code as connection_name or connectionName.
      • Enter your credentials:
      • Click Save.
  5. Authorize a user and make your first call

    quickstart.mts
    import { ScalekitClient } from '@scalekit-sdk/node'
    import 'dotenv/config'
    import { createInterface } from 'node:readline/promises'
    const scalekit = new ScalekitClient(
    process.env.SCALEKIT_ENVIRONMENT_URL,
    process.env.SCALEKIT_CLIENT_ID,
    process.env.SCALEKIT_CLIENT_SECRET,
    )
    const actions = scalekit.actions
    const connector = 'googleanalytics'
    const identifier = 'user_123'
    // Generate an authorization link for the user
    const { link } = await actions.getAuthorizationLink({ connectionName: connector, identifier })
    console.log('Authorize Google Analytics:', link)
    const rl = createInterface({ input: process.stdin, output: process.stdout })
    await rl.question('Press Enter after authorizing...')
    rl.close()
    // Make your first call
    const result = await actions.executeTool({
    connector,
    identifier,
    toolName: 'googleanalytics_list_account_summaries',
    toolInput: {},
    })
    console.log(result)
    Terminal window
    npx tsx quickstart.mts

    Each user signs in once. See Authorize a user for the full flow and statuses.

Tools

Pass the exact name to execute_tool
Try in PlaygroundRequest a tool
  • googleanalytics_accounts_run_access_reportRun a Data Access Record Report for a Google Analytics account: an audit log of who accessed report data and when, across every property in the account.Read-only

    Run Account Access Report

    Run a Data Access Record Report for a Google Analytics account: an audit log of who accessed report data and when, across every property in the account. Useful for compliance/security reviews. Returns rows broken down by the requested access-report dimensions and metrics (e.g. userEmail, accessCount) over a date range.

    Inputs

    end_datestringrequired
    End of the report date range (YYYY-MM-DD, or relative: today/yesterday/NdaysAgo).
    entitystringrequired
    The account to run the access report for, in the form accounts/{accountId}.
    metricsarrayrequired
    Access-report metric names, e.g. ["accessCount"]. At least one metric is required. See the Data Access API schema docs for valid names.
    start_datestringrequired
    Start of the report date range (YYYY-MM-DD, or relative: today/yesterday/NdaysAgo).
    dimension_filterobject
    Advanced: a raw FilterExpression object to filter rows by dimension values.
    dimensionsarray
    Access-report dimension names, e.g. ["userEmail", "propertyId"]. See the Data Access API schema docs for valid names.
    limitinteger
    Maximum rows to return. Defaults to 10000; the API returns at most 100000 rows regardless.
    offsetinteger
    Row offset for pagination. Omit or set to 0 for the first page.
    return_entity_quotaboolean
    If true, the response includes this account's current Data Access API quota consumption.
    time_zonestring
    IANA time zone (e.g. America/New_York) used to interpret start/end dates. Defaults to the property's time zone if omitted.
  • googleanalytics_batch_run_pivot_reportsRun multiple GA4 pivot reports against the same property in a single call.Read-only

    Batch Run Pivot Reports

    Run multiple GA4 pivot reports against the same property in a single call. Provide an array of RunPivotReportRequest-shaped objects (each with dimensions, metrics, pivots, dateRanges, etc. using the GA4 Data API's own field names); each entry's property, if set, must match the top-level property.

    Inputs

    propertystringrequired
    The GA4 property identifier all requests in the batch run against, in the form properties/{propertyId}.
    requestsarrayrequired
    Array of RunPivotReportRequest objects, one per pivot report, using the GA4 Data API's native field names (dimensions: [{name}], metrics: [{name}], pivots: [...], dateRanges: [{startDate,endDate}], etc). Example: [{"dimensions":[{"name":"country"}],"metrics":[{"name":"activeUsers"}],"pivots":[{"fieldNames":["country"],"limit":"5"}],"dateRanges":[{"startDate":"7daysAgo","endDate":"today"}]}]
  • googleanalytics_batch_run_reportsRun multiple GA4 reports against the same property in a single call.Read-only

    Batch Run Reports

    Run multiple GA4 reports against the same property in a single call. Provide an array of RunReportRequest-shaped objects (each with dimensions, metrics, dateRanges, etc. using the GA4 Data API's own field names); each entry's property, if set, must match the top-level property.

    Inputs

    propertystringrequired
    The GA4 property identifier all requests in the batch run against, in the form properties/{propertyId}.
    requestsarrayrequired
    Array of RunReportRequest objects, one per report, using the GA4 Data API's native field names (dimensions: [{name}], metrics: [{name}], dateRanges: [{startDate,endDate}], etc). Example: [{"dimensions":[{"name":"country"}],"metrics":[{"name":"activeUsers"}],"dateRanges":[{"startDate":"7daysAgo","endDate":"today"}]}]
  • googleanalytics_check_compatibilityCheck which dimensions and metrics are compatible with each other for a GA4 property before running a report.Read-only

    Check Compatibility

    Check which dimensions and metrics are compatible with each other for a GA4 property before running a report. Pass the same dimensions/metrics/filters you intend to use in Run Report to preview which combinations are valid.

    Inputs

    propertystringrequired
    The GA4 property identifier to check against, in the form properties/{propertyId}. Should match the property you intend to use in Run Report.
    compatibility_filterstring
    Restrict results to only this compatibility level. Valid values: COMPATIBILITY_UNSPECIFIED, COMPATIBLE, INCOMPATIBLE. Commonly set to COMPATIBLE to only return usable dimensions/metrics.one of COMPATIBILITY_UNSPECIFIEDCOMPATIBLEINCOMPATIBLE
    dimension_filterobject
    Advanced: a raw GA4 FilterExpression object matching what you intend to use in Run Report's dimension filter.
    dimensionsarray
    Dimension names to check, e.g. ["country", "city"]. Should be the same value you intend to use in Run Report.
    metric_filterobject
    Advanced: a raw GA4 FilterExpression object matching what you intend to use in Run Report's metric filter.
    metricsarray
    Metric names to check, e.g. ["activeUsers", "sessions"]. Should be the same value you intend to use in Run Report.
  • googleanalytics_get_accountFetch a single Google Analytics account's details by resource name.Read-only

    Get Account

    Fetch a single Google Analytics account's details by resource name.

    Inputs

    namestringrequired
    Resource name of the account to fetch, in the form accounts/{accountId}.
  • googleanalytics_get_audience_exportFetch the configuration and current state (CREATING, ACTIVE, or FAILED) of a GA4 audience export.Read-only

    Get Audience Export

    Fetch the configuration and current state (CREATING, ACTIVE, or FAILED) of a GA4 audience export. Use this to poll a newly created export until it becomes ACTIVE before querying its rows.

    Inputs

    namestringrequired
    The audience export resource name, in the form properties/{propertyId}/audienceExports/{audienceExportId}.
  • googleanalytics_get_conversion_eventDeprecated: prefer the equivalent Key Event tool.Read-only

    Get Conversion Event

    Deprecated: prefer the equivalent Key Event tool. Fetch a single Google Analytics conversion event by its resource name.

    Inputs

    namestringrequired
    Resource name of the conversion event to fetch, in the form properties/{propertyId}/conversionEvents/{conversionEventId}.
  • googleanalytics_get_custom_dimensionFetch a single custom dimension by resource name.Read-only

    Get Custom Dimension

    Fetch a single custom dimension by resource name.

    Inputs

    namestringrequired
    Resource name of the custom dimension to fetch, in the form properties/{propertyId}/customDimensions/{customDimensionId}.