Skip to content
MCP server
Registry

gtm-ga4 MCP Server

GTM + GA4 MCP: tag management, consent auditing, workspace versioning, reports.

gtm-ga4 scores 68 (Good), licensed MIT and written in TypeScript. It installs as a local process. It declares 18 tools. Filed under Data and analytics. GitHub shows 3 stars. Package registries report about 290 downloads a week. Install configs are generated for 10 clients. Being listed in the registry is not the same as being vendor-official.

by mharnettMITTypeScript3 stars
Trust score
68Good
Trust score 68 of 100, Good

Good trust

68 of 100 from six public signals. Nobody can buy a point.

  • Listed in the official MCP registry.
  • OSI-style license: mit.
How we score trust
Scorecard

License, quality and maintenance

How grades work
Trust breakdown

Where the 68 comes from

22 + 20 + 2 + 10 + 4 + 10 = 68. Each factor is capped, so no single signal can carry a listing.

Registry22 / 30

Active in the official MCP registry, plus a known vendor namespace.

Registry: 22 of 30 points.
Maintenance20 / 20

How recently the repository saw a commit or release.

Maintenance: 20 of 20 points.
Popularity2 / 20

GitHub stars and weekly downloads, on a log scale.

Popularity: 2 of 20 points.
License10 / 10

A clear, OSI-style open-source license.

License: 10 of 10 points.
Security4 / 10

Not archived, a secure install path, a pinned version.

Security: 4 of 10 points.
Docs10 / 10

A real summary, a README with depth, listed tools.

Docs: 10 of 10 points.

Install

Pick your client, copy the config, paste it in.

Needs Cursor or VS Code installed on this device. The button opens the app and asks you to confirm before it adds the server.

~/Library/Application Support/Claude/claude_desktop_config.json
{  "mcpServers": {    "mharnett-mcp-gtm-ga4": {      "command": "npx",      "args": [        "-y",        "mcp-gtm-ga4@1.3.2"      ],      "env": {        "GOOGLE_APPLICATION_CREDENTIALS": "",        "GTM_ACCOUNT_ID": "",        "GTM_CONTAINER_ID": "",        "GA4_PROPERTY_ID": ""      }    }  }}

Environment variables

NameRequiredNotes
GOOGLE_APPLICATION_CREDENTIALSRequiredPath to service account JSON credentials file
GTM_ACCOUNT_IDRequiredGTM account ID
GTM_CONTAINER_IDRequiredGTM container ID
GA4_PROPERTY_IDOptionalGA4 property ID (numeric)

Tools18Tool docs quality grade C

All capabilities

About

mcp-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.

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"
      }
    }
  }
}

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"

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=true to 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.

VariableRequiredDescription
GOOGLE_APPLICATION_CREDENTIALSYesPath to a Google credential JSON key file (service account or authorized-user — see Authentication below)
GTM_ACCOUNT_IDYesGTM account ID
GTM_CONTAINER_IDYesGTM container ID
GA4_PROPERTY_IDYesNumeric GA4 property ID (123456789 or properties/123456789), not the G- measurement ID
GTM_SANDBOX_WORKSPACE_IDNoOverride workspace ID (auto-detects Default Workspace if omitted)
MCP_SERVER_NAMENoServer 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_user keyfile the auth subcommand 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):

ScopeNeeded by
tagmanager.edit.containersgtm_create_tag, gtm_update_tag, gtm_create_variable, gtm_update_variable, gtm_delete_variable, tag/trigger/variable reads
tagmanager.edit.containerversionsgtm_create_version
tagmanager.publishgtm_create_version, gtm_preview (quick preview)
analytics.readonlygtm_ga4_run_report, gtm_ga4_realtime_report, gtm_ga4_list_custom_dimensions
analytics.editgtm_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

ToolDescription
gtm_get_client_contextHealth check and status overview: GTM container path, workspace ID, GA4 property ID and server version

GTM Tags

ToolDescription
gtm_list_tagsList all tags in the workspace with consent status and firing triggers
gtm_get_tagGet full tag configuration by tag ID
gtm_update_tagUpdate an existing tag (merge patch via JSON)
gtm_create_tagCreate a new tag from a JSON definition

GTM Structure

ToolDescription
gtm_list_triggersList all triggers (ID, name, type)
gtm_list_variablesList all variables (ID, name, type)
gtm_get_variableGet full details of a single variable by ID
gtm_create_variableCreate a new variable in the sandbox workspace
gtm_update_variableUpdate a variable (fetch, merge, save) in the sandbox workspace
gtm_delete_variableDelete a variable from the sandbox workspace (destructive)

GTM Consent

ToolDescription
gtm_audit_consentAudit all tags for consent configuration compliance

GTM Workspace

ToolDescription
gtm_previewGenerate a quick preview of the current workspace
gtm_create_versionCreate a new container version from the workspace

GA4 Reports

ToolDescription
gtm_ga4_run_reportRun a GA4 report with dimensions, metrics, date range, and filters
gtm_ga4_realtime_reportRun a GA4 realtime report (last 30 minutes)

GA4 Admin

ToolDescription
gtm_ga4_list_custom_dimensionsList all custom dimensions for the property
gtm_ga4_create_custom_dimensionCreate 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: pino with pino-pretty
  • Transport: MCP SDK stdio transport

License

MIT

Author

Built by Mark Harnett / drak-marketing

Frequently asked questions

What is gtm-ga4 MCP Server?

GTM + GA4 MCP: tag management, consent auditing, workspace versioning, reports.

How do I install gtm-ga4 MCP Server in Claude Desktop, Cursor, or VS Code?

Pick your client in the Install section on this page and copy the generated config into the client's config file. Step-by-step guides: Claude Desktop, Cursor, and VS Code. gtm-ga4 MCP Server runs locally from the npm package mcp-gtm-ga4 with the command npx -y mcp-gtm-ga4@1.3.2.

Is gtm-ga4 MCP Server free and open source?

Yes. gtm-ga4 MCP Server is released under the MIT license, an OSI-approved open-source license, so you can use, modify, and self-host it under those terms.

Does gtm-ga4 MCP Server support remote (HTTP) connections?

No remote endpoint is listed for gtm-ga4 MCP Server. It runs locally on your machine over stdio, started by your MCP client.

What tools does gtm-ga4 MCP Server provide?

gtm-ga4 MCP Server provides 18 tools, including gtm_audit_consent, gtm_create_tag, gtm_create_variable, and gtm_create_version. See the full tool list for descriptions and parameters.

How is gtm-ga4 MCP Server's trust score calculated?

gtm-ga4 MCP Server scores 68 out of 100 (Good). The score adds six capped public signals: registry status, maintenance, popularity, license, documentation, and security. Nobody can pay for points. Read the methodology for the full formula.

Reviews

No reviews yet

—Be the first to review

5 star0 reviews at 5 stars
4 star0 reviews at 4 stars
3 star0 reviews at 3 stars
2 star0 reviews at 2 stars
1 star0 reviews at 1 stars

No published reviews yet. Used it? Tell the next person how it went.

Add badge to your README

Paste either snippet into the repository README. The image links to this listing.

Listed on MCPpedia

Top 5 MCP servers

Daily or weekly. Confirm by email, unsubscribe any time.

How often

Manage this listing

Claim this server