Skip to main content
Glama
GA4 MCP Server

GA4 MCP Server

by Shin-sibainu

GA4 MCP Server

Google Analytics 4 (GA4) のデータを Claude などの LLM から取得・分析できる MCP (Model Context Protocol) サーバーです。

特徴

  • 20種類の分析ツール: 単純なデータ取得だけでなく、実用的な分析ツールを多数搭載

  • 日本語対応: 出力結果は日本語でフォーマット(例: "2分34秒", "45.2%")

  • 柔軟な期間指定: 相対日付(7daysAgo, yesterday)と絶対日付の両方に対応

  • 即座にインサイト: LLMが直接解釈しやすい形式でデータを返却

Related MCP server: ga4-viz

必要要件

  • Node.js 18以上

  • GA4 プロパティへのアクセス権を持つ Google アカウント

インストール

cd ga4-mcp-server
npm install
npm run build

認証設定

方法1: gcloud CLI を使う(推奨・簡単)

サービスアカウント不要で、自分の Google アカウントで認証できます。

1. gcloud CLI をインストール

# Windows (winget)
winget install Google.CloudSDK

# または https://cloud.google.com/sdk/docs/install からダウンロード

2. 認証を実行

gcloud auth application-default login --scopes="https://www.googleapis.com/auth/analytics.readonly"

ブラウザが開くので、GA4 にアクセス権のある Google アカウントでログインするだけ!

これだけで完了です。GOOGLE_APPLICATION_CREDENTIALS の設定は不要です。


方法2: サービスアカウントを使う(本番環境向け)

チーム共有や本番環境では、サービスアカウントを使用します。

1. Google Cloud Console でサービスアカウントを作成

  1. Google Cloud Console にアクセス

  2. プロジェクトを選択(または新規作成)

  3. 「IAM と管理」→「サービスアカウント」→「サービスアカウントを作成」

  4. 名前を入力して作成

  5. 「キー」タブ →「鍵を追加」→「新しい鍵を作成」→ JSON形式でダウンロード

2. API の有効化

「APIとサービス」→「ライブラリ」で以下を有効化:

  • Google Analytics Data API

  • Google Analytics Admin API

3. GA4 プロパティへのアクセス権付与

  1. Google Analytics にアクセス

  2. 「管理」→「プロパティのアクセス管理」

  3. サービスアカウントのメールアドレス(xxx@xxx.iam.gserviceaccount.com)を「閲覧者」として追加

MCP 設定

gcloud CLI 認証を使う場合(推奨)

{
  "mcpServers": {
    "ga4": {
      "command": "node",
      "args": ["/path/to/ga4-mcp-server/dist/index.js"],
      "env": {
        "GA4_PROPERTY_ID": "123456789"
      }
    }
  }
}

サービスアカウントを使う場合

{
  "mcpServers": {
    "ga4": {
      "command": "node",
      "args": ["/path/to/ga4-mcp-server/dist/index.js"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json",
        "GA4_PROPERTY_ID": "123456789"
      }
    }
  }
}

設定ファイルの場所

アプリ

設定ファイル

Claude Desktop (Mac)

~/Library/Application Support/Claude/claude_desktop_config.json

Claude Desktop (Windows)

%APPDATA%\Claude\claude_desktop_config.json

Cursor

.cursor/mcp.json(プロジェクトルート)

環境変数

変数名

必須

説明

GOOGLE_APPLICATION_CREDENTIALS

×

サービスアカウントJSONキーのパス(gcloud CLI使用時は不要)

GA4_PROPERTY_ID

△

デフォルトのGA4プロパティID(ツール実行時に指定も可)

利用可能なツール

基本ツール(5個)

ツール名

説明

list_accounts

アカウント・プロパティ一覧取得

get_property_details

プロパティ詳細情報

run_report

汎用レポート実行(メインツール)

run_realtime_report

リアルタイムレポート

get_metadata

利用可能なディメンション・メトリクス一覧

分析ツール(15個)

ツール名

説明

get_traffic_summary

トラフィックサマリー(PV/UU/セッション等)

get_top_pages

人気ページランキング

get_traffic_sources

流入元分析

get_device_breakdown

デバイス別アクセス比率

get_geo_breakdown

地域別アクセス分析

compare_periods

期間比較(前週比、前月比など)

get_landing_pages

ランディングページ分析

get_exit_pages

離脱ページ分析

get_user_journey

ユーザージャーニー(ページ遷移)

get_conversion_funnel

コンバージョンファネル分析

get_hourly_traffic

時間帯別アクセス分析

get_daily_trend

日別トレンド

get_new_vs_returning

新規 vs リピーター分析

get_engagement_metrics

エンゲージメント指標

get_search_terms

サイト内検索キーワード

使用例

基本的な質問

「今日のPV数を教えて」
→ get_traffic_summary (period: "today")

「今リアルタイムで何人見てる?」
→ run_realtime_report

ランキング系

「過去7日間のアクセス数が多いページTOP10」
→ get_top_pages (period: "7days", limit: 10)

「どこからアクセスが来てる?」
→ get_traffic_sources (period: "7days", groupBy: "channel")

比較・分析系

「先週と今週を比較して」
→ compare_periods (comparisonType: "previousPeriod", period: "7days")

「モバイルとPCの比率は?」
→ get_device_breakdown (period: "7days")

深堀り分析

「何時頃にアクセスが多い?」
→ get_hourly_traffic (period: "7days")

「このページを見た人は次にどこに行く?」
→ get_user_journey (pagePath: "/product/123", direction: "next")

開発

# 開発モード(ファイル変更を監視してリビルド)
npm run dev

