Get the FREE Ultimate OpenClaw Setup Guide →

mcp -google-analytics

Model Context Protocol server for Google Analytics, enabling LLMs to fetch and analyze web analytics data

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio ruchernchong-mcp-server-google-analytics npx -y mcp-server-google-analytics \
  --env GA_PROPERTY_ID="your-ga4-property-id" \
  --env GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n" \
  --env GOOGLE_CLIENT_EMAIL="your-service-account@project.iam.gserviceaccount.com"

How to use

This MCP server provides access to Google Analytics 4 (GA4) data via a TypeScript SDK-based MCP implementation. It exposes functions to retrieve flexible analytics data, including page views, active users, events, and user behavior metrics. After configuring the required Google Analytics credentials through environment variables, you can query GA4 data using the server's available endpoints like runReport, getPageViews, getActiveUsers, getEvents, and getUserBehavior. The RunReport function supports custom dimensions, metrics, date ranges, and optional filters to tailor analytics queries to your needs.

How to install

Prerequisites:

  • Node.js 20 or higher
  • Access to a Google Analytics 4 property with the Analytics Data API enabled
  • A service account with credentials (JSON) and a GA4 property to query

Installation options:

  1. Install via npx (recommended for quick setup):
# Install and run the MCP server using npx
npx -y mcp-server-google-analytics
  1. Global installation (alternative):
npm install -g mcp-server-google-analytics
  1. Manual configuration in Claude Desktop (example):
npx -y mcp-server-google-analytics

Configuration in Claude Desktop (example JSON):

{
  "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"
      }
    }
  }
}

Additional notes

Environment variables:

  • GOOGLE_CLIENT_EMAIL and GOOGLE_PRIVATE_KEY come from your Google Cloud service account credentials JSON. Keep these secrets secure and do not expose them in client-side code.
  • GA_PROPERTY_ID must be the GA4 property ID you intend to query.
  • If using a .env file, ensure it is loaded by your runtime (e.g., with dotenv). Common issues:
  • Ensure the Analytics Data API is enabled in Google Cloud Console for the project.
  • Confirm the service account has Viewer access to the GA4 property.
  • When exchanging keys, preserve newline characters in the private key (escape them properly in shell or config files).
  • If you modify environment variables, restart the MCP server to apply changes.

Related MCP Servers

Sponsor this space

Reach thousands of developers