Get the FREE Ultimate OpenClaw Setup Guide →

mcp -ga4

MCP Server for Google Analytics 4

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

How to use

This MCP server provides GA4 data access through a set of tools that fetch metrics for a given date range. The available tools include get-page-views, get-active-users, get-events, and get-user-behavior, which retrieve page view counts, active user metrics, events, and user behavior data respectively from your GA4 property. It also exposes lightweight resources such as ga4://dimensions, ga4://metrics, ga4://filters-help, and ga4://property-info to help you discover available dimensions, metrics, and property metadata. You can combine these tools with prompts like analyze-data, create-report, and select-dimensions to perform data analysis, generate templates, and assist with choosing appropriate dimensions for your analysis goals. The server supports parameterized queries via filter, limit, and offset to narrow results and manage pagination.

How to install

Prerequisites:

  • A Google Analytics 4 property
  • A Google Cloud service account with access to the GA4 API
  • Node.js 20 or higher
  • pnpm package manager

Installation steps:

  1. Clone the repository
# Clone the repository
git clone https://github.com/yourusername/mcp-server-ga4.git
cd mcp-server-ga4
  1. Install dependencies with pnpm
# Install dependencies using pnpm
pnpm install
  1. Create the .env file from example
# Create the .env file
cp .env.example .env
  1. Edit credentials in .env (example variables shown):
GOOGLE_CLIENT_EMAIL=your-service-account-email@example.iam.gserviceaccount.com
GOOGLE_PRIVATE_KEY=your-private-key
GA_PROPERTY_ID=your-ga4-property-id
  1. Build and run the server
# Build the server
pnpm run build

# Run the server
pnpm start

Additional notes

Notes and tips:

  • The server authenticates using a service account if GOOGLE_CLIENT_EMAIL and GOOGLE_PRIVATE_KEY are set; otherwise it uses default credentials (Application Default Credentials).
  • Ensure the Google Analytics API is enabled and the service account has analytics.readonly permission.
  • To use default credentials locally, you can set GOOGLE_APPLICATION_CREDENTIALS to a JSON key file path.
  • The integration examples show how to wire the MCP server into Claude Desktop. Adjust the paths and environment variables to match your deployment.
  • When querying large datasets, use the limit and offset parameters to paginate results and avoid timeouts.

Related MCP Servers

Sponsor this space

Reach thousands of developers