magebitcom/magento2-mcp-google-analytics-tools 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

magebitcom/magento2-mcp-google-analytics-tools

Composer 安装命令:

composer require magebitcom/magento2-mcp-google-analytics-tools

包简介

Google Analytics 4 MCP tools for Magebit_Mcp — wraps the GA Data and Admin APIs as MCP tools so AI clients can query property metadata, run reports, run realtime reports, and run funnel reports against your store's analytics property.

README 文档

README

Google Analytics 4 tools for the Magebit MCP server. Exposes the Google Analytics Data API and Admin API as MCP tools so AI clients (Claude Desktop, ChatGPT, Gemini, Claude Code, MCP Inspector, …) can discover properties, run reports, and inspect schema metadata against your store's analytics property.

Mirrors the official google-analytics-mcp server, but configured through the Magento admin and authenticated with a connected Google account (OAuth) whose refresh token is stored encrypted in core_config_data.

Tools

All tools are read-only. Every tool accepts an optional property_id argument; when omitted, the Default GA4 Property ID from admin config is used.

Tool Description
google_analytics.account.summaries List every account + property visible to the connected Google account. Use this first to discover property IDs.
google_analytics.property.get Return the GA4 Property resource (display name, currency, time zone, industry, service level, …) for the given property.
google_analytics.property.google_ads_links List the Google Ads accounts linked to a GA4 property.
google_analytics.property.custom_dimensions_and_metrics List the custom dimensions and custom metrics defined on a property. Use before running a report to discover what custom fields are available.
google_analytics.report.run Run a GA4 Data API Core Report (runReport). Supports date_ranges, dimensions, metrics, filters, order-bys, aggregations, currency conversion.
google_analytics.report.run_realtime Run a GA4 Realtime Report (runRealtimeReport) — events in the last 30 minutes.
google_analytics.report.run_funnel Run a GA4 Funnel Report (runFunnelReport, Data API v1alpha).

Every tool surfaces errors as a soft error (isError: true in the MCP response) with a human-readable message, leaving the tools/call JSON-RPC response status as success. Common error cases:

  • Not connected → "Google Analytics is not connected. Connect a Google account…"
  • Property id absent and no default → "Google Analytics property_id is required."
  • API quota / permission errors → "Google Analytics API error: <original gRPC status>."

Installation

composer require magebitcom/magento2-mcp-google-analytics-tools
bin/magento module:enable Magebit_McpGoogleAnalyticsTools
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush

The module depends on magebitcom/magento2-mcp-module and the official Google PHP SDKs (google/analytics-data, google/analytics-admin, google/auth). Composer resolves them automatically.

Connect a Google account

The tools act as a real Google user who already has access to your GA4 property.

  1. Enable the APIs in a Google Cloud project:
  2. Create an OAuth client. In APIs & Services → Credentials, choose Create credentials → OAuth client ID → Web application.
  3. Register the redirect URI. Copy the Authorized redirect URI shown in the Magento admin (Stores → Configuration → Magebit → Google Analytics MCP → Google Connection) into the OAuth client's Authorized redirect URIs. It looks like https://<your-admin-host>/<admin>/magebit_mcp_ga/oauth/callback. Google only accepts public HTTPS hosts (or localhost); if your store runs on a non-public host, set Redirect Base URL to a public tunnel host (ngrok / cloudflared) — the displayed redirect URI updates to match.
  4. Configure the consent screen — for internal use only. Set the User type to Internal so the OAuth client is restricted to your own Google Workspace organization.
  5. Paste client ID + secret into the admin config and click Save Config.
  6. Click Connect with Google and approve the consent screen with an account that has at least Viewer access to the GA4 property. The status flips to "Connected as you@example.com".
  7. (Optional) Set a Default GA4 Property ID — the numeric id (e.g. 123456789) used when a tool call doesn't specify one. Discover IDs at runtime via google_analytics.account.summaries.

The refresh token is stored encrypted at rest. Use Disconnect to revoke it from the store.

Granting tool access

Tool calls go through the standard Magebit MCP token + ACL flow:

  1. Edit (or create) the admin role that owns your MCP token under System → Permissions → User Roles.
  2. Under Role Resources, scroll to Stores → Settings → Configuration → Magebit → MCP → MCP Tools and tick the tool ACLs you want this token to use (each tool has its own resource, e.g. Tool: Run Google Analytics Report).
  3. Save. The next tool call from that token will see the tools in tools/list and be allowed to call them.

The admin Google Analytics MCP Configuration permission gates access to the connection settings — keep it scoped to people who should manage the Google connection.

Quick example

// JSON-RPC body for POST /mcp
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "google_analytics.report.run",
    "arguments": {
      "date_ranges": [{ "start_date": "7daysAgo", "end_date": "today" }],
      "dimensions": [{ "name": "country" }],
      "metrics": [{ "name": "activeUsers" }, { "name": "sessions" }],
      "order_bys": [{ "metric": { "metric_name": "activeUsers" }, "desc": true }],
      "limit": 10
    }
  }
}

License

MIT — see LICENSE.

magebitcom/magento2-mcp-google-analytics-tools 适用场景与选型建议

magebitcom/magento2-mcp-google-analytics-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 magebitcom/magento2-mcp-google-analytics-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 magebitcom/magento2-mcp-google-analytics-tools 我们能提供哪些服务?
定制开发 / 二次开发

基于 magebitcom/magento2-mcp-google-analytics-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-09