Set up Google Analytics MCP in Claude Code
Access GA4 data, run custom reports, and get real-time analytics from your AI editor. Official Google implementation.
1
Locate the config file
Claude Code reads MCP server configuration from the following file:
~/.claude.jsonCreate this file if it does not already exist.
2
Add the configuration
You can configure Google Analytics MCP using the CLI command or by editing the config file directly.
Option A: CLI command
bash
claude mcp add google-analytics-mcp -e GA_PROPERTY_ID=YOUR_GA_PROPERTY_ID -e GOOGLE_APPLICATION_CREDENTIALS=YOUR_GOOGLE_APPLICATION_CREDENTIALS -- npx -y @google-analytics/mcpOption B: Config file
json
{
"mcpServers": {
"google-analytics-mcp": {
"command": "npx",
"args": [
"-y",
"@google-analytics/mcp"
],
"env": {
"GA_PROPERTY_ID": "YOUR_GA_PROPERTY_ID",
"GOOGLE_APPLICATION_CREDENTIALS": "YOUR_GOOGLE_APPLICATION_CREDENTIALS"
}
}
}
}3
Set up environment variables
Google Analytics MCP requires the following environment variables:
GA_PROPERTY_IDRequiredGoogle Analytics 4 property ID
GOOGLE_APPLICATION_CREDENTIALSRequiredPath to Google service account JSON key file
4
Verify it works
Restart Claude Code. Google Analytics MCP should appear in your MCP server list with 4 tools available.
This server adds approximately 2,060 tokens to your context window for tool definitions.