by surendranb
Provides natural‑language access to Google Analytics 4 data via MCP, exposing over 200 dimensions and metrics for Claude, Cursor and other compatible clients.
Google Analytics MCP Server bridges Google Analytics 4 with MCP‑compatible AI assistants, enabling users to query website traffic, user behavior, and e‑commerce data in plain English. It taps into more than 200 GA4 dimensions and metrics, handling aggregation and row‑volume optimization automatically.
pip install google-analytics-mcp
(recommended) or clone the repo and install the requirements.ga4_mcp_server
) and set the environment variables GOOGLE_APPLICATION_CREDENTIALS
and GA4_PROPERTY_ID
.get_ga4_data
, list_dimension_categories
, list_metric_categories
, get_dimensions_by_category
, get_metrics_by_category
.limit
, proceed_with_large_dataset
, enable_aggregation
, estimate_only
.Q: Which Python version is required? A: Python 3.10 or higher.
Q: Do I need a Google Cloud project? A: Yes – a service account with the Analytics Data API enabled and Viewer access to the GA4 property.
Q: How do I avoid context‑window crashes?
A: The server automatically estimates row counts and suggests aggregations; you can also set limit
or proceed_with_large_dataset
.
Q: Can I use the server with other MCP clients? A: Any client that follows the MCP protocol can connect, not just Claude or Cursor.
Q: What if I receive credential errors? A: Verify the JSON key path, ensure the service account email is added to GA4 Property access, and confirm you are using the numeric Property ID (not the Measurement ID).
Connect Google Analytics 4 data to Claude, Cursor and other MCP clients. Query your website traffic, user behavior, and analytics data in natural language with access to 200+ GA4 dimensions and metrics.
Compatible with: Claude, Cursor and other MCP clients.
I also built a Google Search Console MCP that enables you to mix & match the data from both the sources
Check your Python setup:
# Check Python version (need 3.10+)
python --version
python3 --version
# Check pip
pip --version
pip3 --version
Required:
client_email
fieldga4-mcp-server@your-project.iam.gserviceaccount.com
)123456789
)
Verify your credentials:
pip install google-analytics-data
Create a test script (test_ga4.py
):
import os
from google.analytics.data_v1beta import BetaAnalyticsDataClient
# Set credentials path
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/your/service-account-key.json"
# Test connection
client = BetaAnalyticsDataClient()
print("✅ GA4 credentials working!")
Run the test:
python test_ga4.py
If you see "✅ GA4 credentials working!" you're ready to proceed.
Choose one method:
pip install google-analytics-mcp
MCP Configuration:
First, check your Python command:
python3 --version
python --version
Then use the appropriate configuration:
If python3 --version
worked:
{
"mcpServers": {
"ga4-analytics": {
"command": "python3",
"args": ["-m", "ga4_mcp_server"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}
If python --version
worked:
{
"mcpServers": {
"ga4-analytics": {
"command": "python",
"args": ["-m", "ga4_mcp_server"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}
git clone https://github.com/surendranb/google-analytics-mcp.git
cd google-analytics-mcp
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
MCP Configuration:
{
"mcpServers": {
"ga4-analytics": {
"command": "/full/path/to/ga4-mcp-server/venv/bin/python",
"args": ["/full/path/to/ga4-mcp-server/ga4_mcp_server.py"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}
Replace these placeholders in your MCP configuration:
/path/to/your/service-account-key.json
with your JSON file path123456789
with your GA4 Property ID/full/path/to/ga4-mcp-server/
with your download path (Method B only)Once configured, ask your MCP client questions like:
Try these example queries to see the MCP's analytical capabilities:
Show me a map of visitors by city for the last 30 days, with a breakdown of new vs returning users
This demonstrates:
Compare average session duration and pages per session by device category and browser over the last 90 days
This demonstrates:
Show me conversion rates and revenue by traffic source and campaign, comparing last 30 days vs previous 30 days
This demonstrates:
What are my top 10 pages by engagement rate, and how has their performance changed over the last 3 months?
This demonstrates:
This MCP server includes built-in optimizations to prevent context window crashes and ensure smooth operation:
limit
- Set maximum number of rows to returnproceed_with_large_dataset=True
- Override warnings for large datasetsenable_aggregation=False
- Disable automatic aggregationestimate_only=True
- Get row count estimates without fetching data# This query would normally return 2,605 rows and crash context window
get_ga4_data(
dimensions=["date", "pagePath", "country"],
date_range_start="90daysAgo"
)
# Returns: {"warning": True, "estimated_rows": 2605, "suggestions": [...]}
# Use monthly aggregation instead
get_ga4_data(
dimensions=["month", "pagePath", "country"],
date_range_start="90daysAgo"
)
# Returns: Clean monthly data with manageable row count
The server provides 5 main tools with built-in optimization to prevent context window crashes:
get_ga4_data
- Retrieve GA4 data with custom dimensions and metrics
limit
, proceed_with_large_dataset
, enable_aggregation
list_dimension_categories
- Browse available dimension categorieslist_metric_categories
- Browse available metric categoriesget_dimensions_by_category
- Get dimensions for a specific categoryget_metrics_by_category
- Get metrics for a specific categoryAccess to 200+ GA4 dimensions and metrics organized by category:
If you get "No module named ga4_mcp_server" (Method A):
pip3 install --user google-analytics-mcp
If you get "executable file not found":
python
vs python3
)pip3
instead of pip
if neededPermission errors:
# Try user install instead of system-wide
pip install --user google-analytics-mcp
Credentials not working:
123456789
) ✅G-XXXXXXXXXX
) ❌API quota/rate limit errors:
google-analytics-mcp/
├── ga4_mcp_server.py # Main MCP server
├── ga4_dimensions.json # All available GA4 dimensions
├── ga4_metrics.json # All available GA4 metrics
├── requirements.txt # Python dependencies
├── pyproject.toml # Package configuration
├── README.md # This file
└── claude-config-template.json # MCP configuration template
MIT License
Please log in to share your review and rating for this MCP.
{ "mcpServers": { "ga4-analytics": { "command": "python3", "args": [ "-m", "ga4_mcp_server" ], "env": { "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json", "GA4_PROPERTY_ID": "123456789" } } } }
Explore related MCPs that share similar capabilities and solve comparable challenges
by antvis
Offers over 25 AntV chart types for automated chart generation and data analysis, callable via MCP tools, CLI, HTTP, SSE, or streamable transports.
by reading-plus-ai
A versatile tool that enables interactive data exploration through prompts, CSV loading, and script execution.
by Canner
Provides a semantic engine that lets MCP clients and AI agents query enterprise data with contextual understanding, precise calculations, and built‑in governance.
by ergut
Provides secure, read‑only access to BigQuery datasets, allowing large language models to query and analyze data through a standardized interface.
by isaacwasserman
Provides an interface for LLMs to visualize data using Vega‑Lite syntax, supporting saving of data tables and rendering visualizations as either a full Vega‑Lite specification (text) or a base64‑encoded PNG image.
by vantage-sh
Fetch and explore cloud cost and usage data from a Vantage account using natural language through AI assistants and MCP clients.
by acryldata
Provides a Model Context Protocol server that enables searching, metadata retrieval, lineage traversal, and SQL query listing for DataHub entities.
by rishijatia
Provides programmatic access to Fantasy Premier League statistics, team information, gameweeks, and analysis tools via a Model Context Protocol server.
by gomarble-ai
Provides seamless integration of the Google Ads API with Model Context Protocol clients, handling OAuth 2.0 authentication, automatic token refresh, GAQL query execution, account management, and keyword‑research capabilities.