Google Analytics 4

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

Google Analytics 4 MCP server with reporting, schema discovery, and admin visibility tools

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

概覽

AI 產生的概覽

Google Analytics 4 MCP 伺服器,可瀏覽 GA4 帳戶與資料結構、執行報表與匯出,並可選擇性修改資源設定。

可以做什麼
  • 探索帳戶與資源,查看幣別、時區等資源詳細資料
  • 探索即時資料結構:維度、指標、分類與相容性檢查
  • 執行報表:標準、樞紐、批次、即時與漏斗報表,含資料列量保護與配額查詢
  • 建立並分頁讀取大型非同步報表工作與客層匯出
  • 檢視管理設定:客層、關鍵事件、資料串流、各類連結、資料保留與變更歷史
  • 開啟寫入後可建立、更新、封存或刪除資源設定、關鍵事件、維度、指標、客層、資料串流與連結等
適用情境
適合讓助理直接回答 GA4 資料問題、確認可用的維度與指標、取得大規模匯出,或在不開啟 GA4 介面的情況下檢視與調整資源設定。
執行需求
透過 npx 在本機執行,需要 Node.js 20+ 與 npm。需將 GOOGLE_APPLICATION_CREDENTIALS 設為 ADC 或服務帳戶 JSON 的絕對路徑,並準備已啟用 Analytics Admin 與 Data API 的 Google Cloud 專案及該 GA4 資源的存取權。GA4_PROPERTY_ID 為選用,可作為預設資源。寫入工具另需 GA4_ALLOW_WRITES=true、analytics.edit 權限範圍及資源上的編輯者角色。
安裝前請注意
GOOGLE_APPLICATION_CREDENTIALS 指向可存取分析資料的憑證檔案,請勿放入共用設定。寫入工具具破壞性,可刪除或封存資源設定、資料串流、連結與密鑰,部分還需 confirm: true。建立報表工作與客層匯出會消耗配額。列出 Measurement Protocol 密鑰會回傳密鑰值。報表中的資源文字屬於不受信任內容。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

@mindstone/mcp-server-google-analytics

[npm version] [License: FSL-1.1-MIT]

Google Analytics 4 MCP server for Model Context Protocol hosts. Discover account/property structure, explore the live schema, run reports (with row-volume safety), create large asynchronous exports, and inspect admin configuration through a standardised MCP interface. With writes explicitly enabled, it can also set up and change property configuration: key events, custom dimensions and metrics, audiences, channel groups, data streams, enhanced measurement, event create and edit rules, calculated metrics, annotations, attribution, Measurement Protocol secrets, product links, and data retention.

Status

Requirements

  • Node.js 20+
  • npm
  • Google Application Default Credentials (ADC) with the analytics.readonly scope, or a service account JSON with access to the GA4 property
  • For write tools: GA4_ALLOW_WRITES=true, credentials with the analytics.edit scope, and the Editor role on the property

One-click install

[Add to Cursor] [Add to VS Code] [Add to VS Code Insiders]

After clicking the button, your host will prompt you to fill: GOOGLE_APPLICATION_CREDENTIALS.

Manual config for Claude Desktop / Claude Code / Goose / Continue.dev (Google Analytics 4)
json
{  "mcpServers": {    "Google Analytics 4": {      "command": "npx",      "args": [        "-y",        "@mindstone/mcp-server-google-analytics"      ],      "env": {        "GOOGLE_APPLICATION_CREDENTIALS": ""      }    }  }}

Quick Start

Install & build

bash
cd <path-to-repo>/connectors/google-analyticsnpm installnpm run build

npx (once published)

bash
npx -y @mindstone/mcp-server-google-analytics

Local

bash
node dist/index.js

Authentication

This server uses Google Application Default Credentials (ADC). Mint ADC for a user account by installing the Google Cloud CLI and running:

bash
gcloud auth application-default login \  --scopes=https://www.googleapis.com/auth/analytics.readonly \  --client-id-file=/absolute/path/to/oauth-client-secret.json

The --client-id-file is optional but strongly recommended — using your own OAuth client avoids the shared gcloud quota and gives you a stable verification footprint. You'll need a Google Cloud project with the Google Analytics Admin API and Google Analytics Data API enabled.

For service accounts, set GOOGLE_APPLICATION_CREDENTIALS to the absolute path of the service-account JSON. The service account must be granted access to the GA4 property in the GA4 Admin UI.

