- Home
- MCP servers
- Google Analytics
Google Analytics
- typescript
0
GitHub Stars
typescript
Language
7 months ago
First Indexed
3 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
Installation
Add the following to your MCP client configuration file.
Configuration
View docs{
"mcpServers": {
"mcp-mirror-ruchernchong_mcp-server-google-analytics": {
"command": "npx",
"args": [
"-y",
"mcp-server-google-analytics"
],
"env": {
"GA_PROPERTY_ID": "your-ga4-property-id",
"GOOGLE_PRIVATE_KEY": "your-private-key",
"GOOGLE_CLIENT_EMAIL": "your-service-account@project.iam.gserviceaccount.com"
}
}
}
}You can run this MCP server to access Google Analytics 4 data through the Model Context Protocol SDK. It lets you fetch page views, active users, events, and user behavior metrics over flexible date ranges, making it easy to Power analytics-driven features in your apps.
How to use
You connect to the Google Analytics MCP Server from an MCP client by using a stdio-based configuration. Start the server locally, then issue queries through your client to retrieve page views, active users, events, and user behavior metrics within any date range. Use the server to drive dashboards, reports, or automated insights across your GA4 property.
How to install
Prerequisites: You need Node.js 20 or higher and a GA4 property, plus a Google Cloud project with the Analytics Data API enabled and a service account with access to GA4.
# Install the MCP server package
pnpm install mcp-server-google-analytics
# Start the MCP server (development startup)
pnpm start
# Prepare environment variables for GA4 access
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"
# Example end-to-end setup (local run)
# 1) Install deps
pnpm install mcp-server-google-analytics
# 2) Set env vars (as above)
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"
# 3) Start the server
pnpm start
If you are wiring this into Claude Desktop, use the provided stdio configuration described in the next section.
## Configuration and usage notes
The server is configured to run via a CLI-driven MCP entry. To connect from an MCP client, you can invoke the server through the MCP gateway using the following stdio configuration. This uses npx to launch the package and passes the required environment variables for GA4 access.
{ "name": "google_analytics", "type": "stdio", "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
You can perform the following actions through the MCP server: Get page views, Get active users, Get events, Get user behavior.
{ "startDate": "2024-01-01", "endDate": "2024-01-31", "dimensions": ["page", "country"] }
## Security considerations
Use environment variables for sensitive credentials, apply appropriate CORS settings, grant the service account only the minimum permissions needed, rotate credentials regularly, and monitor API usage with rate limiting if necessary.
## Contributing
Contributions are welcome. Follow the project’s contributing guidelines for submitting changes and adhering to the code of conduct.
## License
This project is licensed under the MIT License.
## Available tools
### getPageViews
Fetch page view metrics for a specified date range with optional dimensions such as page and country.
### getActiveUsers
Retrieve active user counts over a given date span.
### getEvents
Query event metrics, with optional filtering by event name.
### getUserBehavior
Obtain user behavior metrics like session duration and bounce rate across a date range.