Google Analytics MCP Server: AI-Powered Analytics for GA4

Google Analytics MCP server enables AI models to interact with Google Analytics 4 for reports, user behavior analysis, event tracking, and real-time data access.

November 15, 2025
Google AnalyticsMCPAIAnalyticsGA4
GitHub starsPyPI version

Overview

The Google Analytics MCP Server bridges AI models and analytics by enabling language models to interact directly with Google Analytics 4 data. It's part of the Model Context Protocol (MCP) ecosystem, providing secure, read-only access to your analytics data for natural language queries and AI-powered insights.

Official Server:

Developed and maintained by Google Analytics

Key Features

🗂️

Comprehensive Reporting

Execute custom reports with flexible dimensions, metrics, and date ranges

📊

Real-Time Analytics

Access live user activity and events as they happen on your site

🔐

Secure Read-Only Access

Safe data exploration without risk of modifying your analytics configuration

💬

Natural Language Queries

Ask questions about your data in plain English and get instant insights

Available Tools

Quick Reference

ToolPurposeCategory
get_account_summariesList GA accounts and propertiesAccount
get_property_detailsGet property configurationAccount
list_google_ads_linksList linked Google Ads accountsIntegration
run_reportExecute custom analytics reportsReporting
get_custom_dimensions_and_metricsList custom fieldsSchema
run_realtime_reportGet real-time analytics dataReporting

Detailed Usage

get_account_summaries

Retrieves information about your Google Analytics accounts and properties, including property IDs and display names.

use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "get_account_summaries",
  arguments: {}
});

Use this to discover available properties before running reports.

get_property_details

Returns detailed configuration information for a specific Google Analytics property.

use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "get_property_details",
  arguments: {
    property_name: "properties/123456789"
  }
});

Get timezone, currency, industry category, and other property settings.

run_report

Execute custom analytics reports with flexible dimensions, metrics, date ranges, and filters.

// Get user and session metrics by country
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_report",
  arguments: {
    property_id: "123456789",
    date_ranges: [{
      start_date: "7daysAgo",
      end_date: "today"
    }],
    dimensions: [{ name: "country" }],
    metrics: [
      { name: "activeUsers" },
      { name: "sessions" }
    ],
    order_bys: [{
      metric: { metric_name: "activeUsers" },
      desc: true
    }],
    limit: 10
  }
});

Supports 200+ dimensions and metrics for comprehensive analysis.

run_realtime_report

Access real-time analytics data showing current user activity on your site.

// Get current active users by page
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_realtime_report",
  arguments: {
    property_id: "123456789",
    dimensions: [{ name: "unifiedScreenName" }],
    metrics: [{ name: "activeUsers" }],
    limit: 10
  }
});

Data reflects activity from the last 30 minutes.

get_custom_dimensions_and_metrics

Retrieves all custom dimensions and metrics configured for your property.

use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "get_custom_dimensions_and_metrics",
  arguments: {
    property_name: "properties/123456789"
  }
});

Discover custom fields for use in reports.

list_google_ads_links

Lists all Google Ads accounts linked to your Analytics property.

use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "list_google_ads_links",
  arguments: {
    property_name: "properties/123456789"
  }
});

View advertising integrations for cross-platform analysis.

Installation

Prerequisites

Before installing, you need to:

  1. Enable required APIs in your Google Cloud Console:

    • Google Analytics Admin API
    • Google Analytics Data API
  2. Set up Application Default Credentials with the Analytics scope:

    gcloud auth application-default login \
      --scopes=https://www.googleapis.com/auth/analytics.readonly
    
  3. Set environment variables:

    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json"
    export GOOGLE_PROJECT_ID="your-project-id"
    

Install with pipx

pipx install google-analytics-mcp

Configuration

Add to your MCP settings file (e.g., ~/.gemini/settings.json or Claude Desktop config):

