A Model Context Protocol (MCP) server for accessing Google Analytics 4 reporting data.
npm install -g mcp-ga4-data
Or use it directly via npx:
npx mcp-ga4-data
- A Google Cloud project with the Google Analytics Data API enabled
- A service account with appropriate permissions for Google Analytics
- A credentials.json file for the service account
This MCP is designed to work with Claude or other MCP Clients. To use it with Claude, create a claude-mcp-config.json
file with the following content:
{
"mcpServers": {
"google-analytics-data": {
"command": "npx",
"args": ["mcp-ga4-data"],
"cwd": "/tmp",
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/credentials.json"
}
}
}
}
Replace /path/to/your/credentials.json
with the actual path to your Google service account credentials file.
You need to provide the path to your Google service account credentials file. There are two ways to do this:
Set the GOOGLE_APPLICATION_CREDENTIALS
environment variable directly:
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credentials.json
Alternatively, you can create a .env
file in the directory where you want to use the MCP with the following content:
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credentials.json
Note: The .env
file is completely optional. The package will work fine with just the environment variable set.
The MCP provides the following functions:
-
ga4_data_api_run_report
- Run a standard GA4 report with dimensions and metrics -
ga4_data_api_run_pivot_report
- Run a pivot report with dimensions, metrics and pivot specifications -
ga4_data_api_run_realtime_report
- Run a realtime GA4 report with dimensions and metrics -
ga4_data_api_get_metadata
- Get metadata about available dimensions and metrics
ISC