Get the FREE Ultimate OpenClaw Setup Guide →

google-analytics

MCP server from gomarble-ai/google-analytics-mcp-server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio gomarble-ai-google-analytics-mcp-server python /path/to/google-analytics-mcp/server.py \
  --env GOOGLE_ANALYTICS_OAUTH_CONFIG_PATH="Path to the Google Analytics OAuth client_secret JSON file downloaded from Google Cloud (e.g., /full/path/to/client_secret_*.json)"

How to use

This Google Analytics MCP Server provides an interface to query Google Analytics 4 data through the MCP protocol. It handles OAuth 2.0 authentication automatically, refreshing tokens as needed so you can focus on building analytics workflows. The server exposes a set of tools you can invoke through MCP clients (like Claude Desktop) to retrieve GA4 metrics such as page views, active users, events, traffic sources, and device metrics, all wrapped in a consistent MCP tool API. Typical usage involves authenticating once, then issuing tool calls like list_properties, get_page_views, get_active_users, get_events, get_traffic_sources, get_device_metrics, and run_report to fetch structured GA4 data for your analysis and reporting pipelines.

How to install

Prerequisites:

  • Python 3.10+ installed
  • Git installed
  • Access to Google Cloud Console to create OAuth credentials for GA4

Step 1: Clone the repository

git clone https://github.com/your-organization/google-analytics-mcp-server.git
cd google-analytics-mcp-server

Step 2: Set up a virtual environment and install dependencies

python3 -m venv .venv
# On macOS/Linux
source .venv/bin/activate
# On Windows
.venv\Scripts\activate

pip install -r requirements.txt

Step 3: Prepare OAuth credentials

  • In Google Cloud Console, create OAuth 2.0 Client ID for a Desktop application and download the JSON file.
  • Place the downloaded file somewhere accessible in your project, e.g. /path/to/client_secret_*.json

Step 4: Configure environment for the MCP server

# Copy example env if provided, then edit
cp .env.example .env

Edit the .env (or set environment variables) to include the path to your Google Analytics OAuth config:

GOOGLE_ANALYTICS_OAUTH_CONFIG_PATH=/path/to/client_secret_*.json

Step 5: Run or configure via Claude Desktop (as described in the README)

  • If you plan to run directly for testing, start the server script with Python:
python /path/to/google-analytics-mcp-server/server.py

Note: For Claude Desktop integration you will configure the MCP server using an absolute path to the Python executable and the server.py script in Claude’s config as shown in the README.

Additional notes

Tips and considerations:

  • Always use absolute paths in your Claude Desktop MCP configuration for reliability across sessions and reboots.
  • Ensure the GOOGLE_ANALYTICS_OAUTH_CONFIG_PATH path is accessible by the user running the MCP server.
  • Tokens are managed automatically by the server; you should see a one-time authentication flow the first time you run or connect via Claude Desktop.
  • If you encounter token refresh failures, verify that the OAuth client has the proper redirect URIs and scopes (analytics.readonly and analytics data access, as needed).
  • On Windows, use forward slashes or double backslashes in file paths when configuring Claude Desktop.
  • Regularly update dependencies and review Google Analytics Data API quotas to avoid throttling during heavy querying.

Related MCP Servers

Sponsor this space

Reach thousands of developers