# ビルド
npm run build

# 型チェック
npm run typecheck

注意事項

  1. レート制限: GA4 Data API には 1 プロジェクトあたり 1 日 50,000 リクエストの制限があります

  2. データの遅延: GA4のデータは通常24-48時間の遅延があります(リアルタイムレポートを除く)

  3. ファネル分析の制限: GA4 Data APIでは真のファネル分析に制限があります。より正確な分析にはBigQuery Exportが必要です

ライセンス

MIT

Available Tools

20 tools
compare_periodsC

2つの期間を比較します。前週比、前月比、前年同期比などの分析が可能です。

Inputs: comparisonType (required), propertyId, period, period1, +2 more.

get_conversion_funnelC

コンバージョンファネルの分析を行います。各ステップの通過率や離脱率を確認できます。

Inputs: period (required), steps (required), propertyId.

get_daily_trendC

日別のトレンドデータを取得します。グラフ作成やトレンド分析に使用できます。

Inputs: startDate (required), endDate (required), propertyId, metrics.

get_device_breakdownB

デバイス別(PC/モバイル/タブレット)のアクセス内訳を取得します。OS別、ブラウザ別の情報も含まれます。

Inputs: period (required), propertyId.

get_engagement_metricsC

エンゲージメント関連の詳細指標(エンゲージメント率、平均エンゲージメント時間など)を取得します。

Inputs: period (required), propertyId.

get_exit_pagesC

離脱ページ(ユーザーが最後に見たページ)の分析結果を取得します。

Inputs: period (required), propertyId, limit.

get_geo_breakdownC

地域別(国または市区町村)のアクセス分析結果を取得します。

Inputs: period (required), level (required), propertyId, limit.

get_hourly_trafficB

時間帯別のアクセス状況を分析します。投稿やキャンペーンのタイミング最適化に活用できます。

Inputs: period (required), propertyId.

get_landing_pagesC

ランディングページ(ユーザーが最初にアクセスしたページ)の分析結果を取得します。

Inputs: period (required), propertyId, limit.

get_metadataB

利用可能なディメンションとメトリクスの一覧を取得します。run_reportで使える項目を確認できます。

Inputs: propertyId.

get_new_vs_returningC

新規ユーザーとリピーターの比較分析を行います。それぞれのセッション数や滞在時間を確認できます。

Inputs: period (required), propertyId.

get_property_detailsC

指定したGA4プロパティの詳細情報(名前、タイムゾーン、通貨など)を取得します。

Inputs: propertyId (required).

get_search_termsB

サイト内検索キーワードを分析します。GA4でサイト内検索が設定されている場合のみ有効です。

Inputs: period (required), propertyId, limit.

get_top_pagesC

人気ページのランキングを取得します。PV数、滞在時間、直帰率などを確認できます。

Inputs: period (required), propertyId, limit, pathFilter.

get_traffic_sourcesC

流入元(チャネル、ソース、メディアなど)の分析結果を取得します。

Inputs: period (required), groupBy (required), propertyId.

get_traffic_summaryB

指定期間のトラフィック概要(PV数、ユーザー数、セッション数、直帰率など)を取得します。ダッシュボード的な使い方に最適です。

Inputs: period (required), propertyId.

get_user_journeyB

特定ページの前後に閲覧されるページを分析します。ユーザーの回遊パターンの把握に便利です。

Inputs: period (required), pagePath (required), direction (required), propertyId, +1 more.

list_accountsA

GA4のアカウントとプロパティの一覧を取得します。どのプロパティIDを使うべきか確認する際に便利です。

Inputs: no named parameters.

run_realtime_reportC

リアルタイムレポートを実行し、現在のアクティブユーザー数などを取得します。

Inputs: propertyId, dimensions, metrics.

run_reportC

GA4の汎用レポートを実行します。任意のディメンションとメトリクスを指定して柔軟にデータを取得できます。

Inputs: startDate (required), endDate (required), dimensions (required), metrics (required), +4 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 20 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose targeting specific GA4 analysis functions, such as comparing periods, analyzing funnels, getting device breakdowns, or running reports. No tools appear to overlap in functionality, making it easy for an agent to select the correct one based on the task.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern, primarily using 'get_' or 'run_' prefixes (e.g., get_daily_trend, run_report). Minor variations like 'compare_periods' and 'list_accounts' still adhere to a clear naming convention, ensuring predictability and readability throughout the set.

    Tool Count4/5

    With 20 tools, the count is slightly high but reasonable for a comprehensive GA4 analytics server, covering diverse aspects like traffic, user behavior, and reporting. It avoids being overwhelming by maintaining clear scopes, though it borders on the upper limit for typical server purposes.

    Completeness5/5

    The tool set provides complete coverage for GA4 analytics, including data retrieval (e.g., get_traffic_summary), detailed analyses (e.g., get_conversion_funnel), property management (e.g., list_accounts), and flexible reporting (e.g., run_report). No obvious gaps exist, supporting full agent workflows from overview to deep dives.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Connects Google Analytics 4 data to Claude, Cursor and other MCP clients, enabling natural language queries of website traffic, user behavior, and analytics data with access to 200+ GA4 dimensions and metrics.
      12
      4,647 PyPI
      243
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables interactive Google Analytics 4 visualizations inside Claude conversations, supporting ad-hoc queries with line, bar, pie charts and data tables.
      -
    • F
      license
      A
      quality
      Not graded
      maintenance
      Connects Claude to Google Analytics 4 for querying website analytics via natural language, enabling traffic summaries, top pages, traffic sources, and user engagement.
      4
      -