MCP Google Analytics Server
This server provides full Google Analytics 4 integration, allowing you to both read analytics data via the GA4 Data API and send/track events via the Measurement Protocol.
Reading & Reporting:
Run custom reports (
ga_run_report) with any dimensions and metrics over custom date ranges.Access real-time data (
ga_run_realtime_report) for the last 30 minutes.Run pivot (
ga_run_pivot_report) and funnel (ga_run_funnel_report) analyses.Execute multiple reports in one request (
ga_batch_run_reports; recommended 2‑5 per batch).Retrieve metadata (
ga_get_metadata) for available dimensions and metrics.Manage accounts and properties: list accounts (
ga_list_accounts), list properties (ga_list_properties), get property details (ga_get_property), list data streams (ga_list_data_streams).
Sending & Tracking Events:
Send custom events (
ga_send_event) with any parameters.Validate events (
ga_validate_event) without recording them.Dedicated methods for pageview, purchase, login, signup, add-to-cart, and begin-checkout.
Link events to the same user session via
client_idand supportuser_idfor cross-device tracking.
Key Features:
All read tools default to 10 rows for token efficiency, with configurable limit and offset for pagination.
Events appear in real-time reports within seconds, enabling end-to-end verification.
Easy setup with MCP clients like Claude Desktop and Cursor.
Provides comprehensive integration with Google Analytics 4, including the Data API for running reports (custom, realtime, pivot, funnel, and batch reports) and Measurement Protocol v2 for sending events (page views, purchases, logins, signups, and custom events).
Uses Google Cloud Console for authentication and API access, requiring service account creation and Google Analytics Data API enablement for reading GA4 data.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Google Analytics Server show me active users for the last 7 days"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
⚡ 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)).
Related MCP server: GA4 MCP Server
💡 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 neededUse 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
npm install -g mcp-google-analyticsOption 2: Use with npx (no installation needed)
npx mcp-google-analytics🔧 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).
{
"mcpServers": {
"google-analytics": {
"command": "npx",
"args": ["-y", "mcp-google-analytics"],
"env": {
"GA_SERVICE_ACCOUNT_JSON": "/path/to/service-account.json",
"GA_PROPERTY_ID": "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:
"GA_MEASUREMENT_ID": "G-XXXXXXXXXX",
"GA_API_SECRET": "your-api-secret"🏢 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:
Show me all my accounts and properties → ga_get_account_summaries
Compare last week's active users between the → ga_run_report with propertyId "111111"
Acme property and the Globex property and again with propertyId "222222"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
{
"mcpServers": {
"google-analytics": {
"command": "npx",
"args": ["-y", "mcp-google-analytics"],
"env": {
"GA_SERVICE_ACCOUNT_JSON": "/path/to/service-account.json",
"GA_PROPERTY_ID": "123456789"
}
}
}
}Or if installed globally:
{
"mcpServers": {
"google-analytics": {
"command": "mcp-google-analytics",
"env": {
"GA_SERVICE_ACCOUNT_JSON": "/path/to/service-account.json",
"GA_PROPERTY_ID": "123456789"
}
}
}
}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
{
"mcpServers": {
"google-analytics": {
"command": "npx",
"args": ["-y", "mcp-google-analytics"],
"env": {
"GA_SERVICE_ACCOUNT_JSON": "/path/to/service-account.json",
"GA_PROPERTY_ID": "123456789"
}
}
}
}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:
Tool | Purpose | Notes |
| Custom reports with dimensions and metrics | Adjust |
| Real-time data (last 30 minutes) | Great for verifying sent events |
| All available dimensions and metrics | Large response (500+ items), use sparingly |
| List accessible GA accounts | |
| List GA4 properties | Aggregates all accounts if no |
| Details of the configured property | |
| Data streams of the property | Useful to find measurement IDs |
| Pivot table reports | Responses can be very large |
| Funnel analysis across event steps | Uses Data API v1alpha |
| Multiple reports in one request | 2–5 reports per batch recommended |
| All accounts and properties in one call | Fastest way to discover IDs |
| Custom dimensions of the property | Discover API names for reports |
| Custom metrics of the property | Discover API names for reports |
| Key events (conversions) of the property | Know what counts as a conversion |
| Google Ads accounts linked to the property | |
| Validate dimension/metric combos before reporting | Avoids wasted requests and error loops |
Sending events (Measurement Protocol):
Tool | Purpose |
| Any custom GA4 event with parameters |
| Test an event against the debug endpoint without recording it |
| Page/screen views |
| Ecommerce purchases with transaction and items |
| User logins |
| User registrations |
| Product/item detail views |
| Add-to-cart events |
| Checkout initiations |
| Full or partial refunds |
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:
{
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
"dimensions": [{"name": "city"}],
"metrics": [{"name": "activeUsers"}],
"limit": 10
}ga_run_realtime_report
Get real-time data (last 30 minutes).
Example:
{
"metrics": [{"name": "activeUsers"}],
"dimensions": [{"name": "country"}],
"limit": 10
}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:
{
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
"dimensions": [{"name": "country"}, {"name": "deviceCategory"}],
"metrics": [{"name": "activeUsers"}],
"pivots": [{"fieldNames": ["deviceCategory"], "limit": 5}]
}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:
{
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
"funnelSteps": [
{"name": "page_view"},
{"name": "add_to_cart"},
{"name": "begin_checkout"},
{"name": "Purchase", "eventName": "purchase"}
]
}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:
{
"dimensions": [{"name": "city"}],
"metrics": [{"name": "activeUsers"}],
"compatibilityFilter": "COMPATIBLE"
}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:
{
"events": [{
"name": "button_click",
"params": {
"button_id": "cta_signup",
"page": "/landing"
}
}],
"user_id": "user123"
}ga_validate_event
Validate events before sending (uses debug endpoint).
ga_send_pageview
Send page view events.
Example:
{
"page_location": "https://example.com/products",
"page_title": "Products",
"user_id": "user123"
}ga_send_purchase
Send ecommerce purchase events.
Example:
{
"transaction_id": "T12345",
"value": 99.99,
"currency": "USD",
"items": [{
"item_id": "SKU123",
"item_name": "Product Name",
"price": 99.99,
"quantity": 1
}]
}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):
{
"transaction_id": "T12345",
"currency": "USD",
"value": 49.99,
"items": [{"item_id": "SKU123", "quantity": 1}]
}📖 Usage Examples
See EXAMPLES.md for practical usage examples in Spanish.
Example: Get users by country (last 7 days)
Show me active users by country for the last 7 daysClaude will use ga_run_report:
{
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
"dimensions": [{"name": "country"}],
"metrics": [{"name": "activeUsers"}],
"limit": 10,
"orderBys": [{"metric": {"metricName": "activeUsers"}, "desc": true}]
}Example: Track a purchase
Send a purchase event for order #12345, $99.99 USDClaude will use ga_send_purchase:
{
"transaction_id": "12345",
"value": 99.99,
"currency": "USD",
"items": [{
"item_id": "product_1",
"item_name": "Example Product",
"price": 99.99,
"quantity": 1
}]
}Example: Validate an event before sending it
Recommended before wiring up any new event: the debug endpoint checks the payload without recording anything.
Validate this tutorial_complete event before we send it for realClaude will use ga_validate_event:
{
"client_id": "test.123",
"events": [{
"name": "tutorial_complete",
"params": {"tutorial_id": "onboarding", "duration_seconds": 120}
}]
}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:
A user just registered with Google OAuth, record the signup in AnalyticsClaude will use ga_send_signup:
{
"user_id": "user_789",
"method": "Google"
}Example: Full ecommerce funnel from an agent
Send the same client_id on each call so GA groups the events into one session:
Track this user's journey: they added a $49 course to the cart, started checkout, and completed the purchaseClaude will chain ga_send_add_to_cart → ga_send_begin_checkout → ga_send_purchase, reusing the client ID:
{
"client_id": "555.1717000000",
"currency": "USD",
"value": 49,
"items": [{"item_id": "course_101", "item_name": "Intro Course", "price": 49, "quantity": 1}]
}Example: Custom events from automations
Measure things GA never sees natively, like AI agent activity or scheduled jobs:
Log that the weekly report generator ran successfullyClaude will use ga_send_event:
{
"events": [{
"name": "automation_run",
"params": {"job": "weekly_report", "status": "success", "duration_ms": 5400}
}]
}Example: Send and verify in one conversation
Combine both APIs to confirm your tracking works end to end:
Send a test event and confirm Analytics received itClaude will call ga_send_event, then check with ga_run_realtime_report:
{
"dimensions": [{"name": "eventName"}],
"metrics": [{"name": "eventCount"}],
"limit": 10
}Measurement Protocol events appear in the realtime report within seconds, while standard reports can take a few minutes.
🔍 Debugging
Enable debug logging by setting:
export DEBUG=mcp-google-analytics:*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
🆘 Support
For issues and questions:
📝 Changelog
See CHANGELOG.md for version history.
Available Tools
26 toolsga_batch_run_reportsARead-onlyIdempotent
Run multiple reports in a single request.
⚠️ TOKEN OPTIMIZATION: Can return LARGE amounts of data. Limit to 2-5 reports per batch. Each report should have small limits.
Inputs: requests (required), propertyId.
ga_check_compatibilityARead-onlyIdempotent
Check whether a combination of dimensions and metrics is valid for this property BEFORE running a report.
Avoids wasted report requests and token-heavy error loops. Also lists which other fields remain compatible with the given combination.
Inputs: metrics, dimensions, propertyId, compatibilityFilter.
ga_get_account_summariesARead-onlyIdempotent
Get a compact overview of all accessible GA accounts and their properties in a single call.
The fastest way to discover account IDs, property IDs, and property names.
Inputs: no named parameters.
ga_get_metadataARead-onlyIdempotent
Get available dimensions and metrics metadata for your GA4 property.
⚠️ TOKEN OPTIMIZATION: This returns ALL available dimensions and metrics. Response can be large (~500+ items). Use sparingly and cache results when possible.
Inputs: propertyId.
ga_get_propertyARead-onlyIdempotent
Get details about a GA4 property (the configured one, or any accessible property via propertyId).
Inputs: propertyId.
ga_list_accountsARead-onlyIdempotent
List all Google Analytics accounts accessible to the service account.
Use this to find account IDs for listing properties.
Inputs: no named parameters.
ga_list_custom_dimensionsARead-onlyIdempotent
List all custom dimensions defined for the configured GA4 property.
Use this to discover custom dimension API names (e.g., "customEvent:plan_type") for reports.
Inputs: propertyId.
ga_list_custom_metricsARead-onlyIdempotent
List all custom metrics defined for the configured GA4 property.
Use this to discover custom metric API names for reports.
Inputs: propertyId.
ga_list_data_streamsARead-onlyIdempotent
List data streams for the configured GA4 property.
Use this to find measurement IDs for Measurement Protocol.
Inputs: propertyId.
ga_list_google_ads_linksARead-onlyIdempotent
List Google Ads accounts linked to a GA4 property.
Inputs: propertyId.
ga_list_key_eventsARead-onlyIdempotent
List the key events (conversions) configured for the GA4 property.
Useful to know which event names count as conversions before building reports or sending events.
Inputs: propertyId.
ga_list_propertiesARead-onlyIdempotent
List Google Analytics properties.
Optionally filter by account ID. Without an account ID, properties from all accessible accounts are aggregated.
Inputs: accountId.
ga_run_funnel_reportARead-onlyIdempotent
Run a funnel analysis report to track user progression through steps (Data API v1alpha).
Each step matches an event: set 'eventName' per step (defaults to the step name). For advanced matching, pass a full 'filterExpression' instead.
Inputs: dateRanges (required), funnelSteps (required), propertyId, funnelBreakdown, +1 more.
ga_run_pivot_reportARead-onlyIdempotent
Run a pivot table report with row and column dimensions.
⚠️ TOKEN OPTIMIZATION: Pivot reports can be VERY large. Limit dimensions and use small date ranges. Recommended for analysis, not raw data extraction.
Inputs: pivots (required), metrics (required), dateRanges (required), dimensions, +1 more.
ga_run_realtime_reportARead-onlyIdempotent
Get real-time Google Analytics data (last 30 minutes).
⚠️ TOKEN OPTIMIZATION: Use 'limit' to control result size (default: 10).
Common dimensions: city, country, deviceCategory, unifiedScreenName Common metrics: activeUsers, screenPageViews, conversions
Inputs: metrics (required), limit, dimensions, propertyId.
ga_run_reportARead-onlyIdempotent
Run a custom Google Analytics report with dimensions and metrics.
⚠️ TOKEN OPTIMIZATION: Use 'limit' to control result size (default: 10). This tool can consume significant tokens with large datasets.
Common dimensions: date, city, country, deviceCategory, browser, pagePath, eventName Common metrics: activeUsers, sessions, screenPageViews, conversions, totalRevenue
Inputs: metrics (required), dateRanges (required), limit, offset, +5 more.
ga_send_add_to_cartA
Send an add to cart event to Google Analytics.
Ecommerce event for tracking when items are added to shopping cart.
Inputs: items (required), value (required), currency (required), user_id, +2 more.
ga_send_begin_checkoutA
Send a begin checkout event to Google Analytics.
Ecommerce event for tracking when users start the checkout process.
Inputs: items (required), value (required), currency (required), coupon, +3 more.
ga_send_eventA
Send a custom event to Google Analytics via Measurement Protocol.
Use this for tracking custom user actions, conversions, or any GA4 event. Events are processed asynchronously and appear in reports within minutes.
Common events: click, form_submit, video_play, file_download, custom_conversion
Inputs: events (required), user_id, client_id, user_properties.
ga_send_loginB
Send a login event to Google Analytics.
Standard event for tracking user logins with authentication method.
Inputs: method (required), user_id, client_id, user_properties.
ga_send_pageviewA
Send a page view event to Google Analytics.
Standard event for tracking page/screen views. Automatically uses 'page_view' event name.
Inputs: page_location (required), user_id, client_id, page_title, +2 more.
ga_send_purchaseA
Send an ecommerce purchase event to Google Analytics.
Standard event for tracking completed purchases with transaction details and items.
Inputs: items (required), value (required), currency (required), transaction_id (required), +7 more.
ga_send_refundA
Send a refund event to Google Analytics.
Ecommerce event for full or partial refunds. Omit 'items' for a full refund; include them (with quantities) for a partial refund. Use the same transaction_id as the original purchase.
Inputs: transaction_id (required), items, value, user_id, +3 more.
ga_send_signupA
Send a sign-up event to Google Analytics.
Standard event for tracking new user registrations.
Inputs: method (required), user_id, client_id, user_properties.
ga_send_view_itemA
Send a view item event to Google Analytics.
Ecommerce event for tracking product/item detail views. Completes the standard funnel: view_item → add_to_cart → begin_checkout → purchase.
Inputs: items (required), value (required), currency (required), user_id, +2 more.
ga_validate_eventARead-onlyIdempotent
Validate an event before sending it to Google Analytics.
Uses GA4's debug endpoint to check for errors without recording the event. Returns validation messages and errors if any.
Inputs: events (required), user_id, client_id, user_properties.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 26 tools
Most tools are clearly separated by resource and action, but the generic ga_send_event overlaps with all of the specialized send_* tools (pageview, purchase, login, etc.), and several account/property discovery tools serve similar listing purposes. Descriptions help agents choose, but misselection is possible when a generic call could substitute for a specific convenience wrapper.
Names consistently use a ga_ prefix and snake_case, with a mostly clear verb_noun pattern (list_*, get_*, send_*, run_*). The main deviation is ga_batch_run_reports, which breaks the run_*_report pattern, and a few event names that embed verbs like send_add_to_cart and send_begin_checkout.
At 26 tools, this is on the heavy side, especially because many send_* event helpers could be consolidated under ga_send_event and several report variants could share a single endpoint. Still, the breadth is not unreasonable for a GA4 server covering admin discovery, reporting, metadata, and Measurement Protocol event collection.
The surface covers the main analytics workflows well: account/property discovery, metadata and compatibility checks, multiple report types, plus custom and standard event sending. The main gap is the lack of create/update/delete operations for admin resources like properties, data streams, or custom dimensions/metrics, though those may be outside the server's intended scope.
Maintenance
Related MCP Connectors
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
Connect Google Analytics to ChatGPT. Query GA4 data in plain English and get instant insights.
Hosted, read-only Google Analytics 4 MCP: reports, period comparisons, realtime, custom fields.
SEO & marketing toolkit for AI agents: GA4, Search Console, AdSense, GTM, PageSpeed, Trends.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Google Analytics APIs to fetch reports, manage properties, data streams, conversion events, and custom dimensions/metrics through OAuth2 authentication.54 npm6MIT
- FlicenseAqualityDmaintenanceEnables interaction with Google Analytics 4 to manage accounts, run standard or realtime reports, and validate event parameters. It supports dual authentication methods and integrates with GTM for end-to-end data collection orchestration.8-
- AlicenseNot gradedqualityCmaintenanceProvides full Google Analytics 4 management and reporting capabilities via MCP, including property management, custom dimensions, audiences, events, data streams, and real-time reporting.MIT
- AlicenseBqualityDmaintenanceEnables managing Google Analytics 4 properties, data streams, conversions, and running reports using natural language through the Admin and Data APIs.2338 PyPIMIT