ga4-mcp
Provides read-only Google Analytics 4 reporting capabilities, including daily summaries, top pages, acquisition, events, realtime activity, metadata, and custom reports through the Google Analytics Data and Admin APIs.
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 show top pages for property 123456789 over the last 28 days"
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 Toolkit
A Python CLI and MCP server for read-only Google Analytics 4 reports. It provides daily summaries, top pages, acquisition, events, realtime activity, metadata, and custom reports through the Google Analytics Data and Admin APIs.
Why use it?
Use the same reporting client in shell scripts and MCP conversations. Common reports have ready-made commands, and results export as tables, JSON, or CSV.
This is an independent community project. Google maintains an official Analytics MCP server. This toolkit focuses on a small CLI and reusable report presets alongside MCP. It is an early release; see the limits below before using it for bulk exports.
Related MCP server: google_analytics
Install
Requires Python 3.11 or newer and uv.
git clone https://github.com/onionst/ga4-toolkit.git
cd ga4-toolkit
uv tool install .
ga4 --versionInstallation provides the ga4 and ga4-mcp commands. To update an existing installation after pulling
changes, run uv tool install --force .. There is no PyPI release; install from
this repository. If upgrading from the earlier private package, uninstall that
package first with uv tool uninstall ga4-codex-toolkit, then install this one.
Try the output format without a Google account:
uv sync --locked
uv run --locked python examples/offline_report.pyThe example uses synthetic data and shows a report with two returned rows out of three, including its truncation warning.
Authentication
Enable the Google Analytics Data API and Google Analytics Admin API in the Google Cloud project used for authentication. The Google identity must have access to the target GA4 property; the Viewer role is sufficient for reports.
The client checks credentials in this order:
A service-account JSON key referenced by
GOOGLE_APPLICATION_CREDENTIALS.~/.config/ga4-cli/google-credentials.json, if present.Google Application Default Credentials (ADC).
The second path respects XDG_CONFIG_HOME when set. Keep credential files outside
this repository. For a service account, grant its email access to the GA4 property
and point to its key:
export GOOGLE_APPLICATION_CREDENTIALS="/absolute/path/outside/repo/service-account.json"
ga4 propertiesFor user authentication, install the Google Cloud CLI and supply a Desktop OAuth client JSON file from your Google Cloud project:
ga4 auth --client-id-file /absolute/path/outside/repo/client_secret.jsonThis invokes gcloud auth application-default login with the Analytics read-only
and Cloud Platform scopes. Follow the URL printed by gcloud; the browser does not
launch automatically unless you add --launch-browser. Reporting requests use
the analytics.readonly scope. No Analytics modification tools are exposed.
ga4 doctor checks access by listing properties. ga4 auth starts a new user
authentication flow or detects the dedicated service-account file; use doctor
to verify an existing ADC setup.
CLI
Use the numeric GA4 property ID, not the G-... measurement ID. Pass --property
on every report to make the target explicit:
ga4 properties --format json
ga4 overview --property 123456789 --start 28daysAgo --end yesterday
ga4 pages --property 123456789 --limit 25
ga4 acquisition --property 123456789 --format csv
ga4 events --property 123456789 --format json
ga4 realtime --property 123456789 --dimensions country --metrics activeUsers,eventCount
ga4 report --property 123456789 --dimensions date,country --metrics sessions,activeUsers
ga4 metadata --property 123456789 --search sessionData commands support --format table, json, and csv. Historical reports
default to 28daysAgo through yesterday. Custom reports also accept
--dimension-filter-json, --metric-filter-json, and --order-by.
An explicit property takes precedence over GA4_PROPERTY_ID, followed by an
optional default saved with ga4 use PROPERTY_ID. The default lives in
~/.config/ga4-cli/config.json and can be inspected with ga4 config. When
--property is omitted, the CLI prints the selected property on stderr before
querying it. An explicitly empty or invalid ID is rejected.
MCP
Configure an MCP client to launch ga4-mcp over stdio. Use the absolute executable
path if the client does not inherit your shell's PATH:
{
"mcpServers": {
"google-analytics": {
"command": "/absolute/path/to/ga4-mcp"
}
}
}The server exposes eight tools:
Tool | Purpose |
| Discover accessible properties |
| Daily traffic, engagement, key events, and revenue |
| Top page paths and titles |
| Session channels and source/medium |
| Event counts, users, and values |
| Custom historical reports and filters |
| Realtime activity |
| Available dimensions and metrics |
property_id is required for every report and metadata call. Omitted, null, and
empty values are rejected; MCP reports do not fall back to environment variables
or saved defaults. Use property discovery when the target is unknown.
Example arguments for ga4_top_pages:
{
"property_id": "123456789",
"start_date": "7daysAgo",
"end_date": "yesterday",
"limit": 25
}MCP and CLI share authentication. The saved default property is a CLI convenience.
Report completeness
JSON and MCP reports include the target property_id, total row_count,
returned_row_count, a truncated flag, and a warnings list. If the API reports
more rows than returned, the report is marked truncated. The CLI also writes the
warning to stderr in every output format, leaving stdout suitable for pipelines.
Increase --limit (or MCP limit) or narrow the report to retrieve more of the
matching rows. The daily overview uses a fixed 366-row cap; shorten its date range
or use a custom report when it is truncated. truncated: false only describes row
limits; Google may still apply thresholds or sampling, reflected in metadata.
Limits
Report requests return at most 10,000 rows and do not paginate. Daily overview requests cap results at 366 rows. Historical reports require 1–9 dimensions and 1–10 metrics; realtime reports require 1–4 of each. This version accepts simple dimension and metric names; namespaced custom fields are not supported.
Metric/dimension compatibility, retention, and quotas are enforced by Google. The client uses a 60-second request timeout and does not automatically retry API failures. The CLI reports API errors on stderr and exits with status 2.
Development
uv sync --locked
uv run --locked python -m unittest discover -s tests -v
uv buildTests use fake API responses and a local MCP handshake. They require no Google credentials and do not query Analytics.
See CONTRIBUTING.md for contribution guidelines and CHANGELOG.md for release notes. Licensed under MIT.
Available Tools
8 toolsga4_acquisitionC
Return session channels and source/medium acquisition performance.
Inputs: property_id (required), limit, end_date, start_date. Returns: object
ga4_eventsC
Return top GA4 events, users, key events, and event values.
Inputs: property_id (required), limit, end_date, start_date. Returns: object
ga4_list_propertiesA
List every GA4 property accessible with the current read-only credentials.
Inputs: no named parameters. Returns: result
ga4_metadataB
List compatible GA4 dimensions and metrics, optionally filtered by text.
Inputs: property_id (required), search. Returns: object
ga4_overviewC
Return daily users, sessions, engagement, key events, and revenue.
Inputs: property_id (required), end_date, start_date. Returns: object
ga4_realtimeB
Run a GA4 realtime report for activity from the last 30 minutes.
Inputs: property_id (required), limit, metrics, descending, +2 more. Returns: object
ga4_run_reportC
Run a custom historical GA4 report with requested dimensions and metrics.
Inputs: metrics (required), dimensions (required), property_id (required), limit, +6 more. Returns: object
ga4_top_pagesB
Return top page paths and titles ordered by page views.
Inputs: property_id (required), limit, end_date, start_date. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Most tools are clearly distinct: one lists properties, one fetches metadata, one covers realtime data, and the rest are named report types. There is minor overlap between ga4_overview and ga4_events, which both surface users and key events, but their primary purposes remain distinguishable.
All tools share the ga4_ prefix and use snake_case, but the naming convention is mixed: ga4_list_properties and ga4_run_report are verb_noun while the other six are noun-style names like ga4_overview, ga4_events, and ga4_realtime. The prefix keeps them readable, but the pattern is not fully consistent.
With 8 tools, the server is well-scoped for a GA4 reporting assistant. Each tool has a clear role, and the count is neither bloated nor too thin.
The tool set covers listing properties, exploring compatible dimensions and metrics, realtime reporting, common pre-built reports, and a fully custom report runner. For a read-only GA4 analytics server, this provides comprehensive coverage with no obvious dead ends.
Maintenance
Related MCP Connectors
Hosted, read-only Google Analytics 4 MCP: reports, period comparisons, realtime, custom fields.
Read-only Google Analytics 4 MCP server for AI assistants.
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
Hosted MCP server for GA4, Google Ads and Search Console. Google OAuth, nothing to install.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides full Google Analytics 4 management and reporting capabilities via MCP, including property management, custom dimensions, audiences, events, data streams, and real-time reporting.MIT
- AlicenseNot gradedqualityCmaintenanceEnables querying Google Analytics 4 data through MCP tools for running reports, listing properties, getting real-time metrics, and exploring metadata.462 npmMIT
- AlicenseNot gradedqualityCmaintenanceRead-only access to Google Analytics 4 reporting data, including traffic overview, top pages, traffic sources, and conversion events, supporting custom report queries via MCP.MIT
- AlicenseAqualityBmaintenanceEnables MCP clients to query Google Analytics 4 reporting and configuration data through 27 read-only tools, including pivots, funnels, realtime reports, Admin API inspection, and diagnostics, with identifiers redacted by default.27148 npmApache 2.0