GA4 MCP Server
Allows running reports, viewing top pages, analyzing traffic sources, checking realtime users, and comparing periods using the Google Analytics 4 Data API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GA4 MCP Server What are my top pages this month?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
GA4 MCP Server
A Model Context Protocol (MCP) server that connects Claude Desktop (and other MCP clients) to the Google Analytics 4 Data API — run reports, view top pages, analyze traffic sources, check realtime users, and compare periods.
Features
7 Analytics Tools
Tool | Description |
| List all GA4 properties accessible by the service account |
| Run a custom report with any dimensions and metrics |
| Top pages by sessions with bounce rate and duration |
| Traffic breakdown by source/medium |
| Conversion events and their counts |
| Realtime active users and top pages |
| Compare current vs previous period with percentage changes |
Built-in Reliability
Token-bucket rate limiter — respects GA4's 10 concurrent request limit
Auto-retry on 429/5xx — exponential backoff (2s, 4s, 8s) up to 3 retries
Lazy imports — defers heavy Google client libraries for fast MCP handshake
Actionable error messages — guides users to fix permission, auth, and input errors
Related MCP server: Google Analytics MCP Server
Quick Start
Prerequisites
Python 3.11+
A Google Cloud service account with GA4 access
Claude Desktop (or any MCP-compatible client)
Set Up Google Analytics Access
Create a Google Cloud service account
Enable the Google Analytics Data API and Google Analytics Admin API in your project
Download the service account JSON key file
In GA4: go to Admin > Property Access Management and add the service account email as a Viewer
Installation
Run the published package without a global install:
uvx --from luminarylane-ga4-mcp luminarylane-ga4-mcpThe package is published on PyPI. Alternatively, install it with pip install luminarylane-ga4-mcp.
Configuration
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"ga4": {
"command": "uvx",
"args": ["--from", "luminarylane-ga4-mcp", "luminarylane-ga4-mcp"],
"env": {
"GA4_CREDENTIALS_PATH": "/path/to/service_account_credentials.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}Environment variables:
Variable | Required | Description |
| Yes | Path to service account JSON key file |
| No | Default property ID (can also pass per-tool) |
For local development only, credential files may be stored in paths excluded by .gitignore; never commit them. Prefer the explicit environment-variable path above.
Usage Examples
Once configured, ask Claude to:
"What are my top pages this month?"
"Show me traffic sources for the last 7 days"
"How does this week compare to last week?"
"Are there any active users on the site right now?"
"Run a report on sessions by country for the last 90 days"
"What conversion events fired this week?"
"List all GA4 properties I have access to"
Rate Limits
GA4 Data API allows 10 concurrent requests per property. The server handles this with a client-side token bucket and exponential backoff retries.
Troubleshooting
Permission denied (403)
The service account doesn't have access to the GA4 property. Go to GA4 Admin > Property Access Management and add the service account email as a Viewer.
Property not found (404)
Property IDs are numeric (e.g., 123456789), not the measurement ID (G-XXXXXXX). Use ga4_list_properties to find valid IDs.
Authentication failed (401)
Check that GA4_CREDENTIALS_PATH points to a valid service account JSON key file.
Invalid dimension/metric (400)
Check the GA4 Dimensions & Metrics Explorer for valid names. Common mistakes: sessions not session, sessionSource not source, pagePath not page.
Contributing
See CONTRIBUTING.md. Never commit service-account credentials or OAuth tokens.
Security
Report vulnerabilities privately using GitHub's private vulnerability reporting; do not include credentials in public issues.
License
MIT License — see LICENSE for details.
Acknowledgments
Anthropic for the MCP specification
Google Analytics Data API for the reporting API
Available Tools
7 toolsga4_compare_periodsA
Compare current period vs previous period for key metrics. Shows absolute values and percentage change for each metric.
Args: property_id: GA4 property ID (numeric). Leave empty to use GA4_PROPERTY_ID env var. metrics: Comma-separated metrics to compare (default: sessions, users, pageviews, bounce rate, avg session duration, conversions). days: Period length in days (default: 28). Compares last N days vs the N days before that.
Inputs: days, metrics, property_id. Returns: result
ga4_get_conversionsA
Get conversion events and their counts. Shows which events are firing and how often, broken down by event name.
Args: property_id: GA4 property ID (numeric). Leave empty to use GA4_PROPERTY_ID env var. days: Lookback period in days (default: 28). row_limit: Max rows to return (default: 20).
Inputs: days, row_limit, property_id. Returns: result
ga4_get_realtimeA
Get realtime active users and current events on the site. Shows what's happening RIGHT NOW — active users, top pages, traffic sources.
Args: property_id: GA4 property ID (numeric). Leave empty to use GA4_PROPERTY_ID env var.
Inputs: property_id. Returns: result
ga4_get_reportA
Run a custom GA4 report with any combination of dimensions and metrics.
Args: property_id: GA4 property ID (numeric). Leave empty to use GA4_PROPERTY_ID env var. dimensions: Comma-separated dimension names (e.g., "date", "sessionSource,sessionMedium", "pagePath", "country", "deviceCategory"). Default: "date". metrics: Comma-separated metric names (e.g., "sessions,totalUsers,screenPageViews", "bounceRate,averageSessionDuration,conversions"). Default: "sessions,totalUsers,screenPageViews". days: Lookback period in days (default: 28). row_limit: Max rows to return (default: 20, max: 100).
Inputs: days, metrics, row_limit, dimensions, +1 more. Returns: result
ga4_get_top_pagesA
Get top pages by sessions. Shows page path, sessions, users, pageviews, bounce rate, and average session duration.
Args: property_id: GA4 property ID (numeric). Leave empty to use GA4_PROPERTY_ID env var. days: Lookback period in days (default: 28). row_limit: Max rows to return (default: 20).
Inputs: days, row_limit, property_id. Returns: result
ga4_get_traffic_sourcesA
Get traffic sources breakdown by source/medium. Shows sessions, users, bounce rate, and conversions per traffic source.
Args: property_id: GA4 property ID (numeric). Leave empty to use GA4_PROPERTY_ID env var. days: Lookback period in days (default: 28). row_limit: Max rows to return (default: 20).
Inputs: days, row_limit, property_id. Returns: result
ga4_list_propertiesA
List all GA4 properties accessible by the service account. Returns property IDs and display names.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each special-purpose tool targets a distinct analytical view (top pages, traffic sources, conversions, realtime, period comparison), and ga4_get_report is explicitly generic. While ga4_get_report could theoretically replicate the specialized tools, its purpose is clearly different, so confusion is unlikely.
All tools follow the consistent ga4_<verb>_<noun> pattern with lowercase and underscores. Verbs are list, get, and compare, which is a predictable and uniform convention across the set.
With 7 tools, the server is well-scoped for a GA4 analytics wrapper. It covers property discovery and the most common report types without unnecessary bloat or excessive minimalism.
The tool set covers property listing, common report dimensions, custom queries, realtime data, and period-over-period comparison. Advanced GA4 features like funnel analysis or user exploration are absent, but these are beyond the typical expectation for an analytics MCP server.
Maintenance
Related MCP Connectors
Connect Google Analytics to ChatGPT. Query GA4 data in plain English and get instant insights.
GA4, Google Ads and Search Console in Claude. Read-only OAuth, multi-account for agencies.
Live Google Ads, GA4, Search Console, Meta Ads and GBP data in Claude, ChatGPT and any MCP client
Google Search Console, GA4 and PageSpeed MCP server for Claude, ChatGPT and Cursor. Free, hosted.
Related MCP Servers
- AlicenseAqualityBmaintenanceConnects 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.122,370 PyPI244MIT
- AlicenseNot gradedqualityDmaintenanceEnables querying Google Analytics 4 data using natural language through MCP clients like Claude and Cursor, supporting 200+ dimensions and metrics for traffic, user behavior, and e-commerce analysis.MIT
- FlicenseAqualityDmaintenanceConnects Claude to Google Analytics 4 for querying website analytics via natural language, enabling traffic summaries, top pages, traffic sources, and user engagement.4-
- AlicenseNot gradedqualityCmaintenanceEnables querying Google Analytics 4 reports, realtime data, funnels, and property configurations from any MCP client using natural language, with a one-command setup requiring only a service account key.22 npmApache 2.0