Enabling writes

Write tools are registered but refuse to run (WRITES_DISABLED) unless GA4_ALLOW_WRITES=true. To use them, mint ADC with the edit scope instead:

bash
gcloud auth application-default login \  --scopes=https://www.googleapis.com/auth/analytics.edit \  --client-id-file=/absolute/path/to/oauth-client-secret.json

The account (or service account) also needs the Editor role on the GA4 property. Service-account credentials request the edit scope automatically when writes are enabled; user ADC keeps whatever scope it was minted with.

Configuration

Environment variables

  • GOOGLE_APPLICATION_CREDENTIALS — required. Absolute path to ADC or service-account JSON. Node does not expand ~ or %APPDATA% — provide a fully-resolved path.
  • GA4_PROPERTY_ID — optional. Default GA4 property ID (e.g. 123456789). Tools fall back to this when property_id is not passed in the call.
  • GA4_ALLOW_WRITES — optional. Set to true (or 1) to allow the write tools to change GA4 configuration. Any other value, or unset, keeps the connector read-only.

Host configuration examples

Claude Desktop / Cursor

json
{  "mcpServers": {    "GoogleAnalytics": {      "command": "npx",      "args": ["-y", "@mindstone/mcp-server-google-analytics"],      "env": {        "GOOGLE_APPLICATION_CREDENTIALS": "/Users/you/.config/gcloud/application_default_credentials.json",        "GA4_PROPERTY_ID": "123456789"      }    }  }}

Local development (no npm publish needed)

json
{  "mcpServers": {    "GoogleAnalytics": {      "command": "node",      "args": ["<path-to-repo>/connectors/google-analytics/dist/index.js"],      "env": {        "GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/credentials.json",        "GA4_PROPERTY_ID": "123456789"      }    }  }}

Tools (91)

Account & property

  • ga_list_account_summaries — discover available accounts and properties
  • ga_list_properties — flat list of GA4 properties with optional filtering
  • ga_get_property_details — currency, time zone, industry category, service level

Schema discovery

  • ga_get_metadata — live property schema
  • ga_get_property_schema — same data with summary counts
  • ga_search_schema — keyword search across dimensions and metrics
  • ga_list_dimension_categories, ga_list_metric_categories
  • ga_get_dimensions_by_category, ga_get_metrics_by_category
  • ga_check_compatibility — verify dimension/metric combinations before reporting

Reporting

  • ga_run_report — core report with row-volume safety (estimate, opt-in to large datasets, automatic aggregation suggestions)
  • ga_run_pivot_report — cross-tabulated reports
  • ga_batch_run_reports — up to 5 reports in one call
  • ga_run_realtime_report — last 30 minutes of activity
  • ga_get_property_quotas_snapshot — remaining tokens / requests
  • ga_run_funnel_report — step-by-step completion and drop-off, with optional breakdown, next action, and trended view (v1alpha)

Large exports

  • ga_create_report_task — start an asynchronous report task for large exports (no synchronous timeout, no row-volume gate)
  • ga_get_report_task — poll task state until ACTIVE
  • ga_query_report_task — page task rows (up to 250,000 per page)
  • ga_create_audience_export — snapshot the users in an audience (incl. predictive segments); charges audience-export quota tokens
  • ga_get_audience_export — poll export state until ACTIVE
  • ga_list_audience_exports — find and reuse existing exports
  • ga_query_audience_export — page user-level rows from an ACTIVE export

Admin visibility

  • ga_list_audiences — audiences configured on the property, with filter clauses
  • ga_list_channel_groups — channel groups and their grouping rules
  • ga_get_custom_dimensions_and_metrics
  • ga_list_google_ads_links
  • ga_list_key_events
  • ga_list_data_streams
  • ga_get_global_site_tag — gtag.js snippet for the first web stream
  • ga_list_bigquery_links
  • ga_get_data_retention_settings
  • ga_list_firebase_links
  • ga_search_change_history_events
  • ga_get_enhanced_measurement_settings — automatic events on a web stream
  • ga_list_event_create_rules — rules that derive new events on a stream
  • ga_list_measurement_protocol_secrets — secret values are returned; treat as sensitive
  • ga_list_annotations — chart annotations (v1alpha)
  • ga_get_attribution_settings — attribution model and lookback windows (v1alpha)
  • ga_list_calculated_metrics — formula metrics (v1alpha)
  • ga_list_event_edit_rules — rules that rename or modify events on a stream (v1alpha)
  • ga_get_google_signals_settings (v1alpha)
  • ga_get_data_sharing_settings — account-level

