
Mcp Google Analytics
io.github.leonardosepulvedat由 GitHub 帳號 leonardosepulvedat 發布v1.3.0更新於 Oct 24, 2026
GA4 MCP that reads AND writes: reports, funnels, audits, and server-side events. 26 tools.
概覽
針對 Google Analytics 4 的本機 MCP 伺服器,讓助理執行報表、漏斗與資源稽核,並透過 Measurement Protocol 傳送事件。
- 可以做什麼
- 在 GA4 資源上執行自訂、即時、樞紐、漏斗與批次報表,預設限制回傳列數以節省 token,並可在查詢前檢查維度與指標相容性。探索帳戶、資源、資料串流、自訂維度與指標、關鍵事件以及連結的 Google Ads 帳戶,支援跨多個資源查詢。稽核資源設定,例如自訂定義與轉換事件。透過 Measurement Protocol 傳送伺服器端事件:自訂事件、頁面瀏覽、登入、註冊、商品瀏覽、加入購物車、結帳、購買與退款。在正式記錄前用偵錯端點驗證事件,再透過即時報表確認送達。
- 適用情境
- 適合讓助理依據 GA4 資料回答分析問題、稽核資源的追蹤設定,或在沒有 JavaScript 標籤的後端與自動化流程中記錄轉換與電商事件。也適合代理商在同一次對話中查詢多個客戶的資源。
- 執行需求
- 透過 npx 或全域 npm 安裝在本機執行(需要 Node.js)。需要一個已啟用 Analytics Data API 的 Google Cloud 服務帳戶,並在 GA4 資源上授予檢視者權限,透過 GA_SERVICE_ACCOUNT_JSON(檔案路徑或內嵌 JSON)提供,讀取工具另需 GA_PROPERTY_ID。傳送事件還需 GA_MEASUREMENT_ID 與 GA_API_SECRET。需要連線至 Google API 的網路。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Mcp Google Analytics,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
MCP Google Analytics Server
A Model Context Protocol (MCP) server for Google Analytics 4, providing comprehensive integration with both the Google Analytics Data API (for reading reports) and Measurement Protocol v2 (for sending events).
The GA4 MCP that reads AND writes. Most GA4 MCP servers (including Google's official one) are read-only. This one gives your AI agent the full loop: run reports and funnels, audit your setup (custom dimensions, key events, compatibility checks), send ecommerce and conversion events server-side, and verify them in the realtime report — 26 tools in one npx command.
Built for agencies too: every read tool accepts an optional propertyId, so one conversation can query all your clients' properties — no reconfiguration between clients. See Multi-Property Mode.
[npm version] [npm downloads] [CI] [License: MIT] [smithery badge]
⚡ One-Click Install
You only need two values to start (same as any other GA4 MCP): the service account JSON and your property ID. Sending events is an optional extra.
Click Install in Cursor, then paste:
GA_SERVICE_ACCOUNT_JSON— path to the downloaded key file, or the JSON itselfGA_PROPERTY_ID— the numeric ID in GA4 Admin → Property Settings (e.g.123456789)
That is enough to ask “users by country this week”. To also send events, add two more keys later (see Send events (optional)).
💡 Keep reports small
Reports can get large. This server is designed with token optimization in mind:
- All read tools default to 10 results - Adjust the
limitparameter as needed - Use specific date ranges - Avoid querying years of data at once
- Select only needed dimensions/metrics - Don't request everything
- Check TOKEN_OPTIMIZATION.md for detailed best practices
See the dedicated Token Optimization Guide for strategies to minimize token usage.
🚀 Quick Start
See QUICKSTART.md for a 5-minute setup guide, or follow the installation steps below.
📦 Installation
Option 1: Install globally via npm
Option 2: Use with npx (no installation needed)
🔧 Configuration
Start with two values. That unlocks reports, funnels, realtime, and property audits — everything most people need, and the same setup every other GA4 MCP asks for.
1. Service account key
- In Google Cloud Console, enable Google Analytics Data API.
- IAM & Admin → Service Accounts → Create. Download a JSON key.
- In GA4: Admin → Property Access Management → add the service account email as Viewer.
Use the file path or paste the JSON into GA_SERVICE_ACCOUNT_JSON.
2. Property ID
GA4 Admin → Property Settings → Property ID (numbers only, e.g. 123456789).
You can now ask: “Show me active users by country this week.”
Send events (optional)
Only if you want the agent to record events (purchases, signups, custom events). Most GA4 MCPs cannot do this; it is extra, not required.
- GA4 Admin → Data Streams → your stream → copy Measurement ID (
G-XXXXXXXXXX). - Measurement Protocol API secrets → Create → copy the secret.
Add them next to the two values you already have:
🏢 Multi-Property Mode (Agencies)
Every read tool accepts an optional propertyId argument that overrides the configured GA_PROPERTY_ID — so a single conversation can query any property the service account can access, with no reconfiguration between clients.
- Grant your service account "Viewer" access on each client's GA4 property (or at account level).
- Set only
GA_SERVICE_ACCOUNT_JSON(GA_PROPERTY_IDbecomes optional — if set, it acts as the default). - Discover properties, then query any of them:
propertyId accepts both 123456789 and properties/123456789. Event sending (Measurement Protocol) remains tied to the configured GA_MEASUREMENT_ID/GA_API_SECRET, since each data stream has its own secret.
🔌 Integration with Claude Desktop
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
Or if installed globally:
Restart Claude Desktop after updating the configuration.
🎯 Integration with Cursor
Add to your Cursor MCP settings file:
macOS/Linux: ~/.cursor/mcp.json
Windows: %USERPROFILE%\.cursor\mcp.json
Restart Cursor after updating the configuration.
🛠️ Available Tools
At a Glance
Reading data (Google Analytics Data API) — all read tools default to 10 rows to save tokens:
Sending events (Measurement Protocol):
Google Analytics Data API (Reading Data)
ga_run_report
Run custom reports with dimensions and metrics.
Common Dimensions: date, city, country, deviceCategory, browser, pagePath, eventName, sessionSource, sessionMedium, sessionCampaignName
Common Metrics: activeUsers, sessions, screenPageViews, conversions, totalRevenue, engagementRate, averageSessionDuration
Example:
ga_run_realtime_report
Get real-time data (last 30 minutes).
Example:
ga_get_metadata
Get all available dimensions and metrics for your property.
Warning: Returns 500+ items. Use sparingly.
ga_list_accounts
List all GA accounts accessible to the service account.
ga_list_properties
List GA4 properties, optionally filtered by account ID.
ga_get_property
Get details about the configured property.
ga_list_data_streams
List data streams for the configured property.
ga_run_pivot_report
Run pivot table reports with row/column dimensions.
Example:
ga_run_funnel_report
Run funnel analysis to track user progression.
Note: Funnel reporting uses the Data API v1alpha channel (the only channel where Google exposes it). Each step matches an event: set eventName per step, or omit it to use the step's name as the event name. For advanced matching, pass a full filterExpression.
Example:
ga_batch_run_reports
Run multiple reports in a single request.
Warning: Can return large datasets. Limit to 2-5 reports per batch.
ga_get_account_summaries
Get all accessible accounts with their properties in a single compact call. The fastest way to discover account and property IDs.
ga_list_custom_dimensions / ga_list_custom_metrics
List the custom dimensions and metrics defined for the property, including their API names (e.g., customEvent:plan_type) so you can use them in reports.
ga_list_key_events
List the key events (conversions) configured for the property — useful before building conversion reports or deciding which events to send.
ga_list_google_ads_links
List Google Ads accounts linked to the property.
ga_check_compatibility
Check whether a dimension/metric combination is valid before running a report, avoiding wasted requests and token-heavy error loops.
Example:
Measurement Protocol (Sending Events)
Good to know:
- Events take a few minutes to appear in standard reports, but show up almost immediately in the realtime report (
ga_run_realtime_report).- Use
ga_validate_eventto test new events without recording them.- If you omit
client_id, one is auto-generated per call. To have GA group several events (e.g., a cart-to-purchase flow) into the same session and user, pass the sameclient_idto every call.
ga_send_event
Send custom events to GA4.
Example:
ga_validate_event
Validate events before sending (uses debug endpoint).
ga_send_pageview
Send page view events.
Example:
ga_send_purchase
Send ecommerce purchase events.
Example:
ga_send_login
Send login events.
ga_send_signup
Send user registration events.
ga_send_view_item
Send product/item detail view events. Completes the standard ecommerce funnel: view_item → add_to_cart → begin_checkout → purchase.
ga_send_add_to_cart
Send add-to-cart events.
ga_send_begin_checkout
Send checkout initiation events.
ga_send_refund
Send full or partial refund events. Use the same transaction_id as the original purchase; omit items for a full refund, include them for a partial one.
Example (partial refund):
📖 Usage Examples
See EXAMPLES.md for practical usage examples in Spanish.
Example: Get users by country (last 7 days)
Claude will use ga_run_report:
Example: Track a purchase
Claude will use ga_send_purchase:
Example: Validate an event before sending it
Recommended before wiring up any new event: the debug endpoint checks the payload without recording anything.
Claude will use ga_validate_event:
The response lists validation messages; an empty list means the event is well-formed.
Example: Server-side conversion tracking
Track signups or logins that happen in your backend, where no JavaScript tag runs:
Claude will use ga_send_signup:
Example: Full ecommerce funnel from an agent
Send the same client_id on each call so GA groups the events into one session:
Claude will chain ga_send_add_to_cart → ga_send_begin_checkout → ga_send_purchase, reusing the client ID:
Example: Custom events from automations
Measure things GA never sees natively, like AI agent activity or scheduled jobs:
Claude will use ga_send_event:
Example: Send and verify in one conversation
Combine both APIs to confirm your tracking works end to end:
Claude will call ga_send_event, then check with ga_run_realtime_report:
Measurement Protocol events appear in the realtime report within seconds, while standard reports can take a few minutes.
🔍 Debugging
Enable debug logging by setting:
For Measurement Protocol, use ga_validate_event to check events before sending them live.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT License - see LICENSE file for details.
🔗 Links
- GitHub Repository
- npm Package
- Smithery
- MCP Documentation
- GA4 Data API Documentation
- Measurement Protocol Documentation
🆘 Support
For issues and questions:
📝 Changelog
See CHANGELOG.md for version history.
來源:README.md,提交 97731c9
工具
0版本歷史
1- v1.3.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分