ai-google-analytics-mcp
The ai-google-analytics-mcp server lets you provision, configure, and integrate Google Analytics 4 (GA4) into local AI/web projects — from creating GA4 properties to injecting tracking code into HTML files.
Authentication & Setup
Get step-by-step GCP/GA4 authentication instructions (gcloud ADC or service account setup)
Check integration status of optional launcher registry and keymaster hooks
Account & Property Discovery
List all GA account summaries and their child properties (read-only Admin API)
Property & Stream Provisioning
Create a new GA4 property under a specified account (configurable timezone, currency, environment)
Create a web data stream for a GA4 property and retrieve its Measurement ID (
G-XXXXXXXX)
Tracking Code Generation & Injection
Render an HTML
gtagsnippet for a given Measurement IDInject or update a
gtagsnippet directly into local HTML or layout files (with dry-run preview support)Generate a Next.js
GoogleAnalytics.tsxclient component (envorinlinemode, optional cookie consent gating)Scaffold full GA4 integration for a Next.js app: write the component, wire it into
layout.tsx, and configure.env.local
Project Configuration
Save a
.ga4.config.jsonfile in a project root for future agent/human referenceRun an end-to-end provisioning workflow: create property + stream, optionally save config, inject gtag, and sync to registry — all in one call
Registry Integration
List projects from a launcher registry with hints about existing GA4 config and keymaster status
Resolve a registry slug or filesystem path to get website URL, web roots, and agent hints
Sync GA4 metadata (Measurement ID, property ID, etc.) back to a launcher registry project entry (requires writable env)
Provisions Google Analytics 4 properties and web data streams, creates measurement IDs, injects gtag snippets into HTML, and configures GA4 tracking for web projects.
Scaffolds Google Analytics 4 tracking components for Next.js applications, including component files and layout wiring.
Click on "Install 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., "@ai-google-analytics-mcpSet up GA4 for my project at https://example.com"
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.
ai-google-analytics-mcp
MCP server to provision Google Analytics 4 for local AI/web projects: create properties and web data streams, capture measurement IDs, inject gtag into HTML, and write .ga4.config.json in project roots.
For reporting and monitoring, use Google's official read-only analytics-mcp alongside this server (see CONTEXT.md).
Tools
Tool | Purpose |
| gcloud ADC + API enablement steps |
| Discover accounts/properties (readonly Admin API) |
| Create GA4 property under an account |
| Create web stream → |
| HTML snippet for a measurement ID |
| Patch a local HTML/layout file |
| Next.js |
| Write component, wire |
| Write |
| Property + stream + optional config/inject (+ optional |
| Filesystem inventory of |
| Registry projects missing GA4 config/metadata |
| Recommend html vs nextjs wiring for a repo |
| Pair with official read-only |
| Whether launcher/keymaster hooks are configured |
| Registry projects + |
| Slug and/or path → website_url, web roots, agent hints |
| Write |
Optional: launcher registry & keymaster
Public-repo safe: no hardcoded paths, no imports from sibling repos. Set env on your MCP host only if you use these services:
GA4_LAUNCHER_REGISTRY_JSON— read launcherregistry.json(same format as launcher-project-registry)GA4_LAUNCHER_REGISTRY_WRITABLE=true— allowsync_ga4_to_launcher_registry/registry_slugon provisionGA4_KEYMASTER_DATABASEorGA4_KEYMASTER_HINTS=true— status hints only; secrets stay in keymaster MCP (keymaster_register_keyfor GA service accounts). Measurement IDs remain in.ga4.config.json.
See docs/adr/0003-optional-registry-keymaster-hooks.md.
Related MCP server: MCP Google Analytics Server
Quick start
cd /path/to/ai-google-analytics-mcp
uv sync
uv run pytest -q
uv run ga4-provision-mcpAuthentication
Full walkthrough: Google Analytics GA4 Service Account Setup Guide — GCP project, enable Admin (and optional Data) API, create a service account, grant GA account access, and point GOOGLE_APPLICATION_CREDENTIALS at the JSON key.
If gcloud auth application-default login shows "This app is blocked", use a service account (recommended): see also research/notes/gcloud-this-app-is-blocked.md.
# After SA JSON is on disk and SA email has Editor on your GA account:
export GOOGLE_APPLICATION_CREDENTIALS=~/.config/ga4/ga4-provisioner-sa.jsonCopy .env.example → .env and set GOOGLE_APPLICATION_CREDENTIALS + optional GA4_DEFAULT_ACCOUNT_ID.
Hermes / MCP config (stdio)
# ~/.hermes/config.yaml (example)
mcp_servers:
ga4_provision:
command: uv
args:
- run
- --directory
- /path/to/ai-google-analytics-mcp
- ga4-provision-mcpCompanion (read-only reports):
google_analytics:
command: pipx
args: ["run", "analytics-mcp"]
env:
CLOUDSDK_CORE_PROJECT: your-gcp-project-idAgent workflow example
"Provision GA4 for this repo: production URL https://my-app.example, inject into
public/index.html, save config in project root."
The agent calls provision_project_ga4_setup with project_dir and inject_html_path.
Docs
SECURITY.md — transport (stdio), trust model, credentials, safe deployment
google-analytics-ga4-service-account-setup-guide.md — step-by-step Google Cloud + GA4 + service account setup
CONTEXT.md— rules and architectureHERMES.md— agent smoke + guardrailsdocs/adr/— durable decisionsresearch/— external references (official analytics-mcp, etc.)BRIEF.md— original Gemini conversation blueprint
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/HappyMonkeyAI/ai-google-analytics-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server