Google Analytics

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

69

GitHub Stars

javascript

Language

6 months ago

First Indexed

2 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": {
    "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_PLACEHOLDER",
        "GOOGLE_CLIENT_EMAIL": "your-service-account@project.iam.gserviceaccount.com"
      }
    }
  }
}

You can run a Google Analytics 4 MCP Server locally or via a client to query GA4 data through a flexible, model-context-enabled API. It lets you retrieve page views, track active and new users, analyze events, and inspect user behavior metrics across customizable date ranges, making it easy to build analytics dashboards and insights.

How to use

You interact with the GA4 MCP Server through a client that supports MCP endpoints. Start the server using your preferred command, then configure your client to point at the local instance or at a running MCP endpoint. Use the available functions to run reports, fetch page views, get active users, access event metrics, and review common user behavior metrics.

How to install

Prerequisites: ensure you have Node.js 20 or higher installed on your machine. You will also need access to a Google Analytics 4 property and a Google Cloud project with the Analytics Data API enabled.

Step 1: Install the MCP server package globally or run it via a package runner.

Step 2: Set up environment variables for authentication and GA property.

Step 3: Start the server and connect a client.

pnpm start

# Or install and run directly with npm/npx as shown
npm install -g mcp-server-google-analytics
npx mcp-server-google-analytics

# If using a client configuration via Claude Desktop:
npx -y mcp-server-google-analytics

Configuration and security notes

Configure authentication with Google Analytics by providing a service account and its credentials. Grant the service account Viewer access to the GA4 property. Store sensitive credentials in environment variables or a secure .env file and avoid exposing keys in client-side code.

Environment variables you need to set:

export GOOGLE_CLIENT_EMAIL="your-service-account@your-project.iam.gserviceaccount.com"
export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n"
export GA_PROPERTY_ID="your_ga4_property_id"

Usage examples and endpoints

The MCP server exposes functions you can call from your MCP client to query GA4 data. Use the following endpoints to retrieve data as part of your analytics workflows.

// Available client calls (illustrative - use your MCP client to invoke these):
// runReport, getPageViews, getActiveUsers, getEvents, getUserBehavior

Available tools

runReport

Run a flexible GA4 report with configurable dimensions, metrics, and optional filters.

getPageViews

Fetch page view metrics for a date range with optional dimensions.

getActiveUsers

Retrieve active users metrics across a date range.

getEvents

Query event metrics, with an optional event name filter.

getUserBehavior

Obtain user behavior metrics such as session duration and bounce rate.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational