GA4 Analytics MCP
Allows querying Google Analytics 4 properties, including listing properties, retrieving metadata for dimensions and metrics, running historical reports, and accessing real-time data (last ~30 minutes).
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GA4 Analytics MCPHow many users did I have yesterday?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
GA4 Analytics MCP
Personal Google Analytics 4 connector for Claude.ai Custom Connectors, hosted on Google Cloud Run.
Claude.ai Custom Connector
→ https://ga4-mcp-xxxxx-uc.a.run.app/ga4mcp
→ Cloud Run
→ Google Analytics Data API
→ your GA4 propertiesThere is no local stdio server, no npx requirement, and no claude_desktop_config.json.
Two authentication layers stay separate:
Claude → MCP: MCP OAuth (CIMD / DCR)
MCP → Google: Google OAuth refresh token stored in
GOOGLE_REFRESH_TOKEN
MCP tools
Tool | Purpose |
| Discover properties on the connected Google account |
| List valid dimensions and metrics |
| Historical GA4 reports |
| Last ~30 minutes |
Related MCP server: GA4 MCP Server
Local development
npm install
copy .env.example .env.localFill in .env.local, then:
npm run devApp:
http://localhost:3000MCP:
http://localhost:3000/ga4mcpGoogle OAuth:
http://localhost:3000/oauth/googleHealth:
http://localhost:3000/health
npm test
npm run buildClaude.ai cannot reach localhost. Deploy to Cloud Run before adding the Custom Connector.
Google Cloud setup (one project)
Use the same Google Cloud project for APIs, OAuth, and Cloud Run.
1. Install and sign in
Install the Google Cloud SDK.
Run:
gcloud auth login
gcloud auth application-default loginCreate or select a project in Google Cloud Console.
gcloud config set project YOUR_PROJECT_ID2. Enable APIs
.\scripts\cloud-run-setup.ps1 -ProjectId YOUR_PROJECT_ID -Region us-central1This enables:
Cloud Run
Cloud Build
Artifact Registry
Google Analytics Data API
Google Analytics Admin API
Or enable them in Console: APIs & Services → Library.
3. OAuth consent and web client
This Google OAuth client is only so Cloud Run can read your GA4 data. It is not the Claude.ai Advanced Settings client.
Open APIs & Services → OAuth consent screen.
User type: External for a personal Gmail account.
App name:
GA4 MCP.Add yourself as a test user if you stay in Testing.
Publish to Production so refresh tokens do not expire after 7 days.
Create OAuth client ID credentials.
Application type: Web application.
Authorized redirect URIs (add both):
http://localhost:3000/oauth/google/callbackhttps://ga4-mcp-XXXXXXXX-uc.a.run.app/oauth/google/callback
(use the real Cloud Run URL after the first deploy)
Scope used by this app:
https://www.googleapis.com/auth/analytics.readonlyCopy the client ID and client secret. Do not commit them.
The Google account you authorize must already have access to the GA4 properties Claude should query.
Deploy to Cloud Run
Default service name: ga4-mcp. Default region: us-central1.
.\scripts\cloud-run-deploy.ps1 -ProjectId YOUR_PROJECT_ID -Region us-central1The script prints:
https://ga4-mcp-XXXXXXXX-uc.a.run.app
https://ga4-mcp-XXXXXXXX-uc.a.run.app/ga4mcp
https://ga4-mcp-XXXXXXXX-uc.a.run.app/health
https://ga4-mcp-XXXXXXXX-uc.a.run.app/oauth/google/callbackThe service is deployed allow unauthenticated. That is required. Claude.ai connects from Anthropic (160.79.104.0/21). Auth is MCP_AUTH_TOKEN / MCP OAuth, not Cloud Run IAM.
Set environment variables
.\scripts\cloud-run-set-env.ps1 `
-ProjectId YOUR_PROJECT_ID `
-AppBaseUrl "https://ga4-mcp-XXXXXXXX-uc.a.run.app" `
-GoogleClientId "....apps.googleusercontent.com" `
-GoogleClientSecret "...." `
-McpAuthToken "a-long-random-string"Then add the Cloud Run callback URL to the Google OAuth client if you have not already.
Connect Google
Open
https://ga4-mcp-XXXXXXXX-uc.a.run.app/oauth/googleEnter
MCP_AUTH_TOKENSign in with your Google account
Copy
GOOGLE_REFRESH_TOKENfrom the success pageSet it and let Cloud Run start a new revision:
.\scripts\cloud-run-set-env.ps1 `
-ProjectId YOUR_PROJECT_ID `
-AppBaseUrl "https://ga4-mcp-XXXXXXXX-uc.a.run.app" `
-GoogleClientId "....apps.googleusercontent.com" `
-GoogleClientSecret "...." `
-McpAuthToken "a-long-random-string" `
-GoogleRefreshToken "1//...."Cloud Run cannot write env vars from inside the container. Same rule as any serverless host.
Confirm the service
https://ga4-mcp-XXXXXXXX-uc.a.run.app/healthmust return:
{"status":"ok"}Environment variables
Variable | Required | Purpose |
| Yes | Cloud Run origin, no trailing slash |
| Yes | Google OAuth web client |
| Yes | Google OAuth web client secret |
| No | Defaults to |
| Yes | Operator setup token for Google OAuth and Claude MCP consent |
| After Google OAuth | Long-lived Google token |
| No | Signs Google OAuth state cookies |
| No | Signs MCP JWTs. Defaults to |
| No | Only for Claude.ai Advanced Settings confidential client |
| No | Pair for that optional client |
Set these on the Cloud Run service. Do not put them in Git.
Optional Console path: Cloud Run → ga4-mcp → Edit & deploy new revision → Variables & secrets.
Claude.ai Custom Connector
Confirm
/healthreturns{"status":"ok"}.Finish Google OAuth and set
GOOGLE_REFRESH_TOKEN.In Claude.ai open Customize → Connectors → Add custom connector.
Name:
GA4 AnalyticsURL:
https://ga4-mcp-XXXXXXXX-uc.a.run.app/ga4mcpLeave Advanced OAuth Client ID / Secret empty.
Click Add.
Enable the connector in + → Connectors.
The first GA4 tool call shows Connect. Enter
MCP_AUTH_TOKENon this app’s consent page (not your Google password).Ask: How many users did I have yesterday?
Manual gcloud (if you do not want the scripts)
gcloud artifacts repositories create ga4-mcp --repository-format=docker --location=us-central1
gcloud builds submit --config cloudbuild.yaml --substitutions=_REGION=us-central1
gcloud run services describe ga4-mcp --region us-central1 --format="value(status.url)"
gcloud run services update ga4-mcp --region us-central1 --update-env-vars APP_BASE_URL=https://...,GOOGLE_CLIENT_ID=...,GOOGLE_CLIENT_SECRET=...,GOOGLE_REDIRECT_URI=https://.../oauth/google/callback,MCP_AUTH_TOKEN=...Security
Never log Google tokens, authorization codes, client secrets, or MCP JWTs.
MCP tools never return secrets.
Only
GOOGLE_REFRESH_TOKENis persisted, as a Cloud Run env var.Cloud Run ingress is public so Claude can connect. Do not also put a Cloud IAP / IAM login in front of
/ga4mcp.Generate a long random
MCP_AUTH_TOKEN.
Dates
Passed to GA4 unchanged: today, yesterday, 7daysAgo, 30daysAgo, 90daysAgo, or YYYY-MM-DD. The date dimension comes back as YYYYMMDD.
Known limitations
One Google account and one refresh token.
Cloud Run cannot persist a file or mutate env vars at runtime; set
GOOGLE_REFRESH_TOKENand deploy a new revision.Google Testing-mode refresh tokens expire after about 7 days.
Realtime data is roughly the last 30 minutes.
Report size is capped at 10,000 rows.
Cold starts can add a few seconds when
min-instancesis 0.
Files added for Cloud Run
File | Purpose |
| Production Next.js standalone image |
| Build image and deploy Cloud Run |
| Enable APIs and Artifact Registry |
| Build and deploy |
| Set Cloud Run env vars |
This server cannot be deployed
Maintenance
Related MCP Connectors
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
Connect Google Analytics to ChatGPT. Query GA4 data in plain English and get instant insights.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
GA4, Google Ads and Search Console in Claude. Read-only OAuth, multi-account for agencies.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables LLM applications to query Google Analytics 4 data through standard MCP interfaces, supporting real-time data, custom reports, and metadata discovery.5371MIT
- AlicenseAqualityBmaintenanceConnects MCP clients like Claude Desktop to Google Analytics 4 Data API, enabling natural language queries for reports, top pages, traffic sources, conversions, realtime users, and period comparisons.7MIT
- AlicenseNot gradedqualityDmaintenanceEnables querying Google Analytics 4 data using natural language through MCP clients like Claude and Cursor, supporting 200+ dimensions and metrics for traffic, user behavior, and e-commerce analysis.MIT
- AlicenseAqualityBmaintenanceEnables querying Google Analytics 4 properties using natural language through MCP clients. Supports customizable reports with any dimensions and metrics, listing properties, and real-time data.4MIT