Google Analytics Mcp

io.github.surendranb由 GitHub 帳號 surendranb 發布v2.11.7更新於 Nov 3, 2026

GA4 MCP server for AI agents: schema discovery, server-side aggregation, analysis-ready defaults.

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

概覽

AI 產生的概覽

本機 MCP 伺服器,讓助理探索 GA4 資源的欄位結構,並以正確的維度與指標名稱執行 Google Analytics 4 報表。

可以做什麼
  • 探索欄位:依關鍵字搜尋維度與指標、瀏覽維度與指標分類,或取得完整資源結構。
  • 查詢資料:依日期範圍與筆數上限執行多維 GA4 報表,支援伺服器端彙總與總計。
  • 檢視資源:列出目前憑證可存取的 GA4 資源與帳戶。
  • 取得指引:擷取分析技能與操作手冊,以及針對設定、IAM 與欄位錯誤的疑難排解指南。
  • 修復設定:以互動方式處理缺少的資源 ID 或憑證問題,並檢查是否有新版本。
適用情境
適合讓助理根據 Google Analytics 4 回答網站或應用程式流量、管道、轉換與電商相關問題,並避免猜測在 Universal Analytics 停用後已改變的欄位名稱。也適合依手冊進行流量下滑診斷等分析。
執行需求
以 stdio 在本機執行,通常透過 uvx、npx 或 Python 模組啟動。需要以 GA4_PROPERTY_ID 提供資源 ID,並以 GOOGLE_APPLICATION_CREDENTIALS 指定 Google Cloud 服務帳戶 JSON 金鑰檔路徑,且該服務帳戶須被授予該資源的存取權。需要連線至 Google API 的網路。
安裝前請注意
需要服務帳戶金鑰檔,其路徑由 GOOGLE_APPLICATION_CREDENTIALS 指定,應視為機密並僅授予唯讀 GA4 權限。伺服器預設會回傳匿名診斷遙測,可用 DO_NOT_TRACK 或 MCP_TELEMETRY_OPT_OUT 關閉。README 中部分工具會從 GitHub 載入技能,完整資源結構可能非常龐大。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

[Google Analytics MCP Logo]

Google Analytics 4 (GA4) MCP Server 📊

Model Context Protocol (MCP) server for Google Analytics 4: real-time query exploration, schema discovery, metric aggregation, and audience insights for AI agents.

[CI] [PyPI version] [npm version] [OpenSSF Scorecard] [License: MIT]

🌐 Live Documentation & Web Portal: https://ga4mcp.com/


⚡ Quickstart

bash
# 1-Line Universal Installer (Auto-configures Claude Desktop, Cursor, Claude Code, Antigravity, VS Code, Zed, Windsurf)curl -fsSL "https://ga4.builditwithai.xyz/install" | bash
# Or run directly via your preferred runtime:uvx google-analytics-mcpuvx --from google-analytics-mcp ga4-mcp-serverpython -m ga4_mcpnpx -y @surendranb/google-analytics-mcp


🤖 Client Setup

A. Claude Code (CLI)

bash
claude mcp add google-analytics -- uvx google-analytics-mcp

B. Cursor & Google Antigravity (mcp.json)

json
{  "mcpServers": {    "google-analytics": {      "command": "uvx",      "args": ["google-analytics-mcp"]    }  }}

C. Claude Desktop (claude_desktop_config.json)

