Google Analytics 4

io.github.stucchi由 GitHub 帳號 stucchi 發布v0.1.1更新於 Oct 24, 2026

Manage GA4 properties, data streams, conversions, and run reports via Admin & Data APIs.

已驗證STDIO僅桌面資料與分析商業與電商

概覽

AI 產生的概覽

針對 Google Analytics 4 的 MCP 伺服器,讓助理透過 Admin 與 Data API 管理 GA4 資源、資料串流與轉換,並執行報表。

可以做什麼
  • 檢查已設定服務帳戶的驗證狀態
  • 列出帳戶與資源,建立、檢視及軟刪除資源
  • 列出、建立與刪除網站資料串流,並產生 gtag.js 追蹤程式碼片段
  • 列出、建立與刪除關鍵事件(轉換)、自訂維度與自訂指標
  • 列出與建立 Google Ads 連結,取得或建立 Measurement Protocol 密鑰
  • 依維度、指標、日期與篩選條件執行報表與即時報表,並列出可用維度與指標
適用情境
適合讓助理為網站設定 GA4 追蹤、調整轉換或自訂維度,或在不開啟 GA4 介面的情況下取得工作階段、國家/地區與即時指標。
執行需求
以 PyPI 套件 google-analytics-4-mcp 在本機執行,通常透過 uvx 啟動,需要 Python 工具鏈。需要 Google Cloud 服務帳戶 JSON 金鑰,透過 GA_CREDENTIALS 或 GA_CREDENTIALS_PATH 提供;需在專案中啟用 Analytics Admin 與 Data API,並在 GA4 資源存取管理中將服務帳戶電子郵件加入為編輯者。
安裝前請注意
服務帳戶 JSON 金鑰是長期憑證,寫入 GA_CREDENTIALS 會存進 MCP 設定檔。README 要求編輯者權限,可建立與刪除資源、資料串流、轉換及 Ads 連結,助理的操作會改動線上分析設定;軟刪除資源或移除資料串流會影響資料收集。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Google Analytics 4,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Google Analytics 4 MCP Server

MCP server for Google Analytics 4 — create properties, configure data streams, manage conversions, and run reports via the Admin & Data APIs.

Setup (one-time, ~3 minutes)

  1. Google Cloud Console → IAM & Admin → Service Accounts

    • Create a service account (any name)
    • Click it → Keys → Add Key → JSON → Download
  2. Enable APIs in your GCP project:

  3. GA4 Admin → Property Access Management → Add the service account email (from the JSON) as Editor

  4. Configure credentials (pick one):

    • Option A (recommended): Copy the JSON content into the GA_CREDENTIALS env var in your MCP config
    • Option B: Save the file to ~/.google-analytics-4-mcp/credentials.json

Done. No browser flow, no consent screen, no tokens to refresh.

Installation

Claude Code

bash
claude mcp add google-analytics -e GA_CREDENTIALS='{"type":"service_account",...}' -- uvx google-analytics-4-mcp

Claude Desktop

Add to claude_desktop_config.json:

json
{  "mcpServers": {    "google-analytics": {      "command": "uvx",      "args": ["google-analytics-4-mcp"],      "env": {        "GA_CREDENTIALS": "{\"type\":\"service_account\",\"project_id\":\"...\", ...}"      }    }  }}

From source

bash
git clone https://github.com/stucchi/mcp-google-analytics.gitcd mcp-google-analyticsuv run google-analytics-4-mcp

Getting Started

  1. Check auth: Call check_auth_status to verify the service account is configured
  2. List accounts: Call list_accounts to see your GA4 accounts
  3. Setup a property: Use create_property → create_web_data_stream → get_tracking_snippet
  4. Query data: Use run_report with dimensions and metrics

Tools (23)

Auth

ToolDescription
check_auth_statusVerify service account is configured and valid

Admin API

ToolDescription
list_accountsList accessible GA4 accounts
list_propertiesList properties for an account
create_propertyCreate a GA4 property
get_propertyGet property details
delete_propertySoft-delete a property
list_data_streamsList data streams
create_web_data_streamCreate web stream → get Measurement ID
delete_data_streamDelete a data stream
get_tracking_snippetGenerate gtag.js HTML snippet
list_key_eventsList conversion events
create_key_eventMark event as conversion
delete_key_eventRemove conversion
list_custom_dimensionsList custom dimensions
create_custom_dimensionCreate custom dimension
list_custom_metricsList custom metrics
create_custom_metricCreate custom metric
list_google_ads_linksList Google Ads links
create_google_ads_linkLink Google Ads account
get_measurement_protocol_secretGet/create Measurement Protocol secret

Data API

ToolDescription
run_reportRun report with dimensions, metrics, dates, filters
run_realtime_reportReal-time active users and events
get_metadataList available dimensions and metrics

Environment Variables

VariableDefaultDescription
GA_CREDENTIALS—Service Account JSON key content (copy-paste the entire JSON)
GA_CREDENTIALS_PATH~/.google-analytics-4-mcp/credentials.jsonAlternative: path to the JSON key file

GA_CREDENTIALS takes priority over GA_CREDENTIALS_PATH.

Example Usage

You: "Set up Google Analytics for my website https://mcpadvisor.stucchi.consulting"
Assistant calls: list_accounts → create_property → create_web_data_stream → get_tracking_snippet
Result: Property created with Measurement ID G-XXXXXXXXXX and ready-to-paste HTML snippet.
You: "Show me the top 10 countries by sessions in the last 7 days"
Assistant calls: run_report(property_id="...", dimensions=["country"], metrics=["sessions"], start_date="7daysAgo", limit=10)

License

MIT

來源:README.md,提交 bb4b629

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.1最新Sep 16, 2026

評分

已滿足適用檢查項的 40%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

    請在儲存庫或註冊中心條目中宣告授權條款。