
Google Analytics
STDIOMCP server for accessing Google Analytics 4 data with customizable metrics
MCP server for accessing Google Analytics 4 data with customizable metrics
An MCP server implementation for accessing Google Analytics 4 (GA4) data, built using the Model Context Protocol TypeScript SDK.
To use this server, you need to configure authentication with Google Analytics. This is done using a service account.
client_email
from the JSON credentials file you downloaded.The server requires the following environment variables:
GOOGLE_CLIENT_EMAIL
: The client_email
from your service account JSON file.GOOGLE_PRIVATE_KEY
: The private_key
from your service account JSON file.GA_PROPERTY_ID
: Your Google Analytics 4 property ID.You can set them in your environment or use a .env
file.
export GOOGLE_CLIENT_EMAIL="[email protected]" export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n" export GA_PROPERTY_ID="your_property_id"
To install Google Analytics Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mcp-server-google-analytics --client claude
npm install -g mcp-server-google-analytics
Or use with npx directly:
npx mcp-server-google-analytics
pnpm start
Add this to your Claude Desktop configuration:
{ "mcpServers": { "google-analytics": { "command": "npx", "args": ["-y", "mcp-server-google-analytics"], "env": { "GOOGLE_CLIENT_EMAIL": "[email protected]", "GOOGLE_PRIVATE_KEY": "your-private-key", "GA_PROPERTY_ID": "your-ga4-property-id" } } } }
Run a flexible report to get analytics data.
Input:
{ "startDate": "2024-01-01", "endDate": "2024-01-31", "dimensions": [{ "name": "country" }, { "name": "city" }], "metrics": [{ "name": "activeUsers" }, { "name": "newUsers" }], "dimensionFilter": { "filter": { "fieldName": "country", "stringFilter": { "value": "United States" } } } }
Get page view metrics for a specific date range:
{ "startDate": "2024-01-01", "endDate": "2024-01-31", "dimensions": ["page", "country"] // Optional }
Get active users metrics:
{ "startDate": "2024-01-01", "endDate": "2024-01-31" }
Get event metrics:
{ "startDate": "2024-01-01", "endDate": "2024-01-31", "eventName": "purchase" // Optional }
Get user behavior metrics:
{ "startDate": "2024-01-01", "endDate": "2024-01-31" }
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.