Skip to main content

Google Analytics Data API MCP server

Use this integration when an AI agent should read and analyze GA4 event data: core reports, pivot and realtime reports, batched reports, compatibility checks, and audience export workflows. Pair it with the Google Analytics Admin API when the same automation also needs to create properties, streams, or links.

Setting up an MCP server

This article covers the standard steps for creating an MCP server in AI Gateway and connecting it to an AI client. The steps are the same for every integration — application-specific details (API credentials, OAuth endpoints, and scopes) are covered in the individual application pages.

Before you begin

You'll need:

  • Access to AI Gateway with permission to create MCP servers
  • API credentials for the application you're connecting (see the relevant application page for what to collect)

Create an MCP server

Find the API in the catalog

  1. Sign in to AI Gateway and select MCP Servers from the left navigation.
  2. Select New MCP Server.
  3. Search for the application you want to connect, then select it from the catalog.

Configure the server

  1. Enter a Name for your server — something descriptive that identifies both the application and its purpose.
  2. Enter a Description so your team knows what the server is for.
  3. Set the Timeout value. 30 seconds works for most APIs; increase to 60 seconds for APIs that return large payloads.
  4. Toggle Production mode on if this server will be used in a live workflow.
  5. Select Next.

Configure authentication

Enter the authentication details for the application. This varies by service — see the Authentication section of the relevant application page for the specific credentials, OAuth URLs, and scopes to use.

Configure security

  1. Set any Rate limits appropriate for your use case and the API's own limits.
  2. Enable Logging if you want AI Gateway to record requests and responses for auditing.
  3. Select Next.

Deploy

Review the summary, then select Deploy. AI Gateway provisions the server and provides a server URL you'll use when configuring your AI client.


Connect to an AI client

Once your server is deployed, you'll need to add it to the AI client your team uses. Select your client for setup instructions:

Tips

  • You can create multiple MCP servers for the same application — for example, a read-only server for reporting agents and a read-write server for automation workflows.
  • If you're unsure which OAuth scopes to request, start with the minimum read-only set and add write scopes only when needed. Most application pages include scope recommendations.
  • You can edit a server's name, description, timeout, and security settings after deployment without redeploying.

How this differs from Analytics “user management” in the Help Center

The Help Center article [UA] Add, edit, and delete users and user groups [Legacy] covers Universal Analytics (legacy) and who has access to the Analytics web UI. It does not describe how to turn on the Analytics Data API in Google Cloud or how to obtain OAuth tokens for applications.

  • People and roles in the product: Managed in GA4 under Admin → Access management (see current GA4 help for user and group administration).
  • Applications and agents calling APIs: Require a Google Cloud project with the Google Analytics Data API enabled and OAuth (or supported server auth) as below.

Enabling the Data API in Google Cloud

  1. Select or create a Google Cloud project
    Use the project that will issue OAuth credentials (or hold the service account) used by AI Gateway.

  2. Enable the Google Analytics Data API
    In APIs & Services → Library, search for Google Analytics Data API, then Enable.
    Direct link pattern: https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com?project=YOUR_PROJECT_ID

  3. OAuth consent screen
    Add the Data API scopes your app needs (see Authentication). Internal apps can stay in testing with explicit test users; external apps may require verification for sensitive scopes.

  4. OAuth client (Web application)
    Create credentials under APIs & Services → Credentials and register the AI Gateway redirect URI your environment uses.

  5. Property ID in requests
    Reporting calls target a GA4 property as properties/{PROPERTY_ID} (for example properties/123456789). The ID is shown in GA4 Admin → Property settings. The Cloud project does not replace the property ID—it only authenticates the caller.

Official references: Data API overview, REST reference (v1beta), Report basics.

Authentication

ValueSetting
Auth endpointhttps://accounts.google.com/o/oauth2/v2/auth
Token endpointhttps://oauth2.googleapis.com/token
Scopes (typical)https://www.googleapis.com/auth/analytics, https://www.googleapis.com/auth/analytics.readonly
  • Prefer analytics.readonly for dashboards, exports, and agents that must not change Google Analytics configuration.
  • Use analytics only if your product design truly requires broader access (understand Google’s policies for production use).

Available tools

Tools map to the Google Analytics Data API v1beta REST surface. Typical capabilities include:

AreaExamples
Core reportingrunReport with dimensions, metrics, date ranges, filters, and pagination
Batch reportingbatchRunReports for multiple report requests against one property
Pivot & realtimerunPivotReport, runRealtimeReport
Quality checkscheckCompatibility before shipping new dimension/metric combinations
Audience exportsCreate, list, get, and query audience exports (product and preview rules apply)

Exact tool names and input schemas follow the OpenAPI-backed catalog in your AI Gateway environment.

Tips

Always pass the property as properties/{numericId} mixing numeric IDs without the prefix leads to avoidable 404s.

Start with tight date ranges and low limit during agent development to reduce quota usage and response size.

Batch methods have per-request limits (Google documents a small maximum number of child requests); split work across calls if you hit those ceilings.

Realtime and core reports follow different compatibility rules; use checkCompatibility when building dynamic report builders.

Audience exports are asynchronous in nature; create, then poll or query per Audience Export guidance.

See also: Google Analytics Admin API for property and stream configuration.