gtm-ga4-mcp
Interact with Google Analytics 4 properties, including account summaries, property configuration, custom dimensions and metrics, data streams, key events, and running standard or realtime reports.
Manage Google Tag Manager entities such as accounts, containers, workspaces, tags, triggers, variables, templates, versions, environments, and permissions, with read, write, and destructive capabilities.
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., "@gtm-ga4-mcp List all GTM accounts and containers, then show yesterday's GA4 traffic by source."
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.
gtm-ga4-mcp
An MCP server for Google Tag Manager + Google Analytics 4 with tiered safety controls.
Existing servers cover slices of this surface: Google's official GA4 server is read-only, and GTM servers expose the API without a safety model. gtm-ga4-mcp is built for the full surface — read, write, and admin operations — with safeguards you opt into deliberately.
The safety model
Every tool belongs to a tier. Higher tiers are off by default and enforced twice:
Tier | Examples | Default | Enable with |
Read | list, get, reports, metadata | ✅ on | — |
Write | create/update tags, triggers, custom dimensions | ❌ off |
|
Destructive | delete, publish, user permissions | ❌ off |
|
Registration gate — tools above your tier are never registered, so they're invisible to the model (not just erroring at call time).
Token gate — the OAuth scopes requested from Google are derived from the same tier. A read-only process asks for
tagmanager.readonly+analytics.readonlyand holds a token that cannot mutate anything, even if the application code misbehaves.
Individual tools can also be disabled by name: --deny gtm_get (repeatable) or GTM_GA4_MCP_DENY=tool_a,tool_b.
Beyond the two gates, mutations carry their own guards:
Write tools default to dry-run — they echo the exact API request without sending it; execution requires an explicit
dry_run: false.Destructive tools are two-phase — the first call changes nothing and returns a one-time
confirm_tokenplus a plain-language summary; only a second call with that token executes. Tokens are fingerprinted to the exact operation (a confirmation for deleting tag X can never authorize deleting tag Y), single-use, and expire in 10 minutes. This follows the Multi Round-Trip Requests pattern from MCP spec 2026-07-28 and works on every client.Blast-radius exclusions — accounts, containers, and GA4 properties can never be deleted through this server, by design.
Related MCP server: Google Tag Manager MCP Server
Tools
Read tier (always on):
Tool | What it does |
| List GTM entities level by level (accounts → containers → workspaces → tags/triggers/variables/templates/permissions/…), trimmed summaries |
| Full JSON for one GTM entity by path (including container versions) |
| Every GA4 account + property you can access — the entry point |
| One property's full configuration |
| Data streams, key events, custom dimensions/metrics, Ads/Firebase links |
| GA4 report over a date range, rows as clean dicts |
| Last-30-minutes activity (verify events are firing) |
| Discover dimension/metric API names (standard + custom), searchable |
Write tier (--allow-write), all dry-run by default:
Tool | What it does |
| Create tags, triggers, variables, folders, templates, clients, transformations, zones, workspaces, environments |
| Replace a GTM entity (full-body update with optional optimistic-lock fingerprint) |
| Create custom dimensions/metrics, key events, data streams |
| Patch GA4 entities or property settings (partial update via update mask) |
Destructive tier (--allow-destructive), all two-phase confirmed:
Tool | What it does |
| Delete workspace entities, workspaces, versions, environments (never accounts/containers) |
| Compile a workspace into a version and publish it LIVE (aborts on compile errors) |
| Grant / update / revoke GTM account access |
| Archive custom dimensions/metrics, delete key events/data streams (never properties) |
Design choices worth knowing: ~8 consolidated tools instead of ~120 endpoint wrappers (smaller agent context, deterministic alphabetical ordering for prompt caching), list results are trimmed summaries with gtm_get for deep dives, and all GTM calls flow through a rate limiter tuned to the GTM API's ~15 requests/minute default quota with backoff on 429/5xx.
Setup
1. Enable APIs in a Google Cloud project: Tag Manager API, Analytics Admin API, Analytics Data API.
2. Authenticate with Application Default Credentials. Log in with the scopes matching the tier you run — this is the token-level gate, so a read-only login is a hard guarantee:
Read-only (default):
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/tagmanager.readonly,https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platformEverything, for a full read/write/destructive session:
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/tagmanager.readonly,https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/tagmanager.edit.containers,https://www.googleapis.com/auth/tagmanager.edit.containerversions,https://www.googleapis.com/auth/analytics.edit,https://www.googleapis.com/auth/tagmanager.delete.containers,https://www.googleapis.com/auth/tagmanager.publish,https://www.googleapis.com/auth/tagmanager.manage.users,https://www.googleapis.com/auth/cloud-platform3. Add the server. Claude Code (read-only):
claude mcp add gtm-ga4 -- uvx --from git+https://github.com/kb223/gtm-ga4-mcp gtm-ga4-mcpAppend --allow-write or --allow-destructive to that command to enable higher tiers.
Or any MCP client via .mcp.json / Claude Desktop config:
{
"mcpServers": {
"gtm-ga4": {
"command": "uvx",
"args": ["--from", "git+https://github.com/kb223/gtm-ga4-mcp", "gtm-ga4-mcp"]
}
}
}PyPI package coming with v1.0 (uvx gtm-ga4-mcp).
"This app is blocked" during login
Google blocks Tag Manager / Analytics scopes on gcloud's shared default OAuth client, so the plain gcloud auth application-default login above may fail with "This app tried to access sensitive info in your Google Account." The fix — same as Google documents for their own analytics-mcp — is a two-minute OAuth client of your own:
In a Google Cloud project with the three APIs enabled, open APIs & Services → OAuth consent screen: user type External, publishing status Testing, and add your own Google account as a test user.
APIs & Services → Credentials → Create Credentials → OAuth client ID → Desktop app, then download the client JSON.
Re-run the login with your client:
gcloud auth application-default login --client-id-file=path/to/client_secret.json --scopes=<same scopes as above>Heads-up: while the consent screen is in Testing mode, Google expires the refresh token after ~7 days, so expect to re-run the login weekly (or publish the app and click through the unverified-app warning).
Try it
Ask your agent things like:
"List my GTM accounts, then show me every tag in the main container's default workspace."
"Which GA4 properties do I have access to, and what custom dimensions does property 123456 define?"
"Run a report on sessions and conversions by default channel group for the last 28 days."
"Is the
purchaseevent firing right now?"(write tier) "Create a
lead_typeevent-scoped custom dimension on property 123456." — you'll see the dry-run payload first(destructive tier) "Delete the paused tag called Old Pixel." — you'll get a summary + confirmation token before anything happens
Development
uv sync
uv run pytest
uv run ruff check .
npx @modelcontextprotocol/inspector uv run gtm-ga4-mcp # interactive testingCI runs the test suite plus an MCP Inspector CLI smoke test (tools/list over stdio, no credentials needed).
Roadmap
v0.2 — write tier✅ shippedv0.3 — destructive tier✅ shippedv1.0: PyPI, MCP registry listing, MCPB bundle
License
MIT
Available Tools
8 toolsga4_account_summariesARead-onlyIdempotent
List every GA4 account and property the authenticated user can access.
This is the entry point for all GA4 work — it returns the property IDs the other ga4_* tools need.
Inputs: page_token. Returns: object
ga4_admin_listARead-onlyIdempotent
List a GA4 property's sub-entities.
Covers data streams, key events, custom dimensions/metrics, Google Ads links, and Firebase links.
Inputs: entity_type (required), property_id (required), page_token. Returns: object
ga4_metadataARead-onlyIdempotent
List the dimension/metric API names available on a property (standard + custom).
Use this before ga4_run_report to find exact API names.
Inputs: property_id (required), search. Returns: object
ga4_property_getARead-onlyIdempotent
Fetch one GA4 property's full configuration (timezone, currency, industry, service level).
Inputs: property_id (required). Returns: object
ga4_run_realtime_reportARead-onlyIdempotent
Run a GA4 realtime report (last 30 minutes) — e.g. to verify events are firing now.
Inputs: metrics (required), property_id (required), limit, dimensions. Returns: object
ga4_run_reportARead-onlyIdempotent
Run a GA4 report over a date range and return one dict per row.
Rows are keyed by the requested dimension/metric API names. row_count is
the total available on the server; raise limit or refine dimensions if
rows were truncated.
Inputs: metrics (required), property_id (required), limit, end_date, +2 more. Returns: object
gtm_getARead-onlyIdempotent
Fetch one GTM entity's complete JSON by its path (tag, trigger, variable, version, ...).
Note: fetching a version returns the entire published container (large).
Inputs: path (required). Returns: object
gtm_listARead-onlyIdempotent
List Google Tag Manager entities one hierarchy level at a time.
Returns trimmed summaries (path, name, type, IDs) to keep context small;
each item's path feeds gtm_get (full detail) or a deeper gtm_list call.
Inputs: entity_type (required), full, parent, page_token. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
The GA4 and GTM tools are clearly separated by prefix and purpose. Within GA4, account discovery, property config, metadata, admin listing, and reporting are mostly distinct; the only slight overlap is between ga4_metadata and ga4_admin_list for custom dimensions/metrics.
All names use snake_case and share the ga4_/gtm_ prefixes, but the verb-noun pattern is inconsistent: some are noun phrases like ga4_account_summaries and ga4_metadata, while others are verb-led like ga4_run_report and gtm_get. This is readable but not a single predictable convention.
Eight tools is a reasonable size for a combined GA4+GTM server, and each tool covers a distinct read/query operation. The GTM side is slightly thin at only two tools, but the overall count is not excessive.
The GA4 surface covers discovery, property configuration, admin entity listing, metadata, standard reporting, and realtime reporting, which supports common analytics workflows. GTM is limited to get/list operations, so deeper management features are missing, but the server appears intentionally read-query oriented.
Related MCP Connectors
Manage Google, Meta, TikTok, Snapchat and LinkedIn ads, plus GA4, Tag Manager and Search Console, by chat from Claude or ChatGPT. Spend increases need your confirmation first.
Let AI manage your Google Tag Manager containers — tags, triggers, variables, and more.
- AdCopilotDeprecatedcloud.adcopilot
Google Ads, GA4, Search Console and Tag Manager for AI assistants. Every change is proposed first.
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables comprehensive management of Google Tag Manager accounts, containers, workspaces, tags, triggers, and variables through OAuth2 authentication, allowing users to create, update, and publish GTM configurations via natural language.26MIT
- AlicenseNot gradedqualityAmaintenanceEnables interaction with Google Tag Manager through its API with built-in Google OAuth authentication. Allows managing GTM containers, tags, triggers, and variables through natural language.250Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables natural language management of Google Tag Manager accounts, containers, tags, triggers, variables, and versions, including creation, update, and publishing.16 PyPICreative Commons Zero v1.0 Universal
- FlicenseNot gradedqualityFmaintenanceEnables interaction with Google Tag Manager containers, tags, triggers, and variables through natural language, using OAuth authentication.-