Connect Google Analytics to ChatGPT: Run Reports & Manage Accounts
Learn how to connect Google Analytics to ChatGPT using a managed MCP server. Automate GA4 reporting, property provisioning, and account management workflows.
If you need to connect Google Analytics to ChatGPT to automate traffic reporting, property provisioning, or campaign analysis, you need a Model Context Protocol (MCP) server. This server acts as the translation layer between ChatGPT's JSON-RPC tool calls and the Google Analytics Data and Admin REST APIs. You can either spend engineering cycles building and maintaining this infrastructure yourself, or use a managed integration platform like Truto to dynamically generate a secure, authenticated MCP server URL.
If your team uses Claude, check out our guide on connecting Google Analytics to Claude or explore our broader architectural overview on connecting Google Analytics to AI Agents.
Giving a Large Language Model (LLM) read and write access to a sprawling data ecosystem like Google Analytics 4 (GA4) is an engineering challenge. You have to handle OAuth 2.0 token lifecycles, map complex hierarchical JSON schemas to MCP tool definitions, and deal with Google's notoriously strict quota systems. Every time Google updates an endpoint or deprecates a reporting field, you have to update your server code, redeploy, and test the integration. This guide breaks down exactly how to use Truto to generate a secure, managed MCP server for Google Analytics, connect it natively to ChatGPT, and execute complex analytics workflows using natural language.
The Engineering Reality of the Google Analytics API
A custom MCP server is a self-hosted integration layer. While the open MCP standard provides a predictable way for models to discover tools, the reality of implementing it against Google Analytics - or maintaining custom connectors for other platforms - is painful. You aren't just integrating a simple CRUD database. You are integrating the GA4 Admin API and the GA4 Data API, which have entirely different design patterns and error formats.
If you decide to build a custom MCP server for Google Analytics, you own the entire API lifecycle. Here are the specific integration challenges that break standard REST assumptions when working with GA4:
The Dimension and Metric Compatibility Maze
Unlike a standard SQL database where you can SELECT any column, the Google Analytics Data API strictly governs which dimensions and metrics can be queried together. An LLM cannot arbitrarily ask for 'Users by Browser and Campaign Type' without verifying if that combination is structurally valid in GA4. If your MCP server does not expose a way for the LLM to check compatibility first, the LLM will hallucinate the report request, pass invalid dimension combinations, and trigger API failures.
Strict Property-Level Quotas and 429 Errors
Google Analytics enforces strict, multi-tiered rate limits (quotas) on a per-property basis. There are concurrent request limits, hourly limits, and daily token limits. When a property exhausts its quota, the API returns a 429 Too Many Requests or 429 Quota Exhausted error.
It is critical to note how managed platforms handle this: Truto does not retry, throttle, or apply backoff on rate limit errors. When the upstream Google Analytics API returns an HTTP 429, Truto passes that error directly back to the caller. Truto normalizes the upstream rate limit information into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset) per the IETF specification. The caller (your AI agent framework or custom application) is fully responsible for reading these headers and implementing its own exponential backoff and retry logic.
The Account, Property, and Data Stream Hierarchy
GA4 does not use a flat data model. An Account contains multiple Properties. A Property contains multiple Data Streams (Web, iOS, Android). To run a report, the LLM must first traverse this hierarchy to find the correct property_id. To create a tracking tag, it must provision a Data Stream under a specific Property. Your MCP server must map this strict parent-child relationship into distinct, discoverable tools, otherwise the LLM will mix up identifiers and target the wrong environments.
How to Generate a Managed Google Analytics MCP Server
Instead of building custom server infrastructure to handle OAuth flows and schema mapping, you can use Truto's Managed MCP feature. When you connect a Google Analytics account to Truto, the platform derives an MCP-compatible JSON-RPC endpoint dynamically based on the integration's documented resources.
There are two ways to create this MCP server: via the Truto dashboard or programmatically via the API.
Method 1: Creating the Server via the Truto UI
If you are setting up an internal automation tool for your data analysts, the dashboard provides a quick, zero-code path.
- Log into Truto and navigate to the integrated account page for your connected Google Analytics instance.
- Click the MCP Servers tab.
- Click Create MCP Server.
- Select your desired configuration. You can assign a human-readable name, filter by specific methods (e.g., read-only access), and set an optional expiration date for security.
- Copy the generated MCP server URL. It will look like
https://api.truto.one/mcp/a1b2c3d4e5f6...
This URL contains a cryptographically hashed token that identifies the specific Google Analytics account. No further authentication configuration is required on the client side unless you explicitly mandate it.
Method 2: Creating the Server via the Truto API
If you are an engineering team building an AI-native analytics application and need to programmatically provision MCP servers for your end-users, you can call the Truto API.
Make an authenticated POST request to the /integrated-account/:id/mcp endpoint:
curl -X POST https://api.truto.one/integrated-account/YOUR_ACCOUNT_ID/mcp \
-H "Authorization: Bearer YOUR_TRUTO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "GA4 Marketing Agent Server",
"config": {
"methods": ["read", "list", "google_analytics_reports_run"]
}
}'The API provisions the server, maps the endpoints, and returns a ready-to-use URL:
{
"id": "mcp-789-xyz",
"name": "GA4 Marketing Agent Server",
"config": { "methods": ["read", "list", "google_analytics_reports_run"] },
"expires_at": null,
"url": "https://api.truto.one/mcp/a1b2c3d4e5f67890"
}How to Connect the MCP Server to ChatGPT
Once you have your Truto MCP server URL, you must register it with your ChatGPT environment. You can do this via the ChatGPT desktop application UI or manually via a JSON configuration file if you are running custom agent environments.
Method A: Via the ChatGPT UI
- Open your ChatGPT Desktop application.
- Navigate to Settings -> Apps -> Advanced settings.
- Enable the Developer mode toggle (MCP support is gated behind this flag).
- Under the MCP servers or Custom connectors section, click to add a new server.
- Name: Enter a recognizable label (e.g., "Google Analytics (Truto)").
- Server URL: Paste the Truto MCP URL generated in the previous step.
- Save your settings.
ChatGPT will immediately ping the endpoint, execute the initialize handshake, and discover the available Google Analytics tools.
Method B: Via Manual Config File (SSE Transport)
If you are orchestrating custom agents or using a local MCP client framework that requires explicit transport definitions, you can wrap the Truto endpoint using the official Server-Sent Events (SSE) proxy command. Create or update your MCP configuration file (typically mcp_config.json):
{
"mcpServers": {
"google_analytics": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sse",
"https://api.truto.one/mcp/YOUR_TRUTO_TOKEN"
]
}
}
}This configuration instructs the client to proxy standard standard I/O communication through the SSE transport layer to Truto's remote JSON-RPC endpoint.
Core Google Analytics Operations
Once connected, Truto exposes Google Analytics resources as strictly typed, LLM-callable tools. The schema generation process automatically structures the payloads, ensuring the model understands required fields and pagination parameters. Here are the highest-leverage tools available for GA4.
List All Google Analytics Properties
list_all_google_analytics_properties
Before an AI agent can run a report or create a data stream, it must know the exact property_id of the environment. This tool lists all child Properties accessible to the caller, returning crucial metadata like the property resource name, display name, and industry category.
"Fetch a list of all active Google Analytics properties under our main account. Give me their display names and property resource IDs, excluding any that are marked as soft-deleted in the trash."
Check Dimension and Metric Compatibility
google_analytics_compatibility_check
This is a critical validation tool. Because GA4 enforces strict rules on which metrics (e.g., activeUsers, sessions) can be queried alongside which dimensions (e.g., city, browser, campaignName), the LLM must run this check before compiling complex reports. It returns dimensionCompatibilities and metricCompatibilities indicating if the requested fields can be combined in a Core report.
"I want to run a custom report comparing 'activeUsers' against 'landingPagePlusQueryString' and 'sessionSourceMedium'. Check the GA4 compatibility endpoint for property ID 'properties/123456789' to ensure these dimensions and metrics are valid together."
Run Customized Reports
google_analytics_reports_run
This tool invokes the GA4 Data API to generate customized tabular reports of event data. It accepts specific date ranges, dimensions, and metrics. The Truto proxy layer handles the complex JSON structure expected by Google, allowing the LLM to easily define the query payload.
"Run a report on property 'properties/123456789' for the last 30 days. Give me the total 'sessions' and 'totalRevenue' grouped by the 'sessionDefaultChannelGroup' dimension. Sort the results descending by revenue."
Run Realtime Reports
google_analytics_realtime_report_run
Unlike historical reports, realtime reports query active data from the last 30 minutes. This tool is heavily used by operations and engineering teams monitoring the immediate impact of a new product launch or email campaign blast.
"Pull the real-time report for our main website property. Show me the number of active users currently on the site right now, broken down by their 'country' and 'deviceCategory'."
Create a Data Stream
create_a_google_analytics_data_stream
For IT administrators, provisioning new tracking environments is a tedious manual task. This tool automates the creation of a Web, iOS, or Android data stream within a specific property. It returns the generated stream details, including the all-important Measurement ID.
"Create a new Web Data Stream for the property 'properties/123456789'. Name it 'Q3 Marketing Landing Pages' and set the stream URL to 'https://marketing.example.com'. Return the Measurement ID so I can pass it to the frontend team."
Create Custom Dimensions
create_a_google_analytics_custom_dimension
To track bespoke application data (like a specific user pricing tier or an A/B test variant), you must configure custom dimensions. This tool defines new custom dimensions at the property level, mapping them to event parameters captured by your frontend tracking code.
"We just deployed a new user authentication flow. Create a new custom dimension for property 'properties/123456789' with the parameter name 'auth_method' and a scope of 'EVENT'. Add a description that it tracks whether they used OAuth or email."
For the complete tool inventory, request body schemas, and JSON typings, review the Google Analytics integration page.
Workflows in Action
Connecting an LLM to Google Analytics transforms how your organization interacts with data. Instead of forcing marketers and product managers to navigate complex UI builders, they can converse with their data via ChatGPT. Here are two concrete scenarios.
Scenario 1: The Automated Campaign Post-Mortem
A marketing analyst wants to understand how a recent email campaign performed. Instead of manually exporting CSVs and building pivot tables, they ask ChatGPT to do the heavy lifting.
"We launched the 'Summer 2026 Promo' email campaign three days ago. Check if the 'campaignName' dimension is compatible with the 'conversions' and 'totalRevenue' metrics. If it is, run a report for property 'properties/123456789' covering the last 5 days, grouped by campaign name. Summarize the ROI for the Summer 2026 campaign specifically."
Execution Steps:
- Validation: ChatGPT calls
google_analytics_compatibility_checkwith the requested dimensions and metrics to ensure the API won't reject the query. - Execution: After confirming compatibility, it calls
google_analytics_reports_runwith a date range covering the last 5 days, filtering or grouping bycampaignName. - Analysis: The LLM ingests the returned JSON rows, isolates the 'Summer 2026 Promo' data, and streams a plain-text summary back to the user, highlighting conversion volume and revenue.
Scenario 2: IT Provisioning and Governance
A DevOps engineer is spinning up a new staging environment and needs to configure the analytics backend to match production.
"List all active properties in our GA account. Find the one named 'Staging Environment'. Once you have the ID, create a new Web data stream named 'Staging Portal Web' with the URL 'https://staging.example.com'. Then, create a custom dimension on that property named 'deployment_version' scoped to 'EVENT'."
Execution Steps:
- Discovery: ChatGPT calls
list_all_google_analytics_propertiesto retrieve the active properties and parses the list to find the resource ID for 'Staging Environment'. - Provisioning Streams: Using the found property ID, it calls
create_a_google_analytics_data_streamto generate the web stream, securing the new Measurement ID. - Configuration: It immediately calls
create_a_google_analytics_custom_dimensionto configure thedeployment_versionparameter. - Confirmation: The agent outputs the new Measurement ID and confirmation that the custom dimension is active and ready for the staging deployment.
Security and Access Control
Exposing your enterprise data warehouse or analytics configuration to an LLM introduces obvious risk (see our guide on how to safely give an AI agent access to third-party SaaS data). You do not want a stray prompt deleting an active data stream or archiving a mission-critical custom metric. Truto's MCP architecture provides several layers of access control at the server generation level:
- Method Filtering: You can strictly bind an MCP server to read-only operations. By setting
methods: ["read"]during server creation, Truto will only expose GET and list endpoints (like running reports or listing properties). The LLM will physically lack the tools to executecreate,update, ordeleteactions. - Tag Filtering: If you only want the AI to access reporting endpoints and not administrative endpoints, you can filter tools by tags. Setting
tags: ["reporting"]ensures the server never exposes account or property deletion tools to the LLM context window. - Enforced API Token Auth: By default, anyone with the generated MCP URL can access the tools. For enterprise environments, setting
require_api_token_auth: trueforces the client to pass a valid Truto API token in the Authorization header. If the token is missing or invalid, the tools refuse to run. - Ephemeral Access: If you are granting a contractor or temporary script access to run reports, you can pass an
expires_atISO datetime. Once the timestamp is reached, Truto's backend physically deletes the server configuration and KV tokens via durable object alarms, terminating access instantly.
Architecting the Future of Analytics
Connecting Google Analytics to ChatGPT via a managed MCP server removes the friction between human curiosity and raw data. You bypass the clunky UI dashboards and rigid custom report builders, enabling your team to query, analyze, and provision analytics infrastructure using natural language.
By offloading the complexities of GA4's hierarchical data model, dimension compatibility rules, and OAuth lifecycles to Truto, your engineering team can focus on building intelligent agent workflows instead of maintaining brittle API plumbing.
FAQ
- Can ChatGPT run real-time Google Analytics reports?
- Yes. By using a Model Context Protocol (MCP) server connected to the Google Analytics Data API, ChatGPT can execute the google_analytics_realtime_report_run tool to fetch live traffic metrics and dimension combinations.
- How does the MCP server handle Google Analytics rate limits?
- The Google Analytics API enforces strict property-level quotas. Truto normalizes upstream rate limit information into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset) and passes HTTP 429 Too Many Requests errors directly back to the caller. The AI agent or client framework must implement its own exponential backoff and retry logic.
- Do I need to hardcode specific dimensions and metrics for ChatGPT?
- No. ChatGPT can use the google_analytics_compatibility_check tool to dynamically verify which dimensions and metrics can be combined before running a report, preventing bad API requests.
- Can I restrict the AI agent to read-only access?
- Yes. When generating the MCP server in Truto, you can apply method filtering (e.g., methods: ['read']) to ensure the AI agent can only execute GET or list operations, preventing it from deleting properties or modifying data streams.