
Google Analytics 4
STDIOMCP server enabling LLMs to interact with Google Analytics 4 data through API
MCP server enabling LLMs to interact with Google Analytics 4 data through API
A Model Context Protocol (MCP) server that allows Large Language Models (LLMs) to interact with Google Analytics 4 (GA4) data through the Google Analytics Data API.
pip install mcp-server-ga4
git clone https://github.com/yourusername/mcp-server-ga4.git cd mcp-server-ga4 pip install -e .
This server uses Google Cloud's Application Default Credentials (ADC) for authentication. Before using the server, you'll need to:
gcloud auth application-default login
For more details, see the Google Cloud Authentication documentation.
Start the server with your GA4 property ID:
mcp-server-ga4 --property-id YOUR_GA4_PROPERTY_ID
The server will use the standard MCP stdio transport by default.
You can also set configuration via environment variables:
GA4_PROPERTY_ID
: Your Google Analytics 4 property IDpip install mcp-server-ga4
gcloud auth application-default login
{ "mcpServers": { "ga4": { "command": "mcp-server-ga4", "args": ["--property-id", "YOUR_GA4_PROPERTY_ID"] } } }
Runs a standard GA4 report with configurable metrics, dimensions, and date ranges.
Parameters:
property_id
(optional): GA4 property ID (overrides the default)metrics
: List of metric names (e.g., ["activeUsers", "sessions"])dimensions
(optional): List of dimension names (e.g., ["date", "country"])date_range
: Date range in one of these formats:
{"start_date": "YYYY-MM-DD", "end_date": "YYYY-MM-DD"}
"last7days"
, "last30days"
, "today"
, "yesterday"
limit
(optional): Number of rows to return (default: 10)Gets real-time data for the past 30 minutes.
Parameters:
property_id
(optional): GA4 property ID (overrides the default)metrics
: List of metric names (e.g., ["activeUsers", "screenPageViews"])dimensions
(optional): List of dimension names (e.g., ["country", "city"])limit
(optional): Number of rows to return (default: 10)Retrieves available metrics and dimensions for a GA4 property.
Parameters:
property_id
(optional): GA4 property ID (overrides the default)type
(optional): Type of metadata to retrieve ("metrics"
, "dimensions"
, or "all"
, default: "all"
)What were the top 5 countries by active users in the last 30 days?
How many users are currently active on the site?
What metrics are available for me to query in GA4?
pip install -e ".[dev]"
pytest
MIT