mcp-server-google-analytics

MCP.Pizza Chef: ruchernchong

The mcp-server-google-analytics is a Model Context Protocol server designed to integrate Google Analytics 4 (GA4) data with large language models. It enables LLMs to access detailed web analytics metrics such as page views, user activity, event tracking, session duration, and bounce rates. Built with the MCP TypeScript SDK, it supports flexible queries with customizable dimensions and date ranges. This server requires Node.js 20+, a GA4 property, and Google Cloud credentials with Analytics Data API enabled. It empowers AI models to perform real-time analysis and insights on website traffic and user behavior, enhancing data-driven decision-making workflows.

Use This MCP server To

Fetch Google Analytics 4 page view metrics Track active and new users over time Analyze specific user events and metrics Monitor session duration and bounce rates Query analytics data with custom date ranges Integrate GA4 data into AI-driven reports Enable LLMs to interpret web traffic patterns Automate web analytics data extraction

README

MseeP.ai Security Assessment Badge

Verified on MseeP

Google Analytics MCP Server

smithery badge

An MCP server implementation for accessing Google Analytics 4 (GA4) data, built using the Model Context Protocol TypeScript SDK.

Features

  • Get page view metrics with customizable dimensions
  • Track active and new users over time
  • Analyze specific events and their metrics
  • Monitor user behavior metrics (session duration, bounce rate)
  • Flexible date range selection for all queries

Prerequisites

  • Node.js 20 or higher
  • Google Analytics 4 property
  • Google Cloud project with Analytics Data API enabled
  • Service account credentials with appropriate permissions

Setup

  1. Create a Google Cloud project and enable the Analytics Data API
  2. Create a service account and download the credentials JSON file
  3. Grant the service account appropriate access to your GA4 property
  4. Set up environment variables:
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"

Installation

Installing via Smithery

To install Google Analytics Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install mcp-server-google-analytics --client claude

Manual Installation

pnpm install mcp-server-google-analytics

Usage

Starting the Server

pnpm start

Configuration in Claude Desktop

Add this to your Claude Desktop configuration:

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

Available Functions

getPageViews

Get page view metrics for a specific date range:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "dimensions": ["page", "country"] // Optional
}

getActiveUsers

Get active users metrics:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31"
}

getEvents

Get event metrics:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "eventName": "purchase" // Optional
}

getUserBehavior

Get user behavior metrics:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31"
}

Security Considerations

  • Always use environment variables for sensitive credentials
  • Implement appropriate CORS settings
  • Follow the principle of least privilege when setting up service account permissions
  • Regularly rotate service account credentials
  • Monitor API usage and implement rate limiting if needed

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

mcp-server-google-analytics FAQ

How do I authenticate the mcp-server-google-analytics?
You authenticate using a Google Cloud service account with Analytics Data API enabled, providing credentials to the server.
What prerequisites are needed to run this MCP server?
Node.js 20 or higher, a Google Analytics 4 property, a Google Cloud project with Analytics Data API enabled, and service account credentials.
Can I customize the metrics and dimensions queried?
Yes, the server supports customizable dimensions and metrics for flexible analytics queries.
How does this server handle date ranges for analytics queries?
It allows flexible date range selection to tailor queries to specific time periods.
Is this MCP server compatible with multiple LLM providers?
Yes, it is provider-agnostic and can work with OpenAI, Anthropic Claude, and Google Gemini models.
What kind of analytics data can the server provide?
It provides page views, user activity, event metrics, session duration, and bounce rate data.
How do I deploy the mcp-server-google-analytics?
Deploy it in a Node.js 20+ environment with access to your Google Cloud credentials and GA4 property.
Does the server support real-time analytics data?
It supports near real-time data access depending on Google Analytics API latency and data availability.