{
  "mcpServers": {
    "google-analytics": {
      "command": "pipx",
      "args": ["run", "google-analytics-mcp"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/credentials.json",
        "GOOGLE_PROJECT_ID": "your-project-id"
      }
    }
  }
}

Common Use Cases

1. Traffic Analysis

Get insights about website traffic and user behavior:

// Find top pages by users in the last 7 days
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_report",
  arguments: {
    property_id: "123456789",
    date_ranges: [{ start_date: "7daysAgo", end_date: "today" }],
    dimensions: [{ name: "pagePath" }, { name: "pageTitle" }],
    metrics: [
      { name: "activeUsers" },
      { name: "screenPageViews" }
    ],
    order_bys: [{ metric: { metric_name: "activeUsers" }, desc: true }],
    limit: 20
  }
});

2. User Acquisition Sources

Understand where your traffic is coming from:

// Analyze traffic sources and conversion rates
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_report",
  arguments: {
    property_id: "123456789",
    date_ranges: [{ start_date: "30daysAgo", end_date: "today" }],
    dimensions: [
      { name: "sessionSource" },
      { name: "sessionMedium" }
    ],
    metrics: [
      { name: "sessions" },
      { name: "conversions" },
      { name: "engagementRate" }
    ],
    order_bys: [{ metric: { metric_name: "sessions" }, desc: true }]
  }
});

3. Event Tracking

Monitor specific user interactions and events:

// Get most popular events
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_report",
  arguments: {
    property_id: "123456789",
    date_ranges: [{ start_date: "7daysAgo", end_date: "today" }],
    dimensions: [{ name: "eventName" }],
    metrics: [
      { name: "eventCount" },
      { name: "eventCountPerUser" }
    ],
    order_bys: [{ metric: { metric_name: "eventCount" }, desc: true }],
    limit: 25
  }
});

4. Real-Time Monitoring

Watch current activity on your site:

// Monitor active users by device
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_realtime_report",
  arguments: {
    property_id: "123456789",
    dimensions: [{ name: "deviceCategory" }],
    metrics: [{ name: "activeUsers" }]
  }
});

5. Geographic Analysis

See where your users are located:

// Users by country and city
use_mcp_tool({
  server_name: "google-analytics",
  tool_name: "run_report",
  arguments: {
    property_id: "123456789",
    date_ranges: [{ start_date: "30daysAgo", end_date: "today" }],
    dimensions: [
      { name: "country" },
      { name: "city" }
    ],
    metrics: [
      { name: "activeUsers" },
      { name: "averageSessionDuration" }
    ],
    order_bys: [{ metric: { metric_name: "activeUsers" }, desc: true }],
    limit: 50
  }
});

Authentication Setup

Step 1: Create Service Account

  1. Go to Google Cloud Console
  2. Create or select a project
  3. Navigate to IAM & Admin > Service Accounts
  4. Click Create Service Account
  5. Add name and description, click Create
  6. Grant Viewer role, click Continue
  7. Click Done

Step 2: Create Key

  1. Click on the service account you created
  2. Go to Keys tab
  3. Click Add Key > Create new key
  4. Select JSON format
  5. Click Create (the key file will download automatically)

Step 3: Grant Analytics Access

  1. Go to Google Analytics
  2. Navigate to Admin (gear icon)
  3. Under Account or Property, click Account Access Management or Property Access Management
  4. Click + button to add users
  5. Enter your service account email (looks like [email protected])
  6. Assign Viewer role
  7. Click Add

Step 4: Enable APIs

  1. In Google Cloud Console, navigate to APIs & Services > Library
  2. Search for and enable:
    • Google Analytics Admin API
    • Google Analytics Data API (GA4)

Example Natural Language Queries

Once configured, you can ask questions like:

  • "What were my top 10 pages by users yesterday?"
  • "Show me real-time active users by device"
  • "Which traffic sources drove the most conversions last month?"
  • "What are my most popular events this week?"
  • "Compare user engagement between mobile and desktop users"

Sources