{
  "markdown": "# MCP Google Analytics Server\n\nA 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).\n\n**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.\n\n**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](#-multi-property-mode-agencies).\n\n[![npm version](https://badge.fury.io/js/mcp-google-analytics.svg)](https://www.npmjs.com/package/mcp-google-analytics)\n[![npm downloads](https://img.shields.io/npm/dm/mcp-google-analytics.svg)](https://www.npmjs.com/package/mcp-google-analytics)\n[![CI](https://github.com/leonardosepulvedat/mcp-google-analytics/actions/workflows/ci.yml/badge.svg)](https://github.com/leonardosepulvedat/mcp-google-analytics/actions/workflows/ci.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![smithery badge](https://smithery.ai/badge/lsepulvedatabares/mcp-google-analytics)](https://smithery.ai/servers/lsepulvedatabares/mcp-google-analytics)\n\n## ⚡ One-Click Install\n\nYou 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.\n\n[![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](cursor://anysphere.cursor-deeplink/mcp/install?name=google-analytics&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIm1jcC1nb29nbGUtYW5hbHl0aWNzIl0sImVudiI6eyJHQV9TRVJWSUNFX0FDQ09VTlRfSlNPTiI6Ii9wYXRoL3RvL3NlcnZpY2UtYWNjb3VudC5qc29uIiwiR0FfUFJPUEVSVFlfSUQiOiIxMjM0NTY3ODkifX0=)\n\nClick **Install in Cursor**, then paste:\n\n1. **`GA_SERVICE_ACCOUNT_JSON`** — path to the downloaded key file, or the JSON itself  \n2. **`GA_PROPERTY_ID`** — the numeric ID in GA4 Admin → Property Settings (e.g. `123456789`)\n\nThat is enough to ask “users by country this week”. To also send events, add two more keys later (see [Send events (optional)](#send-events-optional)).\n\n## 💡 Keep reports small\n\nReports can get large. This server is designed with token optimization in mind:\n\n- **All read tools default to 10 results** - Adjust the `limit` parameter as needed\n- **Use specific date ranges** - Avoid querying years of data at once\n- **Select only needed dimensions/metrics** - Don't request everything\n- **Check [TOKEN_OPTIMIZATION.md](TOKEN_OPTIMIZATION.md)** for detailed best practices\n\nSee the dedicated [Token Optimization Guide](TOKEN_OPTIMIZATION.md) for strategies to minimize token usage.\n\n## 🚀 Quick Start\n\nSee [QUICKSTART.md](QUICKSTART.md) for a 5-minute setup guide, or follow the installation steps below.\n\n## 📦 Installation\n\n### Option 1: Install globally via npm\n\n```bash\nnpm install -g mcp-google-analytics\n```\n\n### Option 2: Use with npx (no installation needed)\n\n```bash\nnpx mcp-google-analytics\n```\n\n## 🔧 Configuration\n\n**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.\n\n### 1. Service account key\n\n1. In [Google Cloud Console](https://console.cloud.google.com/), enable **Google Analytics Data API**.\n2. IAM & Admin → Service Accounts → Create. Download a JSON key.\n3. In GA4: Admin → Property Access Management → add the service account email as **Viewer**.\n\nUse the file path or paste the JSON into `GA_SERVICE_ACCOUNT_JSON`.\n\n### 2. Property ID\n\nGA4 Admin → Property Settings → **Property ID** (numbers only, e.g. `123456789`).\n\n```json\n{\n  \"mcpServers\": {\n    \"google-analytics\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"mcp-google-analytics\"],\n      \"env\": {\n        \"GA_SERVICE_ACCOUNT_JSON\": \"/path/to/service-account.json\",\n        \"GA_PROPERTY_ID\": \"123456789\"\n      }\n    }\n  }\n}\n```\n\nYou can now ask: *“Show me active users by country this week.”*\n\n### Send events (optional)\n\nOnly if you want the agent to **record** events (purchases, signups, custom events). Most GA4 MCPs cannot do this; it is extra, not required.\n\n1. GA4 Admin → Data Streams → your stream → copy **Measurement ID** (`G-XXXXXXXXXX`).\n2. Measurement Protocol API secrets → Create → copy the secret.\n\nAdd them next to the two values you already have:\n\n```json\n\"GA_MEASUREMENT_ID\": \"G-XXXXXXXXXX\",\n\"GA_API_SECRET\": \"your-api-secret\"\n```\n\n## 🏢 Multi-Property Mode (Agencies)\n\nEvery 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.\n\n1. Grant your service account \"Viewer\" access on each client's GA4 property (or at account level).\n2. Set only `GA_SERVICE_ACCOUNT_JSON` (`GA_PROPERTY_ID` becomes optional — if set, it acts as the default).\n3. Discover properties, then query any of them:\n\n```\nShow me all my accounts and properties          → ga_get_account_summaries\nCompare last week's active users between the    → ga_run_report with propertyId \"111111\"\nAcme property and the Globex property             and again with propertyId \"222222\"\n```\n\n`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.\n\n## 🔌 Integration with Claude Desktop\n\nAdd to your Claude Desktop configuration file:\n\n**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`\n**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`\n\n```json\n{\n  \"mcpServers\": {\n    \"google-analytics\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"mcp-google-analytics\"],\n      \"env\": {\n        \"GA_SERVICE_ACCOUNT_JSON\": \"/path/to/service-account.json\",\n        \"GA_PROPERTY_ID\": \"123456789\"\n      }\n    }\n  }\n}\n```\n\nOr if installed globally:\n\n```json\n{\n  \"mcpServers\": {\n    \"google-analytics\": {\n      \"command\": \"mcp-google-analytics\",\n      \"env\": {\n        \"GA_SERVICE_ACCOUNT_JSON\": \"/path/to/service-account.json\",\n        \"GA_PROPERTY_ID\": \"123456789\"\n      }\n    }\n  }\n}\n```\n\nRestart Claude Desktop after updating the configuration.\n\n## 🎯 Integration with Cursor\n\nAdd to your Cursor MCP settings file:\n\n**macOS/Linux**: `~/.cursor/mcp.json`\n**Windows**: `%USERPROFILE%\\.cursor\\mcp.json`\n\n```json\n{\n  \"mcpServers\": {\n    \"google-analytics\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"mcp-google-analytics\"],\n      \"env\": {\n        \"GA_SERVICE_ACCOUNT_JSON\": \"/path/to/service-account.json\",\n        \"GA_PROPERTY_ID\": \"123456789\"\n      }\n    }\n  }\n}\n```\n\nRestart Cursor after updating the configuration.\n\n## 🛠️ Available Tools\n\n### At a Glance\n\n**Reading data (Google Analytics Data API)** — all read tools default to 10 rows to save tokens:\n\n| Tool | Purpose | Notes |\n|---|---|---|\n| `ga_run_report` | Custom reports with dimensions and metrics | Adjust `limit` as needed |\n| `ga_run_realtime_report` | Real-time data (last 30 minutes) | Great for verifying sent events |\n| `ga_get_metadata` | All available dimensions and metrics | Large response (500+ items), use sparingly |\n| `ga_list_accounts` | List accessible GA accounts | |\n| `ga_list_properties` | List GA4 properties | Aggregates all accounts if no `accountId` |\n| `ga_get_property` | Details of the configured property | |\n| `ga_list_data_streams` | Data streams of the property | Useful to find measurement IDs |\n| `ga_run_pivot_report` | Pivot table reports | Responses can be very large |\n| `ga_run_funnel_report` | Funnel analysis across event steps | Uses Data API v1alpha |\n| `ga_batch_run_reports` | Multiple reports in one request | 2–5 reports per batch recommended |\n| `ga_get_account_summaries` | All accounts and properties in one call | Fastest way to discover IDs |\n| `ga_list_custom_dimensions` | Custom dimensions of the property | Discover API names for reports |\n| `ga_list_custom_metrics` | Custom metrics of the property | Discover API names for reports |\n| `ga_list_key_events` | Key events (conversions) of the property | Know what counts as a conversion |\n| `ga_list_google_ads_links` | Google Ads accounts linked to the property | |\n| `ga_check_compatibility` | Validate dimension/metric combos before reporting | Avoids wasted requests and error loops |\n\n**Sending events (Measurement Protocol)**:\n\n| Tool | Purpose |\n|---|---|\n| `ga_send_event` | Any custom GA4 event with parameters |\n| `ga_validate_event` | Test an event against the debug endpoint without recording it |\n| `ga_send_pageview` | Page/screen views |\n| `ga_send_purchase` | Ecommerce purchases with transaction and items |\n| `ga_send_login` | User logins |\n| `ga_send_signup` | User registrations |\n| `ga_send_view_item` | Product/item detail views |\n| `ga_send_add_to_cart` | Add-to-cart events |\n| `ga_send_begin_checkout` | Checkout initiations |\n| `ga_send_refund` | Full or partial refunds |\n\n### Google Analytics Data API (Reading Data)\n\n#### `ga_run_report`\nRun custom reports with dimensions and metrics.\n\n**Common Dimensions**: `date`, `city`, `country`, `deviceCategory`, `browser`, `pagePath`, `eventName`, `sessionSource`, `sessionMedium`, `sessionCampaignName`\n\n**Common Metrics**: `activeUsers`, `sessions`, `screenPageViews`, `conversions`, `totalRevenue`, `engagementRate`, `averageSessionDuration`\n\n**Example**:\n```typescript\n{\n  \"dateRanges\": [{\"startDate\": \"7daysAgo\", \"endDate\": \"today\"}],\n  \"dimensions\": [{\"name\": \"city\"}],\n  \"metrics\": [{\"name\": \"activeUsers\"}],\n  \"limit\": 10\n}\n```\n\n#### `ga_run_realtime_report`\nGet real-time data (last 30 minutes).\n\n**Example**:\n```typescript\n{\n  \"metrics\": [{\"name\": \"activeUsers\"}],\n  \"dimensions\": [{\"name\": \"country\"}],\n  \"limit\": 10\n}\n```\n\n#### `ga_get_metadata`\nGet all available dimensions and metrics for your property.\n\n**Warning**: Returns 500+ items. Use sparingly.\n\n#### `ga_list_accounts`\nList all GA accounts accessible to the service account.\n\n#### `ga_list_properties`\nList GA4 properties, optionally filtered by account ID.\n\n#### `ga_get_property`\nGet details about the configured property.\n\n#### `ga_list_data_streams`\nList data streams for the configured property.\n\n#### `ga_run_pivot_report`\nRun pivot table reports with row/column dimensions.\n\n**Example**:\n```typescript\n{\n  \"dateRanges\": [{\"startDate\": \"7daysAgo\", \"endDate\": \"today\"}],\n  \"dimensions\": [{\"name\": \"country\"}, {\"name\": \"deviceCategory\"}],\n  \"metrics\": [{\"name\": \"activeUsers\"}],\n  \"pivots\": [{\"fieldNames\": [\"deviceCategory\"], \"limit\": 5}]\n}\n```\n\n#### `ga_run_funnel_report`\nRun funnel analysis to track user progression.\n\n**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`.\n\n**Example**:\n```typescript\n{\n  \"dateRanges\": [{\"startDate\": \"7daysAgo\", \"endDate\": \"today\"}],\n  \"funnelSteps\": [\n    {\"name\": \"page_view\"},\n    {\"name\": \"add_to_cart\"},\n    {\"name\": \"begin_checkout\"},\n    {\"name\": \"Purchase\", \"eventName\": \"purchase\"}\n  ]\n}\n```\n\n#### `ga_batch_run_reports`\nRun multiple reports in a single request.\n\n**Warning**: Can return large datasets. Limit to 2-5 reports per batch.\n\n#### `ga_get_account_summaries`\nGet all accessible accounts with their properties in a single compact call. The fastest way to discover account and property IDs.\n\n#### `ga_list_custom_dimensions` / `ga_list_custom_metrics`\nList 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.\n\n#### `ga_list_key_events`\nList the key events (conversions) configured for the property — useful before building conversion reports or deciding which events to send.\n\n#### `ga_list_google_ads_links`\nList Google Ads accounts linked to the property.\n\n#### `ga_check_compatibility`\nCheck whether a dimension/metric combination is valid **before** running a report, avoiding wasted requests and token-heavy error loops.\n\n**Example**:\n```typescript\n{\n  \"dimensions\": [{\"name\": \"city\"}],\n  \"metrics\": [{\"name\": \"activeUsers\"}],\n  \"compatibilityFilter\": \"COMPATIBLE\"\n}\n```\n\n### Measurement Protocol (Sending Events)\n\n> **Good to know**:\n> - Events take a few minutes to appear in standard reports, but show up almost immediately in the realtime report (`ga_run_realtime_report`).\n> - Use `ga_validate_event` to test new events without recording them.\n> - 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 **same `client_id`** to every call.\n\n#### `ga_send_event`\nSend custom events to GA4.\n\n**Example**:\n```typescript\n{\n  \"events\": [{\n    \"name\": \"button_click\",\n    \"params\": {\n      \"button_id\": \"cta_signup\",\n      \"page\": \"/landing\"\n    }\n  }],\n  \"user_id\": \"user123\"\n}\n```\n\n#### `ga_validate_event`\nValidate events before sending (uses debug endpoint).\n\n#### `ga_send_pageview`\nSend page view events.\n\n**Example**:\n```typescript\n{\n  \"page_location\": \"https://example.com/products\",\n  \"page_title\": \"Products\",\n  \"user_id\": \"user123\"\n}\n```\n\n#### `ga_send_purchase`\nSend ecommerce purchase events.\n\n**Example**:\n```typescript\n{\n  \"transaction_id\": \"T12345\",\n  \"value\": 99.99,\n  \"currency\": \"USD\",\n  \"items\": [{\n    \"item_id\": \"SKU123\",\n    \"item_name\": \"Product Name\",\n    \"price\": 99.99,\n    \"quantity\": 1\n  }]\n}\n```\n\n#### `ga_send_login`\nSend login events.\n\n#### `ga_send_signup`\nSend user registration events.\n\n#### `ga_send_view_item`\nSend product/item detail view events. Completes the standard ecommerce funnel: `view_item` → `add_to_cart` → `begin_checkout` → `purchase`.\n\n#### `ga_send_add_to_cart`\nSend add-to-cart events.\n\n#### `ga_send_begin_checkout`\nSend checkout initiation events.\n\n#### `ga_send_refund`\nSend 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.\n\n**Example (partial refund)**:\n```typescript\n{\n  \"transaction_id\": \"T12345\",\n  \"currency\": \"USD\",\n  \"value\": 49.99,\n  \"items\": [{\"item_id\": \"SKU123\", \"quantity\": 1}]\n}\n```\n\n## 📖 Usage Examples\n\nSee [EXAMPLES.md](EXAMPLES.md) for practical usage examples in Spanish.\n\n### Example: Get users by country (last 7 days)\n\n```\nShow me active users by country for the last 7 days\n```\n\nClaude will use `ga_run_report`:\n```json\n{\n  \"dateRanges\": [{\"startDate\": \"7daysAgo\", \"endDate\": \"today\"}],\n  \"dimensions\": [{\"name\": \"country\"}],\n  \"metrics\": [{\"name\": \"activeUsers\"}],\n  \"limit\": 10,\n  \"orderBys\": [{\"metric\": {\"metricName\": \"activeUsers\"}, \"desc\": true}]\n}\n```\n\n### Example: Track a purchase\n\n```\nSend a purchase event for order #12345, $99.99 USD\n```\n\nClaude will use `ga_send_purchase`:\n```json\n{\n  \"transaction_id\": \"12345\",\n  \"value\": 99.99,\n  \"currency\": \"USD\",\n  \"items\": [{\n    \"item_id\": \"product_1\",\n    \"item_name\": \"Example Product\",\n    \"price\": 99.99,\n    \"quantity\": 1\n  }]\n}\n```\n\n### Example: Validate an event before sending it\n\nRecommended before wiring up any new event: the debug endpoint checks the payload without recording anything.\n\n```\nValidate this tutorial_complete event before we send it for real\n```\n\nClaude will use `ga_validate_event`:\n```json\n{\n  \"client_id\": \"test.123\",\n  \"events\": [{\n    \"name\": \"tutorial_complete\",\n    \"params\": {\"tutorial_id\": \"onboarding\", \"duration_seconds\": 120}\n  }]\n}\n```\n\nThe response lists validation messages; an empty list means the event is well-formed.\n\n### Example: Server-side conversion tracking\n\nTrack signups or logins that happen in your backend, where no JavaScript tag runs:\n\n```\nA user just registered with Google OAuth, record the signup in Analytics\n```\n\nClaude will use `ga_send_signup`:\n```json\n{\n  \"user_id\": \"user_789\",\n  \"method\": \"Google\"\n}\n```\n\n### Example: Full ecommerce funnel from an agent\n\nSend the same `client_id` on each call so GA groups the events into one session:\n\n```\nTrack this user's journey: they added a $49 course to the cart, started checkout, and completed the purchase\n```\n\nClaude will chain `ga_send_add_to_cart` → `ga_send_begin_checkout` → `ga_send_purchase`, reusing the client ID:\n```json\n{\n  \"client_id\": \"555.1717000000\",\n  \"currency\": \"USD\",\n  \"value\": 49,\n  \"items\": [{\"item_id\": \"course_101\", \"item_name\": \"Intro Course\", \"price\": 49, \"quantity\": 1}]\n}\n```\n\n### Example: Custom events from automations\n\nMeasure things GA never sees natively, like AI agent activity or scheduled jobs:\n\n```\nLog that the weekly report generator ran successfully\n```\n\nClaude will use `ga_send_event`:\n```json\n{\n  \"events\": [{\n    \"name\": \"automation_run\",\n    \"params\": {\"job\": \"weekly_report\", \"status\": \"success\", \"duration_ms\": 5400}\n  }]\n}\n```\n\n### Example: Send and verify in one conversation\n\nCombine both APIs to confirm your tracking works end to end:\n\n```\nSend a test event and confirm Analytics received it\n```\n\nClaude will call `ga_send_event`, then check with `ga_run_realtime_report`:\n```json\n{\n  \"dimensions\": [{\"name\": \"eventName\"}],\n  \"metrics\": [{\"name\": \"eventCount\"}],\n  \"limit\": 10\n}\n```\n\nMeasurement Protocol events appear in the realtime report within seconds, while standard reports can take a few minutes.\n\n## 🔍 Debugging\n\nEnable debug logging by setting:\n\n```bash\nexport DEBUG=mcp-google-analytics:*\n```\n\nFor Measurement Protocol, use `ga_validate_event` to check events before sending them live.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📄 License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## 🔗 Links\n\n- [GitHub Repository](https://github.com/leonardosepulvedat/mcp-google-analytics)\n- [npm Package](https://www.npmjs.com/package/mcp-google-analytics)\n- [Smithery](https://smithery.ai/servers/lsepulvedatabares/mcp-google-analytics)\n- [MCP Documentation](https://modelcontextprotocol.io/)\n- [GA4 Data API Documentation](https://developers.google.com/analytics/devguides/reporting/data/v1)\n- [Measurement Protocol Documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4)\n\n## 🆘 Support\n\nFor issues and questions:\n- [GitHub Issues](https://github.com/leonardosepulvedat/mcp-google-analytics/issues)\n- [MCP Community Discord](https://discord.gg/modelcontextprotocol)\n\n## 📝 Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for version history.\n\n---\n",
  "bytes": 18774,
  "sha": "050c5583089660858059e15510e8b19fd52746b6333e3ffb304b238192a2d81f",
  "repo_slug": "leonardosepulvedat/mcp-google-analytics",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_leonardosepulvedat_mcp_google__d612afb9/readme"
}