Get the FREE Ultimate OpenClaw Setup Guide →

mcp -google-analytics

A MCP server for Google Analytics Data API

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio eno-graph-mcp-server-google-analytics node /path/to/mcp-server-google-analytics/build/index.js \
  --env GA_PROPERTY_ID="your-ga4-property-id" \
  --env GOOGLE_PRIVATE_KEY="your-private-key" \
  --env GOOGLE_CLIENT_EMAIL="your-service-account@project.iam.gserviceaccount.com"

How to use

This MCP server provides an interface to Google Analytics Data API, exposing tools to retrieve analytics data and access GA4 property metadata. The main tools available are get_report, which fetches reports based on specified date ranges, metrics, and dimensions; and get_realtime_data, which returns real-time user activity data. You can reference the GA4 resource at ga4://property/{propertyId}/metadata to explore available metrics and dimensions for a particular GA4 property. To integrate with Claude Desktop, configure the mcpServers.google-analytics entry with the appropriate node command, the built server path, and the necessary environment variables. With these tools, you can programmatically request aggregations like active users, pageviews, and other metrics across custom date ranges, and you can also pull real-time metrics such as active users by device category.

Usage is designed to be straightforward: start the MCP server and issue commands to get_report for historical insights or get_realtime_data for live metrics. The provided resource endpoint metadata helps you discover which metrics and dimensions are available for your GA4 property, enabling dynamic query construction for dashboards or assistants like Claude.

How to install

Prerequisites:

  • Node.js and npm installed on your system
  • Access to a Google Cloud project with the Analytics Data API enabled
  • A Google service account JSON key with GA4 property access

Install and run:

# 1. Clone the repository
git clone https://github.com/eno-graph/mcp-server-google-analytics.git
cd mcp-server-google-analytics

# 2. Install dependencies
npm install

# 3. Build the project
npm run build

Configure environment variables (example):

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"

Run the server:

npm start

Alternative run method (if a script is provided):

./run-server.sh

Additional notes

Notes and tips:

  • Keep your Google private key secure; never commit it to version control. Use a secure secret store in production.
  • Ensure the service account has access to the GA4 property you are querying.
  • If you rotate keys, update GOOGLE_PRIVATE_KEY accordingly and restart the server.
  • The build output is expected at build/index.js; adjust the path in the MCP config if your setup differs.
  • When configuring Claude Desktop, ensure the env block provides the correct credentials for the target GA4 property to avoid authentication errors.
  • If you encounter API quota errors, review your Analytics Data API quotas in Google Cloud Console and consider applying for higher quotas or batching requests.

Related MCP Servers

Sponsor this space

Reach thousands of developers