Set up Google Analytics MCP in VS Code
Access GA4 data, run custom reports, and get real-time analytics from your AI editor. Official Google implementation.
1
Locate the config file
VS Code reads MCP server configuration from the following file:
.vscode/settings.json → mcp sectionCreate this file if it does not already exist. For VS Code, this is inside your workspace .vscode/settings.json file under the mcp section.
2
Add the configuration
Add the following to your VS Code config file:
json
{
"servers": {
"google-analytics-mcp": {
"type": "stdio",
"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 VS 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.