Google Analytics MCP Server
Google Analytics MCP
用于 Google Analytics 4 的本地 MCP 服务器。将 GA4 Data API 封装在专注于 SEO 和付费 报告的工具中。
工具
工具 | 用途 |
| SEO:按着陆页、来源、国家或设备划分的自然搜索会话/用户/互动/转化 |
| 付费:按广告系列、着陆页、关键词或来源划分的付费搜索会话/转化/成本/CPC |
| 付费:所有付费渠道(搜索 + 社交 + 视频 + 展示)的成本和 ROAS |
| 付费:Google Ads 广告系列 × 广告组 × 关键词(需要 GA4 ↔ Google Ads 关联) |
| 按会话/互动/转化排序的顶级着陆页(可选渠道筛选) |
| 默认渠道组汇总 |
| 广告系列 × 来源 × 媒介细分 |
| 按来源/媒介/渠道划分的转化和关键事件 |
| 过去 30 分钟内的活跃用户 |
| 灵活的逃生舱 — 任意维度 + 指标 |
设置
git clone https://github.com/ZLeventer/google-analytics-mcp-server.git
cd google-analytics-mcp-server
npm install
npm run build凭据
将 .env.example 复制为 .env 并填写:
GA4_PROPERTY_ID— 来自 GA4 管理 → 媒体资源设置的数字媒体资源 ID(例如123456789)。不是衡量 ID (G-XXXXXXX)。GOOGLE_APPLICATION_CREDENTIALS— 服务账号 JSON 密钥文件的绝对路径。
创建服务账号
前往 console.cloud.google.com → 选择/创建一个项目
API 和服务 → 库 → 启用 Google Analytics Data API
IAM 和管理 → 服务账号 → 创建服务账号(命名为
ga4-mcp或类似名称)在创建的账号上 → 密钥 → 添加密钥 → 创建新密钥 → JSON → 下载
将 JSON 保存为该目录下的
service-account.json(已包含在.gitignore中)在 GA4 → 管理 → 媒体资源访问权限管理 中,点击 + → 粘贴服务账号电子邮件 (
ga4-mcp@project-id.iam.gserviceaccount.com) → 分配 查看者 角色
Google SDK 会自动读取 GOOGLE_APPLICATION_CREDENTIALS — 无需更改代码。
安装到 Claude Code
claude mcp add google-analytics \
--env-file "/absolute/path/to/google-analytics-mcp-server/.env" \
-- node "/absolute/path/to/google-analytics-mcp-server/dist/index.js"或者手动添加到 ~/.claude.json:
{
"mcpServers": {
"google-analytics": {
"command": "node",
"args": ["/absolute/path/to/google-analytics-mcp-server/dist/index.js"],
"env": {
"GA4_PROPERTY_ID": "123456789",
"GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/google-analytics-mcp-server/service-account.json"
}
}
}
}安装后重启 Claude Code。
日期格式
所有日期参数均接受 GA4 格式:
YYYY-MM-DD(例如2026-04-01)NdaysAgo(例如28daysAgo,90daysAgo)yesterday,today
默认值:28daysAgo → yesterday。
验证
配置好凭据后:
node -e '
import("./dist/tools/reports.js").then(m =>
m.channelPerformance({ start_date: "7daysAgo", end_date: "yesterday", limit: 10 })
).then(r => console.log(JSON.stringify(r, null, 2)))
'如果返回了行数据,则说明一切正常。预期错误:
GA4_PROPERTY_ID is not set— 检查.envPERMISSION_DENIED— 服务账号未被授予该媒体资源的查看者权限403 Google Analytics Data API has not been used— 在 GCP 项目中启用该 API
路线图
[ ] 管理 API 工具(列出自定义维度、转化事件、受众群体),按需添加
[ ] Search Console MCP 作为兄弟服务器,用于排名/展示次数/点击率数据(与此服务器互补)
[ ] 与 Demandbase MCP 配对,将 GA4 流量与公司画像(账户级归因)结合
Available Tools
10 toolsga4_all_paid_performanceA
Paid: all paid channels (Search + Social + Video + Display + Other) broken down by channel × campaign × source × medium, with cost and ROAS.
Inputs: start_date, end_date, property_id, limit.
ga4_campaign_performanceB
Campaign × source × medium breakdown with sessions/conversions/revenue. Optional channel filter.
Inputs: start_date, end_date, property_id, limit, +1 more.
ga4_channel_performanceB
Default channel group rollup: sessions/users/conversions/revenue for Organic Search, Paid Search, Email, Direct, Referral, etc.
Inputs: start_date, end_date, property_id, limit.
ga4_conversions_by_sourceB
Conversions and key events broken down by session source × medium × channel group. Sorted by key events desc.
Inputs: start_date, end_date, property_id, limit.
ga4_google_ads_performanceA
Paid: Google Ads campaign × ad group × keyword performance (impressions, clicks, cost, CPC, conversions, ROAS). Requires Google Ads ↔ GA4 link.
Inputs: start_date, end_date, property_id, limit.
ga4_landing_page_performanceA
Top landing pages by sessions/engagement/conversions. Optional channel filter (e.g. 'Organic Search', 'Paid Search').
Inputs: start_date, end_date, property_id, limit, +1 more.
ga4_organic_search_performanceA
SEO: sessions/users/engagement/conversions for Organic Search traffic, broken down by landing page (default), source, country, or device.
Inputs: start_date, end_date, property_id, limit, +1 more.
ga4_paid_search_performanceB
Paid: sessions/conversions/cost/CPC for Paid Search traffic, broken down by campaign (default), landing page, keyword, or source.
Inputs: start_date, end_date, property_id, limit, +1 more.
ga4_realtime_active_usersB
Current active users (last 30 min) broken down by screen/page, country, device, or audience.
Inputs: property_id, breakdown, limit.
ga4_run_reportA
Flexible GA4 Data API runReport. Pass any dimensions + metrics. Use for custom reports the preset tools don't cover.
Inputs: dimensions (required), metrics (required), start_date, end_date, +4 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool targets a distinct area of GA4 data: all paid, specific channels, campaigns, conversions, landing pages, organic/paid search, realtime, and a generic report. No two tools have overlapping purposes that would cause confusion.
All tool names consistently follow the 'ga4_<descriptive_name>' format using snake_case. The naming pattern is predictable and uniform across the entire set.
10 tools is well within the ideal 3-15 range for a focused analytics server. Each tool serves a clear purpose, and the count feels neither excessive nor insufficient for covering core GA4 queries.
The set covers acquisition, behavior, conversions, and realtime analytics well. Minor gaps exist (e.g., user demographics, event details), but the flexible ga4_run_report tool allows agents to fill these gaps for custom reports.
Related MCP Connectors
Hosted MCP server for GA4, Google Ads and Search Console. Google OAuth, nothing to install.
MCP server for querying and analyzing data from ad platforms, analytics tools, and spreadsheets
SEO MCP server for keyword research, SERP analysis, audits, and Search Console workflows.
SEO platform MCP server: GSC, Bing, Yandex, technical audits, local rank grids, and AI visibility.