The Google Analytics MCP server allows you to query your Google Analytics 4 data using natural language through Claude, Cursor, and other MCP clients. It provides access to over 200 GA4 dimensions and metrics, enabling you to analyze website traffic, user behavior, and analytics data through conversational interfaces.
Before installing the server, ensure you have:
You can verify your Python setup with these commands:
# Check Python version (need 3.10+)
python --version
python3 --version
# Check pip
pip --version
pip3 --version
client_email
field[email protected]
)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
Choose one of these installation methods:
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, you can ask your MCP client various types of questions:
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
Compare average session duration and pages per session by device category and browser over the last 90 days
Show me conversion rates and revenue by traffic source and campaign, comparing last 30 days vs previous 30 days
What are my top 10 pages by engagement rate, and how has their performance changed over the last 3 months?
The server provides 5 main tools:
get_ga4_data
- Retrieve GA4 data with custom dimensions and metricslist_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 over 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:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "ga4-analytics" '{"command":"python3","args":["-m","ga4_mcp_server"],"env":{"GOOGLE_APPLICATION_CREDENTIALS":"/path/to/your/service-account-key.json","GA4_PROPERTY_ID":"123456789"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"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"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"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"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect