home / mcp / google analytics mcp server
Provides an MCP server to connect Google Analytics 4 data to MCP clients with automatic OAuth 2.0 authentication and reporting.
Configuration
View docs{
"mcpServers": {
"gomarble-ai-google-analytics-mcp-server": {
"command": "/Users/marble-dev-01/workspace/google_analytics_mcp/.venv/bin/python",
"args": [
"/Users/marble-dev-01/workspace/google_analytics_mcp/server.py"
]
}
}
}You can run a FastMCP-powered server that connects Google Analytics 4 data to MCP clients, enabling OAuth 2.0 authentication, automatic token handling, and rich GA4 analytics directly from your preferred MCP consumer.
You use this MCP server by running it as a local or HTTP-accessible service and connecting your MCP client to it. Once authenticated, you can issue GA4 data queries through predefined tools that cover properties, page views, active users, events, traffic sources, device metrics, and custom reporting. The server handles all authentication, token refresh, and storage locally, so you donβt manage tokens in your client calls.
Prerequisites include Python 3.10 or newer, a Google Cloud Platform account, and a GA4 property with data access.
# Clone the MCP server
git clone https://github.com/yourusername/google-analytics-mcp-server.git
cd google-analytics-mcp-server
# Create a virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtConfigure OAuth credentials path in the environment before starting the server.
# Copy the example environment file
cp .env.example .env
# Edit the environment to point to your OAuth credentials
# Required: Path to OAuth credentials JSON file (downloaded from Google Cloud)
GOOGLE_ANALYTICS_OAUTH_CONFIG_PATH=/full/path/to/your/client_secret_file.json{
"mcpServers": {
"google-analytics": {
"command": "/full/path/to/your/project/.venv/bin/python",
"args": [
"/full/path/to/your/project/server.py"
]
}
}
}After configuring the environment and the Claude Desktop integration, restart Claude Desktop to load the new MCP server setting.
First-time authentication is initiated by issuing any GA4 command from Claude Desktop. A browser window opens for you to authenticate and authorize access to GA4 data. You should see a token file created locally (for example, google_analytics_token.json) and your GA4 properties appear in Claudeβs responses.
Store credentials and tokens locally with strict file permissions. Use environment variables for sensitive data in production. Regularly rotate tokens and monitor API usage in Google Cloud Console to stay within quotas.
If authentication fails, re-authenticate by triggering the GA4 command again and ensure the token file is present. If the server cannot connect, verify the Claude config and that the MCP server is reachable at the expected path or port.
Common GA4 queries you can run through the MCP interface include listing GA4 properties, retrieving page views, active users, events, and traffic sources, and creating custom reports with specific metrics and dimensions.
List all GA4 accounts and properties.
Get page view metrics for a property over a date range.
Get active users metrics by date range and optional dimensions.
Get event metrics for a property over a date range.
Get traffic source data over a date range with optional dimensions.
Get device-based metrics with optional dimensions.
Create comprehensive custom reports with metrics, dimensions, and filters.