
Gtm Ga4
io.github.mharnett由 GitHub 帳號 mharnett 發布v1.0.1更新於 Oct 25, 2026
GTM + GA4 MCP: tag management, consent auditing, workspace versioning, reports.
概覽
本機 MCP 伺服器,讓助理管理 Google Tag Manager 的代碼、觸發條件和變數、稽核同意設定,並執行 GA4 報表。
- 可以做什麼
- 列出、讀取、建立和更新 GTM 代碼,並列出工作區中的觸發條件和變數。稽核所有代碼的同意設定合規性。預覽目前工作區並據此建立容器版本。執行 GA4 報表和即時報表,列出或建立 GA4 自訂維度。
- 適用情境
- 適合在使用 Google Tag Manager 和 GA4 時,讓助理檢查或修改容器設定、檢視同意設定,或直接取得分析報表,而不必切換到網頁主控台。
- 執行需求
- 透過 npm(npx mcp-gtm-ga4)或建置後的複本在本機執行,需要 Node.js。需在 GOOGLE_APPLICATION_CREDENTIALS 提供 Google 憑證 JSON 金鑰檔路徑(服務帳戶或授權使用者 OAuth),並設定 GTM_ACCOUNT_ID、GTM_CONTAINER_ID 和 GA4_PROPERTY_ID。選用 GTM_SANDBOX_WORKSPACE_ID 和 MCP_SERVER_NAME。需要連線至 Google API 的網路。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Gtm Ga4,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
mcp-gtm-ga4
MCP server for Google Tag Manager and GA4 -- tag management, consent auditing, workspace versioning, and analytics reporting via Claude.
Features
- 14 tools spanning GTM workspace management (tags, triggers, variables), consent compliance auditing, workspace preview/versioning, and GA4 reporting
- 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
Or clone and 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.
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:
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):
tagmanager.readonly is intentionally not requested — the edit scopes already grant read access.
Usage
Claude Code (.mcp.json)
npx
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_update_tag, gtm_create_tag, gtm_preview, 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
GTM Tags
GTM Structure
GTM Consent
GTM Workspace
GA4 Reports
GA4 Admin
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
來源:README.md,提交 539cc67
工具
0版本歷史
1- v1.0.1最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分