mcp-gtm-ga4
MCP server for Google Tag Manager + GA4 - tag management, consent auditing, workspace versioning, and analytics via Claude
Install / Use
claude mcp add mharnett -- npx -y github:mharnett/mcp-gtm-ga4If the server publishes to npm under a different name, use that package instead — check the repo README.
MCP Server
Model Context Protocol server
Quality Score
Category
AutomationSupported Platforms
Tags
Our assessment of mcp-gtm-ga4
mcp-gtm-ga4 scores 74/100 on our quality scale, 2502nd of 2,728 Automation skills we index.
Its MCP Server is 10 KB long, well organised into 30 sections with 8 code examples: a thorough specification that gives an agent plenty to work with.
It has 3 GitHub stars, so there is little community track record yet; judge it on its content.
Maintenance, license and trust
- The repository was last updated 3 days ago, so mcp-gtm-ga4 is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 92/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
mcp-gtm-ga4 compared with similar skills
All 4 of these similar skills score higher than mcp-gtm-ga4; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| mcp-gtm-ga4 (this skill)by mharnett | 74 | 3 | 3d ago | MCP Server |
| Agent-Reachby Panniantong | 100 | 115.5k | 3d ago | CLAUDE.md |
| hyperframesby heygen-com | 100 | 91.7k | today | CLAUDE.md |
| rufloby ruvnet | 100 | 82.6k | today | CLAUDE.md |
| headroomby headroomlabs-ai | 100 | 81.0k | today | CLAUDE.md |
Frequently asked questions
- How do I install mcp-gtm-ga4?
- Run
claude mcp add mharnett -- npx -y github:mharnett/mcp-gtm-ga4. The install tabs above show the steps for each supported agent. - Which AI agents does mcp-gtm-ga4 work with?
- It is written for Claude Code and Claude Desktop, as a MCP Server file. Other agents that read the same format can often use it too.
- Is mcp-gtm-ga4 safe to use?
- It is MIT-licensed and scores 92/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is mcp-gtm-ga4 still maintained?
- The repository was last updated 3 days ago, so mcp-gtm-ga4 is actively maintained.
Skill content
View source on GitHubmcp-gtm-ga4
MCP server for Google Tag Manager and GA4 -- tag management, consent auditing, workspace versioning, and analytics reporting via Claude.
Quick install
Claude Code, one line (replace the placeholder values with your own; see Configuration and Authentication for how to get them):
claude mcp add --env GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json --env GTM_ACCOUNT_ID=YOUR_GTM_ACCOUNT_ID --env GTM_CONTAINER_ID=YOUR_GTM_CONTAINER_ID --env GA4_PROPERTY_ID=YOUR_GA4_PROPERTY_ID --transport stdio mcp-gtm-ga4 -- npx -y mcp-gtm-ga4
All write operations are sandbox-checked: the server refuses to write to a workspace that is not the resolved sandbox workspace.
<details> <summary>Claude Desktop</summary>Add this to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS), then fully quit and restart Claude Desktop:
{
"mcpServers": {
"mcp-gtm-ga4": {
"command": "npx",
"args": ["-y", "mcp-gtm-ga4"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/credentials.json",
"GTM_ACCOUNT_ID": "YOUR_GTM_ACCOUNT_ID",
"GTM_CONTAINER_ID": "YOUR_GTM_CONTAINER_ID",
"GA4_PROPERTY_ID": "YOUR_GA4_PROPERTY_ID"
}
}
}
}
</details>
<details>
<summary>Codex CLI</summary>
Add this to ~/.codex/config.toml:
[mcp_servers.mcp-gtm-ga4]
command = "npx"
args = ["-y", "mcp-gtm-ga4"]
[mcp_servers.mcp-gtm-ga4.env]
GOOGLE_APPLICATION_CREDENTIALS = "/path/to/credentials.json"
GTM_ACCOUNT_ID = "YOUR_GTM_ACCOUNT_ID"
GTM_CONTAINER_ID = "YOUR_GTM_CONTAINER_ID"
GA4_PROPERTY_ID = "YOUR_GA4_PROPERTY_ID"
</details>
Features
- 18 tools (11 read, 7 write-gated) spanning GTM workspace management (tags, triggers, variables), consent compliance auditing, workspace preview/versioning, and GA4 reporting. The server starts read-only; set
GTM_GA4_MCP_WRITE=trueto expose the 7 write tools (gtm_create_tag,gtm_update_tag,gtm_create_variable,gtm_update_variable,gtm_delete_variable,gtm_create_version,gtm_ga4_create_custom_dimension) - Sandbox safety -- all write operations verify they target the resolved workspace, refusing to write to non-sandbox workspaces
- Multi-client support -- configure per-client via environment variables
- Auto-detects Default Workspace ID -- no need to manually specify workspace IDs unless using a custom sandbox
Installation
npm install mcp-gtm-ga4
Or clone and build:
git clone https://github.com/mharnett/mcp-gtm-ga4.git
cd mcp-gtm-ga4
npm install
npm run build
Configuration
Security: Never share your .mcp.json file or commit it to git -- it may contain API credentials. Add .mcp.json to your .gitignore.
Runtime configuration is via environment variables.
| Variable | Required | Description |
|---|---|---|
| GOOGLE_APPLICATION_CREDENTIALS | Yes | Path to a Google credential JSON key file (service account or authorized-user — see Authentication below) |
| GTM_ACCOUNT_ID | Yes | GTM account ID |
| GTM_CONTAINER_ID | Yes | GTM container ID |
| GA4_PROPERTY_ID | Yes | Numeric GA4 property ID (123456789 or properties/123456789), not the G- measurement ID |
| GTM_SANDBOX_WORKSPACE_ID | No | Override workspace ID (auto-detects Default Workspace if omitted) |
| MCP_SERVER_NAME | No | Server name (defaults to package name mcp-gtm-ga4) |
See config.example.json for a reference template. The only value read from disk is oauth.scope (in an optional config.json) — the single source of truth for the OAuth scope the onboarding paths request. If no config.json is present, the committed minimum scope is used.
Authentication
This MCP supports two auth models. Both feed the same GOOGLE_APPLICATION_CREDENTIALS runtime path.
Precedence & mechanism
There is no runtime service-account-vs-OAuth toggle. Both models converge on a
single slot — GOOGLE_APPLICATION_CREDENTIALS — which the runtime hands to
GoogleAuth({ keyFile }). Whichever file you point that env var at is the
credential:
- a service-account JSON key (option 1 below), or
- the
authorized_userkeyfile theauthsubcommand writes (option 2) — a file that plugs into the exact same slot.
So the only real precedence rule is failure handling: an explicitly-configured
keyfile is used; when GOOGLE_APPLICATION_CREDENTIALS is unset the server fails
loudly at startup with an onboarding error naming both the service-account path
and the auth OAuth helper. It deliberately does not fall back to Google's
Application Default Credentials (gcloud user creds / GCE metadata server) — no
silent machine-local default, no silent runtime failover.
1. Service account (primary, recommended for unattended/server use)
Create a service account in your GCP project, download its JSON key, grant it the
GTM container role (on the target GTM container) and GA4 property access, and
point GOOGLE_APPLICATION_CREDENTIALS at the key file. No OAuth flow, no browser,
no refresh token. This is the recommended path for headless/server/unattended
deployments.
2. User OAuth (interactive, for users without a service account)
If you can't use a service account, mint a user credential with your own Google OAuth client (a "Desktop app" OAuth 2.0 Client ID created in your own GCP project — enable the Tag Manager API and the Google Analytics Admin + Data APIs). Two equivalent onboarding commands, both hardened with PKCE (RFC 7636, S256) and both requesting the scope from config.json (oauth.scope) so they never drift:
export GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
export GOOGLE_CLIENT_SECRET=your-client-secret
# Option A: write an authorized_user credential file directly
node dist/index.js auth --output ./gtm-ga4-credentials.json
# then set GOOGLE_APPLICATION_CREDENTIALS=./gtm-ga4-credentials.json
# Option B: the standalone helper (prints GOOGLE_REFRESH_TOKEN + a ready-to-save
# authorized_user JSON you can write to a file for GOOGLE_APPLICATION_CREDENTIALS)
node get-refresh-token.cjs
The refresh token / credential is written by you and read from your environment only. Nothing is shared and no OAuth client keyfile is bundled. Do not run the helper with stdout redirected to a shared log — the refresh token is printed to stdout by design.
OAuth scopes requested
The onboarding paths request exactly the scopes this MCP's tools use (from config.example.json → oauth.scope):
| Scope | Needed by |
|---|---|
| tagmanager.edit.containers | gtm_create_tag, gtm_update_tag, gtm_create_variable, gtm_update_variable, gtm_delete_variable, tag/trigger/variable reads |
| tagmanager.edit.containerversions | gtm_create_version |
| tagmanager.publish | gtm_create_version, gtm_preview (quick preview) |
| analytics.readonly | gtm_ga4_run_report, gtm_ga4_realtime_report, gtm_ga4_list_custom_dimensions |
| analytics.edit | gtm_ga4_create_custom_dimension |
tagmanager.readonly is intentionally not requested — the edit scopes already grant read access.
Usage
Claude Code (.mcp.json)
{
"mcpServers": {
"gtm-ga4": {
"command": "node",
"args": ["/path/to/mcp-gtm-ga4/dist/index.js"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json",
"GTM_ACCOUNT_ID": "1234567890",
"GTM_CONTAINER_ID": "9876543",
"GA4_PROPERTY_ID": "331956119"
}
}
}
}
npx
GTM_ACCOUNT_ID=1234567890 \
GTM_CONTAINER_ID=9876543 \
GA4_PROPERTY_ID=331956119 \
GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json \
npx mcp-gtm-ga4
Claude Desktop: Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows).
Safety
Workspace sandbox protection
All write operations (gtm_create_tag, gtm_update_tag, gtm_create_variable, gtm_update_variable, gtm_delete_variable, gtm_create_version) verify they target the resolved workspace before executing. If a request attempts to write to a different workspace, the server returns a SafetyError and blocks the operation.
This prevents accidental production changes when the MCP server is configured against a sandbox workspace.
Tools
Status
| Tool | Description |
|---|---|
| gtm_get_client_context | Health check and status overview: GTM container path, workspace ID, GA4 property ID and server version |
GTM Tags
| Tool | Description |
|---|---|
| gtm_list_tags | List all tags in the workspace with consent status and firing triggers |
| gtm_get_tag | Get full tag configuration by tag ID |
| gtm_update_tag | Update an existing tag (merge patch via JSON) |
| gtm_create_tag | Create a new tag from a JSON definition |
GTM Structure
| Tool | Description |
|---|---|
| gtm_list_triggers | List all triggers (ID, name, type) |
| gtm_list_variables | List all variables (ID, name, type) |
| gtm_get_variable | Get full details of a single variable by ID |
| gtm_create_variable | Create a new variable in the sandbox workspace |
| gtm_update_variable | Update a variable (fetch, merge, save) in the sandbox workspace |
| gtm_delete_variable | Delete a variable from the sandbox workspace (destructive) |
GTM Consent
| Tool | Description |
|---|---|
| gtm_audit_consent | Audit all tags for consent configuration compliance |
GTM Workspace
| Tool | Description |
|---|---|
| gtm_preview | Generate a quick preview of the current workspace |
| gtm_create_version | Create a new container version from the workspace |
GA4 Reports
| Tool | Description |
|---|---|
| gtm_ga4_run_report | Run a GA4 report with dimensions, metrics, date range, and filters |
| gtm_ga4_realtime_report | Run a GA4 realtime report (last 30 minutes) |
GA4 Admin
| Tool | Description |
|---|---|
| gtm_ga4_list_custom_dimensions | List all custom dimensions for the property |
| gtm_ga4_create_custom_dimension | Create a new custom dimension |
Architecture
- GTM API:
googleapis(Tag Manager v2) - GA4 Data:
@google-analytics/data(BetaAnalyticsDataClient) - GA4 Admin:
@google-analytics/admin(AnalyticsAdminServiceClient) - Resilience:
cockatiel(retry, circuit breaker, timeout policies) - Logging:
pinowithpino-pretty - Transport: MCP SDK stdio transport
License
MIT
Author
Built by Mark Harnett / drak-marketing
Related Skills
Agent-Reach
115.5kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
hyperframes
91.7kOpen-source AI video editor: edit your own footage, or create and remake any video with Claude Code, Codex or the free Studio app. Write HTML, render MP4. By HeyGen.
ruflo
82.6k🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
headroom
81.0kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
