Google Analytics 4 data to AI agents, agentic workflows, and MCP clients. Give agents analysis-ready access to website traffic, user behavior, and performance data with schema discovery, server-side aggregation, and safe defaults that reduce data wrangling.
mcp-name: io.github.surendranb/google-analytics-mcp
Connect Google Analytics 4 data to AI agents, agentic workflows, and MCP clients. Give agents analysis-ready access to website traffic, user behavior, and performance data with schema discovery, server-side aggregation, and safe defaults that reduce data wrangling.
Built for: AI agents, analyst copilots, and MCP runtimes across Claude, ChatGPT, Cursor, Windsurf, and custom hosts.
I also built a Google Search Console MCP that enables you to mix & match the data from both the sources
</p> ---Check your Python setup:
# Check Python version (need 3.10+)
python --version
python3 --version
# Check pip
pip --version
pip3 --versionRequired:
client_email fieldga4-mcp-server@your-project.iam.gserviceaccount.com)123456789)Verify your credentials:
pip install google-analytics-dataCreate 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.pyIf you see "✅ GA4 credentials working!" you're ready to proceed.
There are two supported ways to launch the server:
ga4-mcp-server when the installed console script is available on your PATHpython -m ga4_mcp when you want to use a specific interpreter or virtual environmentpython3 -m pip install google-analytics-mcpIf your machine uses python instead of python3, run:
python -m pip install google-analytics-mcpUse this when ga4-mcp-server is available on your PATH:
{
"mcpServers": {
"ga4-analytics": {
"command": "ga4-mcp-server",
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}Use this when you want to pin the exact Python runtime or when the console script is not on your PATH.
If python3 --version worked:
{
"mcpServers": {
"ga4-analytics": {
"command": "python3",
"args": ["-m", "ga4_mcp"],
"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"],
"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
python -m pip install .If you plan to modify the package locally, use python -m pip install -e . instead.
MCP Configuration:
{
"mcpServers": {
"ga4-analytics": {
"command": "/full/path/to/google-analytics-mcp/.venv/bin/python",
"args": ["-m", "ga4_mcp"],
"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 the absolute path to your JSON key123456789 with your numeric GA4 Property ID/full/path/to/google-analytics-mcp/.venv/bin/python with your virtual environment's Python 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 usersThis demonstrates:
Compare average session duration and pages per session by device category and browser over the last 90 daysThis demonstrates:
Show me conversion rates and revenue by traffic source and campaign, comparing last 30 days vs previous 30 daysThis 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 countAccess to 200+ GA4 dimensions and metrics organized by category:
If ga4-mcp-server is not found:
python -m ga4_mcpIf you get No module named ga4_mcp:
/full/path/to/python -m pip install google-analytics-mcpInstall the package with the exact interpreter you reference in your MCP configuration.
Permission errors:
# Try user install instead of system-wide
python -m pip install --user google-analytics-mcpIf the server says the credentials file is missing:
If the server says GA4_PROPERTY_ID is invalid or queries return no data:
123456789)G-XXXXXXXXXX)API quota/rate limit errors:
google-analytics-mcp/
├── ga4_mcp/ # Main package directory
│ ├── server.py # Core server logic
│ ├── coordinator.py # MCP instance
│ └── tools/ # Tool definitions (reporting, metadata)
├── pyproject.toml # Package configuration for PyPI
├── requirements.txt # Dependencies for local dev
├── README.md # This file
└── ...Apache License 2.0
surendranb/google-analytics-mcp
May 24, 2025
June 15, 2026
Python