MCP-Mirror

Google Analytics MCP Server

Community MCP-Mirror
Updated

Google Analytics MCP server for accessing web analytics data

Google Analytics MCP Server

An MCP server implementation for accessing Google Analytics 4 (GA4) data, built using the Model Context ProtocolTypeScript 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="[email protected]"
export GOOGLE_PRIVATE_KEY="your-private-key"
export GA_PROPERTY_ID="your-ga4-property-id"

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": "[email protected]",
        "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 andthe process for submitting pull requests.

License

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

MCP Server · Populars

MCP Server · New

    PraneshASP

    Foundry MCP Server

    An experimental MCP Server for foundry built for Solidity devs

    Community PraneshASP
    karakeep-app

    Karakeep MCP Server

    A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

    Community karakeep-app
    karakeep-app

    karakeep

    A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

    Community karakeep-app
    prisma

    Prisma

    Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

    Community prisma
    iannuttall

    Flux UI MCP Server

    MCP Server

    Community iannuttall