json
{  "mcpServers": {    "google-analytics": {      "command": "uvx",      "args": ["google-analytics-mcp"],      "env": {        "GA4_PROPERTY_ID": "your_ga4_property_id",        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service_account.json"      }    }  }}

D. VS Code (Cline / Roo Code / Continue)

json
{  "mcpServers": {    "google-analytics": {      "command": "npx",      "args": ["-y", "@surendranb/google-analytics-mcp"]    }  }}

🛠️ Tools & Capabilities

Tool NameParametersDescriptionReturn Type
get_ga4_datadimensions (list), metrics (list), date_ranges (list), limit (int)Runs multi-dimensional GA4 reports with automated metric totals and server-side aggregation.JSON / Markdown
list_accounts(none)Lists all accessible Google Analytics accounts and permission levels.JSON
list_propertiesaccount_id (optional)Lists all GA4 properties associated with an account.JSON
get_property_metadataproperty_id (optional)Fetches complete dimension and metric schemas, custom definitions, and compatibility rules.JSON
run_realtime_reportmetrics (list), dimensions (list)Queries real-time active users and event counts from the last 30 minutes.JSON
search_skillsquery (string)Searches built-in GA4 analytical playbooks (e-commerce, channel attribution, bot filtering).Markdown
skill_readskill_name (string)Dynamically loads procedural skills and analytical guides from GitHub.Markdown
skills_list(none)Lists all available live GA4 analytical skills.JSON

🧠 Dynamic Skills & Guided Playbooks

This server ships with built-in analytical recipes that load dynamically from GitHub:

  • traffic-diagnosis: Step-by-step root cause analysis for sudden traffic drops.
  • channel-acquisition: Best-practice channel grouping and attribution modeling.
  • ecommerce-analysis: Revenue, item purchase rate, and conversion funnel analysis.
  • ai-referral-analysis: Tracks and isolates referral traffic from ChatGPT, Claude, Perplexity, and Gemini.

🔒 Telemetry & Privacy

This package collects anonymous, non-PII diagnostic telemetry (command executions, latency, error codes) to improve tool reliability. No queries, user credentials, personal data, source code, or environment variables are ever collected or stored.

You can opt out anytime by setting either of the following environment variables:

bash
export DO_NOT_TRACK=1# orexport MCP_TELEMETRY_OPT_OUT=1

📄 License

MIT License. See LICENSE for details.

來源:README.md,提交 d8afdf5

工具

12

check_for_updates

Check PyPI for newer versions of this MCP server and get upgrade instructions.

無需輸入參數。

list_properties

List all GA4 properties associated with an account.

輸入參數account_id

search_schema

Search for a keyword across all dimensions and metrics for this property. Returns a ranked list of up to 10 matching fields scored by relevance. Returns: {"top_results": {"DIMENSION: api_name": score, "METRIC: api_name": score, ...}} Use this when you have a concept ("engagement", "revenue", "channel") and need exact API field names before calling get_ga4_data. Use list_dimension_categories or list_metric_categories instead if you want to browse all available fields without a specific keyword. Args: keyword: One or more keywords to search for (e.g., "user", "campaign revenue").

輸入參數keyword必填

get_property_schema

Returns the complete schema for the configured GA4 property, including all available dimensions and metrics (standard and custom). Warning: This can be a very large object (10k+ tokens). Use search_schema for most discovery tasks.

無需輸入參數。

list_dimension_categories

List all dimension categories for this GA4 property, with a count of dimensions in each category. Returns: {"dimension_categories": {"Category Name": count, ...}} Use this as the first step in dimension exploration — browse categories, then call get_dimensions_by_category with the name that fits your analysis. Use search_schema instead if you already have a keyword to search for.

無需輸入參數。

list_metric_categories

List all metric categories for this GA4 property, with a count of metrics in each category. Returns: {"metric_categories": {"Category Name": count, ...}} Use this as the first step in metric exploration — browse categories, then call get_metrics_by_category with the name that fits your analysis. Use search_schema instead if you already have a keyword to search for.

無需輸入參數。

get_dimensions_by_category

Return all dimensions in a specific category with their API names and descriptions. Returns: {"dimension_api_name": "description", ...} The category name must exactly match a value returned by list_dimension_categories. Use search_schema instead if you already have a keyword — it is faster and more targeted than browsing by category. Args: category: Exact category name from list_dimension_categories (case-insensitive).

輸入參數category必填

get_metrics_by_category

Return all metrics in a specific category with their API names and descriptions. Returns: {"metric_api_name": "description", ...} The category name must exactly match a value returned by list_metric_categories. Use search_schema instead if you already have a keyword — it is faster and more targeted than browsing by category. Args: category: Exact category name from list_metric_categories (case-insensitive).

輸入參數category必填

get_ga4_data

Retrieve GA4 data with built-in intelligence for better and safer results. Returns on success: {"data": [...], "metadata": {...}, "_skills_tip": "..."}. For multi-row pulls (a time series like ['date'], or any breakdown) the result also carries "totals": {metric: value} — GA4 server-side aggregates across all rows. Read the period figure from "totals"; do NOT sum the rows yourself. (Additive metrics sum; rate metrics are period-computed by GA4.) Returns on volume warning: {"warning": "...", "estimated_rows": N, "suggestions": [...]} Returns on error: {"error": "..."} CRITICAL WORKFLOW — follow this sequence every time: 1. DISCOVER FIELDS: NEVER guess dimension or metric names. Call `search_schema`, `list_dimension_categories`, or `list_metric_categories` FIRST to verify exact API names for this property. Guessing costs you a failed round-trip. 2. DISCOVER PATTERN: For any domain-specific analysis, call `search_skills('<topic>')` BEFORE querying to get the proven methodology — correct dimensions, metrics, filters, and how to interpret the result. One extra call prevents multiple failures. Use for: traffic diagnosis, attribution, ecommerce, channel acquisition, content performance, geo/device segmentation, AI referrals, bot detection. 3. RETRIEVE: Call get_ga4_data with the verified fields and the skill's pattern. 4. TROUBLESHOOT: On schema error, invalid field, or filter parse error — do NOT retry by guessing. Your training may predate current GA4 (UA was sunset 2023-07-01). Call `search_schema('<keyword>')` to find the current name in THIS property, or `search_skills('ua-to-ga4' | 'common-metric-names' | 'filter-structures')` for the mapping. FIELD NAMES — GA4 API names vs common wrong guesses: - 'screenPageViews' not 'uniquePageviews' or 'pageViews' - 'totalUsers' not 'users' - 'keyEvents'

輸入參數limitintentmetricsdimensionsestimate_onlydate_range_enddate_range_startdimension_filterenable_aggregationproceed_with_large_dataset

get_troubleshooting_guide

Returns the troubleshooting/setup guide for a topic, served from inside the server (no network needed). Use whenever you hit a schema error, dimension_filter parse error, IAM / 403 authorization error, or a boot-time setup error. Args: topic: One of "setup", "iam", or "schema".

輸入參數topic必填

search_skills

Fetch analytical recipes and how-to guides from the GA4 skills library. Skills are domain-specific playbooks for common GA4 analysis patterns — exact dimensions, metrics, filters, and interpretation logic for each use case. Call this BEFORE querying get_ga4_data for any domain-specific analysis. Available skills: gcp-setup, traffic-diagnosis, attribution-scope, channel-acquisition, content-performance, geo-device-segmentation, ecommerce-analysis, ai-referral-analysis, bot-traffic-detection, common-metric-names, filter-structures, custom-dimensions, compatible-combinations, ua-to-ga4, date-ranges, ga4-limitations. Usage: - search_skills("") → returns full index of all skills - search_skills("gcp-setup") → returns the GCP service-account setup playbook - search_skills("ecommerce") → returns the ecommerce-analysis skill - search_skills("ua-to-ga4") → returns the UA→GA4 field name mapping Args: query: A skill name (exact slug) or empty string to browse the full index.

輸入參數query必填

setup_ga4_access

Interactively fix a broken GA4 MCP setup (missing property ID, missing or expired credentials, or missing GA4 access) by asking the user for the needed input through the client, then re-initializing without a restart. Call this whenever a configuration or authentication error is reported.

無需輸入參數。

版本歷史

2
  1. v2.11.7最新Oct 29, 2026
  2. v2.8.2Sep 16, 2026

評分

已滿足適用檢查項的 90%

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

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

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

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分