Google Analytics MCP Server
Connects Google Analytics 4 data to Claude, Cursor and other MCP clients, enabling natural language queries of website traffic, user behavior, and analytics data with access to 200+ GA4 dimensions and metrics.
README
<p align="center"> <img src="logo.png" alt="Google Analytics MCP Logo" width="120" />
Google Analytics MCP Server
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. </p>
Prerequisites
Check your Python setup:
# Check Python version (need 3.8+)
python --version
python3 --version
# Check pip
pip --version
pip3 --version
Required:
- Python 3.8 or higher
- Google Analytics 4 property with data
- Service account with Analytics Reporting API access
Step 1: Setup Google Analytics Credentials
Create Service Account in Google Cloud Console
- Go to Google Cloud Console
- Create or select a project:
- New project: Click "New Project" → Enter project name → Create
- Existing project: Select from dropdown
- Enable the Analytics APIs:
- Go to "APIs & Services" → "Library"
- Search for "Google Analytics Reporting API" → Click "Enable"
- Search for "Google Analytics Data API" → Click "Enable"
- Create Service Account:
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "Service Account"
- Enter name (e.g., "ga4-mcp-server")
- Click "Create and Continue"
- Skip role assignment → Click "Done"
- Download JSON Key:
- Click your service account
- Go to "Keys" tab → "Add Key" → "Create New Key"
- Select "JSON" → Click "Create"
- Save the JSON file - you'll need its path
Add Service Account to GA4
- Get service account email:
- Open the JSON file
- Find the
client_emailfield - Copy the email (format:
ga4-mcp-server@your-project.iam.gserviceaccount.com)
- Add to GA4 property:
- Go to Google Analytics
- Select your GA4 property
- Click "Admin" (gear icon at bottom left)
- Under "Property" → Click "Property access management"
- Click "+" → "Add users"
- Paste the service account email
- Select "Viewer" role
- Uncheck "Notify new users by email"
- Click "Add"
Find Your GA4 Property ID
- In Google Analytics, select your property
- Click "Admin" (gear icon)
- Under "Property" → Click "Property details"
- Copy the Property ID (numeric, e.g.,
123456789)- Note: This is different from the "Measurement ID" (starts with G-)
Test Your Setup (Optional)
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.
Step 2: Install the MCP Server
Choose one method:
Method A: pip install (Recommended)
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"
}
}
}
}
Method B: GitHub download
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"
}
}
}
}
Step 3: Update Configuration
Replace these placeholders in your MCP configuration:
/path/to/your/service-account-key.jsonwith your JSON file path123456789with your GA4 Property ID/full/path/to/ga4-mcp-server/with your download path (Method B only)
Usage
Once configured, ask your MCP client questions like:
Discovery & Exploration
- What GA4 dimension categories are available?
- Show me all ecommerce metrics
- What dimensions can I use for geographic analysis?
Traffic Analysis
- What's my website traffic for the past week?
- Show me user metrics by city for last month
- Compare bounce rates between different date ranges
Multi-Dimensional Analysis
- Show me revenue by country and device category for last 30 days
- Analyze sessions and conversions by campaign and source/medium
- Compare user engagement across different page paths and traffic sources
E-commerce Analysis
- What are my top-performing products by revenue?
- Show me conversion rates by traffic source and device type
- Analyze purchase behavior by user demographics
Quick Start Examples
Try these example queries to see the MCP's analytical capabilities:
1. Geographic Distribution
Show me a map of visitors by city for the last 30 days, with a breakdown of new vs returning users
This demonstrates:
- Geographic analysis
- User segmentation
- Time-based filtering
- Data visualization
2. User Behavior Analysis
Compare average session duration and pages per session by device category and browser over the last 90 days
This demonstrates:
- Multi-dimensional analysis
- Time series comparison
- User engagement metrics
- Technology segmentation
3. Traffic Source Performance
Show me conversion rates and revenue by traffic source and campaign, comparing last 30 days vs previous 30 days
This demonstrates:
- Marketing performance analysis
- Period-over-period comparison
- Conversion tracking
- Revenue attribution
4. Content Performance
What are my top 10 pages by engagement rate, and how has their performance changed over the last 3 months?
This demonstrates:
- Content analysis
- Trend analysis
- Engagement metrics
- Ranking and sorting
Available Tools
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 category
Dimensions & Metrics
Access to 200+ GA4 dimensions and metrics organized by category:
Dimension Categories
- Time: date, hour, month, year, etc.
- Geography: country, city, region
- Technology: browser, device, operating system
- Traffic Source: campaign, source, medium, channel groups
- Content: page paths, titles, content groups
- E-commerce: item details, transaction info
- User Demographics: age, gender, language
- Google Ads: campaign, ad group, keyword data
- And 10+ more categories
Metric Categories
- User Metrics: totalUsers, newUsers, activeUsers
- Session Metrics: sessions, bounceRate, engagementRate
- E-commerce: totalRevenue, transactions, conversions
- Events: eventCount, conversions, event values
- Advertising: adRevenue, returnOnAdSpend
- And more specialized metrics
Troubleshooting
If you get "No module named ga4_mcp_server" (Method A):
pip3 install --user google-analytics-mcp
If you get "executable file not found":
- Try the other Python command (
pythonvspython3) - Use
pip3instead ofpipif needed
Permission errors:
# Try user install instead of system-wide
pip install --user google-analytics-mcp
Credentials not working:
- Verify the JSON file path is correct and accessible
- Check service account permissions:
- Go to Google Cloud Console → IAM & Admin → IAM
- Find your service account → Check permissions
- Verify GA4 access:
- GA4 → Admin → Property access management
- Check for your service account email
- Verify ID type:
- Property ID: numeric (e.g.,
123456789) ✅ - Measurement ID: starts with G- (e.g.,
G-XXXXXXXXXX) ❌
- Property ID: numeric (e.g.,
API quota/rate limit errors:
- GA4 has daily quotas and rate limits
- Try reducing the date range in your queries
- Wait a few minutes between large requests
Project Structure
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
License
MIT License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.