Google Analytics 4
数据与存储by stucchi
Manage GA4 properties, data streams, conversions, and run reports via Admin & Data APIs.
什么是 Google Analytics 4?
Manage GA4 properties, data streams, conversions, and run reports via Admin & Data APIs.
README
Google Analytics 4 MCP Server
<!-- mcp-name: io.github.stucchi/google-analytics -->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)
-
Google Cloud Console → IAM & Admin → Service Accounts
- Create a service account (any name)
- Click it → Keys → Add Key → JSON → Download
-
Enable APIs in your GCP project:
-
GA4 Admin → Property Access Management → Add the service account email (from the JSON) as Editor
-
Configure credentials (pick one):
- Option A (recommended): Copy the JSON content into the
GA_CREDENTIALSenv var in your MCP config - Option B: Save the file to
~/.google-analytics-4-mcp/credentials.json
- Option A (recommended): Copy the JSON content into the
Done. No browser flow, no consent screen, no tokens to refresh.
Installation
Claude Code
claude mcp add google-analytics -e GA_CREDENTIALS='{"type":"service_account",...}' -- uvx google-analytics-4-mcp
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"google-analytics": {
"command": "uvx",
"args": ["google-analytics-4-mcp"],
"env": {
"GA_CREDENTIALS": "{\"type\":\"service_account\",\"project_id\":\"...\", ...}"
}
}
}
}
From source
git clone https://github.com/stucchi/mcp-google-analytics.git
cd mcp-google-analytics
uv run google-analytics-4-mcp
Getting Started
- Check auth: Call
check_auth_statusto verify the service account is configured - List accounts: Call
list_accountsto see your GA4 accounts - Setup a property: Use
create_property→create_web_data_stream→get_tracking_snippet - Query data: Use
run_reportwith dimensions and metrics
Tools (23)
Auth
| Tool | Description |
|---|---|
check_auth_status | Verify service account is configured and valid |
Admin API
| Tool | Description |
|---|---|
list_accounts | List accessible GA4 accounts |
list_properties | List properties for an account |
create_property | Create a GA4 property |
get_property | Get property details |
delete_property | Soft-delete a property |
list_data_streams | List data streams |
create_web_data_stream | Create web stream → get Measurement ID |
delete_data_stream | Delete a data stream |
get_tracking_snippet | Generate gtag.js HTML snippet |
list_key_events | List conversion events |
create_key_event | Mark event as conversion |
delete_key_event | Remove conversion |
list_custom_dimensions | List custom dimensions |
create_custom_dimension | Create custom dimension |
list_custom_metrics | List custom metrics |
create_custom_metric | Create custom metric |
list_google_ads_links | List Google Ads links |
create_google_ads_link | Link Google Ads account |
get_measurement_protocol_secret | Get/create Measurement Protocol secret |
Data API
| Tool | Description |
|---|---|
run_report | Run report with dimensions, metrics, dates, filters |
run_realtime_report | Real-time active users and events |
get_metadata | List available dimensions and metrics |
Environment Variables
| Variable | Default | Description |
|---|---|---|
GA_CREDENTIALS | — | Service Account JSON key content (copy-paste the entire JSON) |
GA_CREDENTIALS_PATH | ~/.google-analytics-4-mcp/credentials.json | Alternative: 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
常见问题
Google Analytics 4 是什么?
Manage GA4 properties, data streams, conversions, and run reports via Admin & Data APIs.
相关 Skills
技术栈评估
by alirezarezvani
对比框架、数据库和云服务,结合 5 年 TCO、安全风险、生态活力与迁移复杂度做量化评估,适合技术选型、栈升级和替换路线决策。
✎ 帮你系统比较技术栈优劣,不只看功能,还把TCO、安全性和生态健康度一起量化,选型和迁移决策更稳。
资深数据工程师
by alirezarezvani
聚焦生产级数据工程,覆盖 ETL/ELT、批处理与流式管道、数据建模、Airflow/dbt/Spark 优化和数据质量治理,适合设计数据架构、搭建现代数据栈与排查性能问题。
✎ 复杂数据管道、ETL/ELT 和治理难题交给它,凭 Spark、Airflow、dbt 等现代数据栈经验,能更稳地搭起可扩展的数据基础设施。
迁移架构师
by alirezarezvani
为数据库、API 与基础设施迁移制定分阶段零停机方案,提前校验兼容性与风险,生成回滚策略、验证关卡和时间线,适合复杂系统平滑切换。
✎ 做数据库与存储迁移时,用它统一梳理表结构和数据搬迁流程,架构视角更完整,复杂迁移也更稳。
相关 MCP Server
SQLite 数据库
编辑精选by Anthropic
SQLite 是让 AI 直接查询本地数据库进行数据分析的 MCP 服务器。
✎ 这个服务器解决了 AI 无法直接访问 SQLite 数据库的问题,适合需要快速分析本地数据集的开发者。不过,作为参考实现,它可能缺乏生产级的安全特性,建议在受控环境中使用。
PostgreSQL 数据库
编辑精选by Anthropic
PostgreSQL 是让 Claude 直接查询和管理你的数据库的 MCP 服务器。
✎ 这个服务器解决了开发者需要手动编写 SQL 查询的痛点,特别适合数据分析师或后端开发者快速探索数据库结构。不过,由于是参考实现,生产环境使用前务必评估安全风险,别指望它能处理复杂事务。
Firecrawl 智能爬虫
编辑精选by Firecrawl
Firecrawl 是让 AI 直接抓取网页并提取结构化数据的 MCP 服务器。
✎ 它解决了手动写爬虫的麻烦,让 Claude 能直接访问动态网页内容。最适合需要实时数据的研究者或开发者,比如监控竞品价格或抓取新闻。但要注意,它依赖第三方 API,可能涉及隐私和成本问题。