Navigation
Google Analytics MCP Server: Real-Time Sync & Seamless Insights - MCP Implementation

Google Analytics MCP Server: Real-Time Sync & Seamless Insights

Google Analytics MCP Server: Mirror real-time data flawlessly, ensuring seamless access and actionable insights to power smarter decisions—your analytics just got unstoppable.

Research And Data
4.9(22 reviews)
33 saves
15 comments

Ranked in the top 3% of all AI tools in its category

About Google Analytics MCP Server

What is Google Analytics MCP Server: Real-Time Sync & Seamless Insights?

Google Analytics MCP Server enables real-time access to Google Analytics 4 (GA4) data through the Model Context Protocol (MCP). Built with TypeScript SDK, it provides a server-side interface to fetch metrics like page views, user behavior, and custom events. This tool bridges GA4 data with applications like Claude Desktop, offering developers a streamlined way to integrate analytics without manual API calls.

How to use Google Analytics MCP Server: Real-Time Sync & Seamless Insights?

Setup Steps

  1. Install Node.js 20+ and configure a Google Cloud project with Analytics Data API enabled.
  2. Create a service account, download credentials JSON, and grant access to your GA4 property.
  3. Set environment variables for credentials and property ID:
export GOOGLE_CLIENT_EMAIL="your-service-account-email"
export GOOGLE_PRIVATE_KEY="your-private-key"
export GA_PROPERTY_ID="your-ga4-property-id"

Integration Example (Claude Desktop)

Add this configuration to your config.json:

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

Google Analytics MCP Server Features

Key Features of Google Analytics MCP Server: Real-Time Sync & Seamless Insights?

  • Customizable Metrics: Filter page views by dimensions like page or country.
  • User Tracking: Monitor active users and retention over time.
  • Event Analysis: Query specific events (e.g., purchase events) with metrics.
  • Flexible Time Ranges: Fetch data for any timeframe via API parameters.
  • Security-first Design: Enforces credentials management and API rate limiting.

Use Cases

Examples of practical applications:

  • E-commerce: Track product page performance and checkout funnel metrics.
  • Blogs: Analyze traffic sources and popular article categories in real-time.
  • SaaS Platforms: Monitor user engagement and feature adoption rates.

Google Analytics MCP Server FAQ

FAQ

Q: What if the server returns an authentication error?

A: Verify your service account credentials and ensure the analyticsdata.read scope is enabled in Google Cloud.

Q: Can I use this with other platforms besides Claude?

A: Yes! The MCP interface is open-standard, so any compatible app (e.g., chatbots, dashboards) can integrate.

Q: How do I handle API rate limits?

A: The server includes automatic retries and exponential backoff. For heavy usage, consider caching frequent queries.

For contribution guidelines and licensing details, visit our official documentation.

Content

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="[[email protected]](/cdn-cgi/l/email-protection)"
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]](/cdn-cgi/l/email-protection)",
        "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.

Related MCP Servers & Clients