Admin writes (require GA4_ALLOW_WRITES=true)

Every write is annotated readOnlyHint: false, destructiveHint: true. Archive, delete, acknowledgement, and data-retention tools also require confirm: true. Update tools change only the fields you pass (the update mask is built from them) and fail with NOTHING_TO_UPDATE if you pass none.

  • Key events: ga_create_key_event, ga_update_key_event, ga_delete_key_event
  • Custom dimensions: ga_create_custom_dimension, ga_update_custom_dimension, ga_archive_custom_dimension
  • Custom metrics: ga_create_custom_metric, ga_update_custom_metric, ga_archive_custom_metric
  • Audiences (v1alpha): ga_create_audience, ga_update_audience, ga_archive_audience
  • Channel groups (v1alpha): ga_create_channel_group, ga_update_channel_group, ga_delete_channel_group
  • Event create rules (v1alpha): ga_create_event_create_rule, ga_update_event_create_rule, ga_delete_event_create_rule
  • Property: ga_create_property, ga_update_property, ga_delete_property (moves to trash for 35 days), ga_acknowledge_user_data_collection
  • Data streams: ga_create_web_data_stream, ga_update_data_stream, ga_delete_data_stream
  • Enhanced measurement (v1alpha): ga_update_enhanced_measurement_settings
  • Measurement Protocol secrets: ga_create_measurement_protocol_secret, ga_delete_measurement_protocol_secret
  • Google Ads links: ga_create_google_ads_link, ga_update_google_ads_link, ga_delete_google_ads_link
  • Firebase links: ga_create_firebase_link, ga_delete_firebase_link
  • BigQuery links (v1alpha): ga_create_bigquery_link, ga_update_bigquery_link, ga_delete_bigquery_link
  • Data retention: ga_update_data_retention_settings
  • Annotations (v1alpha): ga_create_annotation, ga_update_annotation, ga_delete_annotation
  • Attribution (v1alpha): ga_update_attribution_settings
  • Calculated metrics (v1alpha): ga_create_calculated_metric, ga_update_calculated_metric, ga_delete_calculated_metric
  • Event edit rules (v1alpha): ga_create_event_edit_rule, ga_update_event_edit_rule, ga_delete_event_edit_rule

Explorations, saved reports, and report layouts have no Google API, so they cannot be created or changed by this connector.

Notes

  • Read-only by default. Without GA4_ALLOW_WRITES=true, the only tools that create anything are ga_create_report_task and ga_create_audience_export, which materialise server-side snapshots and charge quota without modifying property configuration. The admin write tools refuse with WRITES_DISABLED before any request is sent. All of these are annotated readOnlyHint: false, destructiveHint: true, so hosts can gate them behind explicit user approval.
  • Alpha endpoints. Audiences, channel groups, BigQuery links, enhanced measurement, event create and edit rules, annotations, attribution, calculated metrics, Google Signals, the global site tag, change history (Admin API), and report tasks and funnel reports (Data API) are only exposed on Google's v1alpha surfaces today; the corresponding tools note this in their descriptions.
  • Untrusted content. Text authored inside the GA4 property — report dimension values (page titles, campaign names, custom-dimension values), audience/display names, descriptions, definition blobs, data-stream stream-data blobs, the global site tag snippet, custom-metadata expressions, vendor-echoed header/dimension names, and vendor error messages — is returned inside <untrusted-content source="…"> envelopes so hosts treat it as data, not instructions. Metric values and resource identifiers stay raw so agents can compose follow-up calls. Resource IDs passed to tools are constrained to the ID charset before URL interpolation (INVALID_RESOURCE_ID on anything else).
  • Response validation. Every Google API response is validated against a Zod schema at the boundary; a shape mismatch fails closed with an INVALID_API_RESPONSE error rather than propagating malformed data. Paginated lists follow nextPageToken in full and fail with PAGINATION_LIMIT_EXCEEDED if the API does not stop paging after a generous safety cap — never a silent truncation.

Licence

FSL-1.1-MIT — Functional Source License, Version 1.1, with MIT future licence. The software converts to MIT licence on the second anniversary of release.

來源:connectors/google-analytics/README.md,提交 9b9aa57

工具

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

版本歷史

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

評分

已滿足適用檢查項的 40%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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

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