what is Google Analytics MCP Server?
Google Analytics MCP Server is an implementation that allows users to access Google Analytics 4 (GA4) data using the Model Context Protocol TypeScript SDK.
how to use Google Analytics MCP Server?
To use the server, set up a Google Cloud project, enable the Analytics Data API, create a service account, and configure the server with your credentials. Start the server using the provided commands.
key features of Google Analytics MCP Server?
- Retrieve page view metrics with customizable dimensions.
- Track active and new users over time.
- Analyze specific events and their metrics.
- Monitor user behavior metrics such as session duration and bounce rate.
- Flexible date range selection for all queries.
use cases of Google Analytics MCP Server?
- Analyzing website traffic and user engagement metrics.
- Monitoring user behavior to improve website performance.
- Tracking specific events like purchases or sign-ups.
FAQ from Google Analytics MCP Server?
- What are the prerequisites for using this server?
You need Node.js 20 or higher, a Google Analytics 4 property, and a Google Cloud project with the Analytics Data API enabled.
- How do I install the server?
You can install it using the command
pnpm install mcp-server-google-analytics
.
- Is it secure to use service account credentials?
Yes, but always use environment variables for sensitive information and follow security best practices.
Google Analytics MCP Server
An MCP server implementation for accessing Google Analytics 4 (GA4) data, built using the Model Context Protocol TypeScript SDK.
Features
- Get page view metrics with customizable dimensions
- Track active and new users over time
- Analyze specific events and their metrics
- Monitor user behavior metrics (session duration, bounce rate)
- Flexible date range selection for all queries
Prerequisites
- Node.js 20 or higher
- Google Analytics 4 property
- Google Cloud project with Analytics Data API enabled
- Service account credentials with appropriate permissions
Setup
- Create a Google Cloud project and enable the Analytics Data API
- Create a service account and download the credentials JSON file
- Grant the service account appropriate access to your GA4 property
- Set up environment variables:
export GOOGLE_CLIENT_EMAIL="your-service-account@project.iam.gserviceaccount.com"
export GOOGLE_PRIVATE_KEY="your-private-key"
export GA_PROPERTY_ID="your-ga4-property-id"
Installation
pnpm install mcp-server-google-analytics
Usage
Starting the Server
pnpm start
Configuration in Claude Desktop
Add this to your Claude Desktop configuration:
{
"mcpServers": {
"google-analytics": {
"command": "npx",
"args": ["-y", "mcp-server-google-analytics"],
"env": {
"GOOGLE_CLIENT_EMAIL": "your-service-account@project.iam.gserviceaccount.com",
"GOOGLE_PRIVATE_KEY": "your-private-key",
"GA_PROPERTY_ID": "your-ga4-property-id"
}
}
}
}
Available Functions
getPageViews
Get page view metrics for a specific date range:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["page", "country"] // Optional
}
getActiveUsers
Get active users metrics:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}
getEvents
Get event metrics:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"eventName": "purchase" // Optional
}
getUserBehavior
Get user behavior metrics:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}
Security Considerations
- Always use environment variables for sensitive credentials
- Implement appropriate CORS settings
- Follow the principle of least privilege when setting up service account permissions
- Regularly rotate service account credentials
- Monitor API usage and implement rate limiting if needed
Contributing
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.