Navigation
Google Analytics Data API MCP Server: Secure Real-Time Access - MCP Implementation

Google Analytics Data API MCP Server: Secure Real-Time Access

Effortlessly harness Google Analytics Data API insights with our MCP server—secure, real-time access to transform raw data into actionable strategies, seamlessly.

Research And Data
4.2(59 reviews)
88 saves
41 comments

This tool saved users approximately 7528 hours last month!

About Google Analytics Data API MCP Server

What is the Google Analytics Data API MCP Server?

The MCP (Model Context Protocol) Server acts as an intermediary layer to securely access real-time and historical data from the Google Analytics Data API. It provides structured endpoints for retrieving analytics insights, including report generation and metadata exploration, while enforcing best practices for authentication and authorization through service account credentials.

How to Use the MCP Server

Implementation requires three core steps: environment configuration, server deployment, and integration setup. Begin by installing dependencies via package managers, configuring API credentials in environment variables, and specifying required scopes. The server must be initialized with proper authorization headers before connecting to external platforms like Claude Desktop through documented API endpoints. Configuration files and detailed setup guidelines are provided in the configuration documentation.

Google Analytics Data API MCP Server Features

Key Features

  • Dynamic Reporting: The /report endpoint generates customized analytics reports using date ranges, metrics, and dimensions filters
  • Real-Time Monitoring: Access live user activity data via the /realtime interface with device-type segmentation capabilities
  • Metadata Discovery: The /metadata endpoint provides comprehensive API entity definitions to simplify query construction
  • Secure Authentication: Implements OAuth2.0 service account flow with environment-variable-based credential management

Use Cases

Common applications include:

  • Automating daily user engagement reports using scheduled API calls
  • Building real-time dashboards showing current session metrics
  • Validating custom dimension configurations against metadata definitions
  • Integrating analytics data into third-party platforms through RESTful API interfaces

Google Analytics Data API MCP Server FAQ

FAQ

Q: How is data security maintained?
The server uses encrypted service account credentials and restricts access via IP whitelisting and token validation. Environment variables ensure sensitive data isn't hardcoded.

Q: What happens if API quota limits are exceeded?
The server implements exponential backoff strategies and returns detailed quota-exceeded responses with retry-after headers for programmatic handling.

Q: Can this support multiple Google Analytics properties?
Yes, by specifying property IDs in API requests and configuring appropriate permissions in Google Cloud IAM roles.

Q: How are outdated metrics handled?
The metadata endpoint automatically reflects current API schema, ensuring queries always reference the latest available dimensions and metrics.

Content

Google Analytics Data API MCP Server

Model Context Protocol (MCP) サーバーを使用して、Google Analytics Data APIにアクセスするためのインターフェースを提供します。

機能

このMCPサーバーは、Google Analytics Data APIの主要な機能にアクセスするためのツールとリソースを提供します:

ツール

  • get_report : 指定した日付範囲、メトリクス、ディメンションに基づいてレポートを取得します
  • get_realtime_data : リアルタイムデータを取得します

リソース

  • ga4://property/{propertyId}/metadata : Google Analyticsプロパティのメタデータにアクセスします

セットアップ

前提条件

  1. Google Cloudプロジェクトを作成し、Analytics Data APIを有効にします
  2. サービスアカウントを作成し、認証情報JSONファイルをダウンロードします
  3. サービスアカウントにGA4プロパティへの適切なアクセス権を付与します

詳細なセットアップ手順については、セットアップガイドを参照してください。

インストール

# リポジトリをクローン
git clone https://github.com/eno-graph/mcp-server-google-analytics.git
cd mcp-server-google-analytics

# 依存関係をインストール
npm install

# ビルド
npm run build

環境変数の設定

以下の環境変数を設定する必要があります:

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"

使用方法

サーバーの起動

npm start

または、提供されているスクリプトを使用することもできます:

./run-server.sh

Claude Desktopでの設定

Claude Desktopの設定ファイルに以下を追加します:

{
  "mcpServers": {
    "google-analytics": {
      "command": "node",
      "args": ["/path/to/mcp-server-google-analytics/build/index.js"],
      "env": {
        "GOOGLE_CLIENT_EMAIL": "[[email protected]](/cdn-cgi/l/email-protection)",
        "GOOGLE_PRIVATE_KEY": "your-private-key",
        "GA_PROPERTY_ID": "your-ga4-property-id"
      }
    }
  }
}

詳細な設定例については、claude-desktop-config-sample.jsonを参照してください。

ツールの使用例

レポートの取得

get_report ツールを使用して、過去7日間のアクティブユーザー数とページビュー数を取得します。

引数:
{
  "startDate": "7daysAgo",
  "endDate": "today",
  "metrics": ["activeUsers", "screenPageViews"],
  "dimensions": ["date"],
  "limit": 10
}

リアルタイムデータの取得

get_realtime_data ツールを使用して、現在アクティブなユーザー数を取得します。

引数:
{
  "metrics": ["activeUsers"],
  "dimensions": ["deviceCategory"],
  "limit": 10
}

リソースの使用例

ga4://property/123456789/metadata リソースにアクセスして、利用可能なメトリクスとディメンションを確認します。

使用例

Claudeでの使用例については、Claude使用例を参照してください。

ライセンス

MIT

Related MCP Servers & Clients