ga4-mcp-server
Allows creating Google Analytics 4 audiences that can be shared to Google Ads for remarketing campaigns.
Provides read and write access to Google Analytics 4 properties, including running reports, managing custom dimensions, metrics, key events, audiences, and sending events via the Measurement Protocol.
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 create an audience of users who fired generate_lead in the last 30 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-mcp-server
A Model Context Protocol (MCP) server for Google Analytics 4 with both read and write access. Connect it to Claude (or any MCP client) and pull reports, manage configuration, build remarketing audiences, and send server-side events — in natural language, using your own Google credentials. No third-party service, no subscription.
Most GA4 MCP servers are read-only. This one also writes: it can create custom dimensions and metrics, mark conversions, create audiences (for remarketing lists you can share to Google Ads), and manage/use the Measurement Protocol.
Features
Read
List accounts and properties, property details, and data streams
Run GA4 reports (
run_report) and realtime reports (run_realtime_report)List custom dimensions, custom metrics, key events (conversions), and audiences
Write
Create and archive custom dimensions
Create custom metrics
Create key events (conversions)
Create and archive audiences (e.g. everyone who fired
generate_leadin the last 30 days)Create / list / delete Measurement Protocol API secrets
Send events into a property via the Measurement Protocol (with a
validate=Truemode that checks the payload without ingesting it)
Related MCP server: MCP Google Suite
Requirements
Python 3.10+ (the MCP SDK requires it)
A Google Cloud project and a service account with a JSON key
The service account granted access on your GA4 account/property (Viewer/Analyst for reads, Editor for writes)
Google setup (one time)
In the Google Cloud Console, create (or pick) a project.
Enable the Google Analytics Data API and the Google Analytics Admin API for that project.
Create a service account and download a JSON key for it.
In Google Analytics → Admin → Account (or Property) access management, add the service account's email (
...@your-project.iam.gserviceaccount.com) as a user — Editor if you want write access.
That's it — no OAuth consent screen, no token refresh. The service account authenticates directly.
Install
Using uv (recommended — it manages an isolated Python for you):
git clone https://github.com/burhan29ee/ga4-mcp-server.git
cd ga4-mcp-server
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -e .Or with pip:
python3 -m venv .venv && source .venv/bin/activate
pip install -e .Configure your MCP client
Point the server at your service-account key with the GOOGLE_APPLICATION_CREDENTIALS environment variable, then add it to your client. For Claude Desktop, edit claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json; Windows: %APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"ga4": {
"command": "/absolute/path/to/ga4-mcp-server/.venv/bin/python",
"args": ["-m", "ga4_mcp_server.server"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/service-account-key.json"
}
}
}
}Restart the client. You should be able to ask things like "list my GA4 properties," "pull last 28 days of users and conversions by channel," or "create a remarketing audience of everyone who registered for a webinar in the last 60 days."
Tool reference
Tool | Type | What it does |
| read | List accounts and their properties |
| read | Property name, time zone, currency, industry |
| read | Web/app streams and their measurement IDs |
| read | GA4 report by metrics/dimensions/date range |
| read | Realtime report (last ~30 min) |
| read | Custom dimensions on a property |
| write | Create a custom dimension |
| write | Archive a custom dimension |
| read | Custom metrics on a property |
| write | Create a custom metric |
| read | Key events (conversions) |
| write | Mark an event as a conversion |
| read | Audiences on a property |
| write | Create an audience of users who fired an event |
| write | Archive an audience |
| read | MP API secrets for a stream |
| write | Create an MP API secret |
| write | Delete an MP API secret |
| write | Send an event via the Measurement Protocol |
Development
pip install -e ".[dev]"
ruff check .
pytest -qSee CONTRIBUTING.md for the full workflow.
Security
The service-account key is a credential — treat it like a password. Never commit it (the .gitignore blocks key files), grant the service account the least access it needs, and rotate the key if it's ever exposed. See SECURITY.md for details and how to report a vulnerability.
Notes
The
mcpdependency is pinned to>=1.2,<2. The 2.0 SDK reorganized its API and removedmcp.server.fastmcp, which this server uses.Audiences use the GA4 Admin v1alpha API; the rest use the stable v1beta and Data APIs.
This is an independent open-source project and is not affiliated with or endorsed by Google.
License
Available Tools
19 toolsarchive_audienceA
Archive a GA4 audience. audience_id may be the numeric id or the full 'properties/NNN/audiences/MMM' name.
Inputs: audience_id (required), property_id (required).
archive_custom_dimensionB
Archive (delete) a custom dimension. custom_dimension_id may be the numeric id or the full 'properties/NNN/customDimensions/MMM' name.
Inputs: property_id (required), custom_dimension_id (required).
create_custom_dimensionB
Create a custom dimension. parameter_name is the event parameter / user property key; scope is 'EVENT', 'USER' or 'ITEM'. display_name may contain only letters, numbers, underscores and spaces.
Inputs: property_id (required), display_name (required), parameter_name (required), scope, +1 more.
create_custom_metricC
Create a custom metric. measurement_unit is one of STANDARD, CURRENCY, FEET, METERS, KILOMETERS, MILES, MILLISECONDS, SECONDS, MINUTES, HOURS.
Inputs: property_id (required), display_name (required), parameter_name (required), scope, +2 more.
create_event_audienceA
Create a GA4 audience of users who triggered a given event (e.g. 'purchase', 'generate_lead') — useful for remarketing lists that can be shared to Google Ads. membership_duration_days is how long a user stays in the audience (max 540).
Inputs: event_name (required), property_id (required), display_name (required), description, +1 more.
create_key_eventA
Mark an event as a key event (conversion). counting_method is 'ONCE_PER_EVENT' or 'ONCE_PER_SESSION'.
Inputs: event_name (required), property_id (required), counting_method.
create_measurement_protocol_secretA
Create a Measurement Protocol API secret on a data stream. Returns the secret_value (api_secret) needed by send_ga4_event. Treat it as sensitive.
Inputs: stream_id (required), property_id (required), display_name (required).
delete_measurement_protocol_secretB
Delete a Measurement Protocol API secret. secret_id may be the numeric id or the full resource name.
Inputs: secret_id (required), stream_id (required), property_id (required).
get_property_detailsA
Get configuration details for one GA4 property (name, time zone, currency, industry, create time).
Inputs: property_id (required).
list_account_summariesA
List every GA4 account and its properties the service account can see. Returns account name/id plus each property's display name and numeric id. Call this first to discover property ids for the other tools.
Inputs: no named parameters. Returns: result
list_audiencesB
List audiences defined on a GA4 property.
Inputs: property_id (required). Returns: result
list_custom_dimensionsA
List custom dimensions defined on a GA4 property.
Inputs: property_id (required). Returns: result
list_custom_metricsB
List custom metrics defined on a GA4 property.
Inputs: property_id (required). Returns: result
list_data_streamsA
List the data streams (web/app) on a GA4 property. The stream id (last path segment of 'name') is needed by the Measurement Protocol secret tools.
Inputs: property_id (required). Returns: result
list_key_eventsB
List key events (conversions) on a GA4 property.
Inputs: property_id (required). Returns: result
list_measurement_protocol_secretsA
List Measurement Protocol API secrets for a data stream. stream_id is the numeric id from list_data_streams.
Inputs: stream_id (required), property_id (required). Returns: result
run_realtime_reportA
Run a GA4 realtime report (last ~30 minutes). Example: metrics ['activeUsers'], dimensions ['country','unifiedScreenName'].
Inputs: metrics (required), property_id (required), limit, dimensions.
run_reportC
Run a GA4 report. metrics/dimensions are GA4 API names (e.g. metrics ['activeUsers','conversions'], dimensions ['date','sessionDefaultChannelGroup']). Dates accept YYYY-MM-DD or relative forms like '28daysAgo' / 'today'.
Inputs: metrics (required), property_id (required), limit, end_date, +2 more.
send_ga4_eventA
Send an event into a GA4 property via the Measurement Protocol. measurement_id is the stream's 'G-XXXXXXX'; api_secret comes from a Measurement Protocol secret; client_id identifies the user/device. Set validate=True to hit GA4's debug/validation endpoint (checks the payload WITHOUT ingesting it) — recommended before real sends.
Inputs: client_id (required), api_secret (required), event_name (required), measurement_id (required), +2 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 19 tools
Each tool targets a distinct resource and action—accounts, properties, streams, reports, custom dimensions/metrics, key events, audiences, secrets, and event sending. No two tools overlap in purpose; even similar operations (archive vs. delete) are clearly differentiated by resource type.
All tool names follow a consistent verb_noun snake_case pattern (list_*, create_*, get_*, run_*, archive_*, delete_*, send_*). The use of 'archive' for some resources and 'delete' for others reflects GA4 API conventions rather than inconsistency.
At 19 tools, the set is on the heavier side but still well-scoped for GA4 management, covering configuration, reporting, audience creation, and Measurement Protocol. Each tool serves a distinct purpose, though some trimming could be possible.
The surface covers core workflows but has notable gaps: no update/archive for custom metrics, no update for audiences, no delete for key events, and no tools for user properties or property management. These omissions could force workarounds but don't break the primary use cases.
Maintenance
Related MCP Connectors
Read-only Google Analytics 4 MCP server for AI assistants.
Hosted Google Analytics 4 MCP server, with each action switched on or off per account.
Google Search Console, GA4 and PageSpeed MCP server for Claude, ChatGPT and Cursor. Free, hosted.
Hosted MCP server for GA4, Google Ads and Search Console. Google OAuth, nothing to install.
Related MCP Servers
- AlicenseCqualityDmaintenanceA Model Context Protocol server that connects to Google Cloud services, allowing users to query logs, interact with Spanner databases, and analyze Cloud Monitoring metrics through natural language interaction.40186 npm80Apache 2.0
- AlicenseAqualityDmaintenanceA Model Context Protocol server that provides seamless integration with Google Workspace, allowing operations with Google Drive, Docs, and Sheets through secure OAuth2 authentication.845 PyPI3MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides unified access to Google Analytics 4 and Google Search Console data through real-time analytics queries.2MIT
- AlicenseNot gradedqualityDmaintenanceA powerful Model Context Protocol (MCP) server that provides comprehensive Google Analytics 4 (GA4), Google Search Console (GSC), and Google Merchant Center (GMC) integration for Claude Desktop and other MCP clients.Apache 2.0