Google Analytics MCP Server

by MCP-Mirror

393 downloads
Not rated
GitHub

About

Google Analytics MCP Server is an MCP server implementation for accessing Google Analytics 4 (GA4) data, built using the Model Context Protocol TypeScript SDK. It provides functions to query page views, active users, events, and user behavior metrics.

Details

Author
MCP-Mirror
Downloads
393
Categories
Search

- 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

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Google Analytics MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install the package with pnpm install mcp-server-google-analytics and set the environment variables GOOGLE_CLIENT_EMAIL, GOOGLE_PRIVATE_KEY, and GA_PROPERTY_ID. Start the server with pnpm start or configure it in Claude Desktop using the provided npx command with environment variables.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "google analytics mcp server": {
            "google-analytics": {
                "command": "npx",
                "args": [
                    "-y",
                    "mcp-server-google-analytics"
                ],
                "env": {
                    "GOOGLE_CLIENT_EMAIL": "",
                    "GOOGLE_PRIVATE_KEY": "",
                    "GA_PROPERTY_ID": ""
                }
            }
        }
    }
}

McpServers

{
    "google-analytics": {
        "command": "npx",
        "args": [
            "-y",
            "mcp-server-google-analytics"
        ],
        "env": {
            "GOOGLE_CLIENT_EMAIL": "",
            "GOOGLE_PRIVATE_KEY": "",
            "GA_PROPERTY_ID": ""
        }
    }
}

Google Analytics MCP Server

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

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.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.