- Home
- MCP servers
- Google Analytics
Google Analytics
- python
13
GitHub Stars
python
Language
6 months ago
First Indexed
2 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
Installation
Add the following to your MCP client configuration file.
Configuration
View docs{
"mcpServers": {
"gomarble-ai-google-analytics-mcp-server": {
"command": "/Users/marble-dev-01/workspace/google_analytics_mcp/.venv/bin/python",
"args": [
"/Users/marble-dev-01/workspace/google_analytics_mcp/server.py"
]
}
}
}You can run a FastMCP-powered server that connects Google Analytics 4 data to MCP clients, enabling OAuth 2.0 authentication, automatic token handling, and rich GA4 analytics directly from your preferred MCP consumer.
How to use
You use this MCP server by running it as a local or HTTP-accessible service and connecting your MCP client to it. Once authenticated, you can issue GA4 data queries through predefined tools that cover properties, page views, active users, events, traffic sources, device metrics, and custom reporting. The server handles all authentication, token refresh, and storage locally, so you don’t manage tokens in your client calls.
How to install
Prerequisites include Python 3.10 or newer, a Google Cloud Platform account, and a GA4 property with data access.
# Clone the MCP server
git clone https://github.com/yourusername/google-analytics-mcp-server.git
cd google-analytics-mcp-server
# Create a virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
Configure OAuth credentials path in the environment before starting the server.
# Copy the example environment file
cp .env.example .env
# Edit the environment to point to your OAuth credentials
# Required: Path to OAuth credentials JSON file (downloaded from Google Cloud)
GOOGLE_ANALYTICS_OAUTH_CONFIG_PATH=/full/path/to/your/client_secret_file.json
{
"mcpServers": {
"google-analytics": {
"command": "/full/path/to/your/project/.venv/bin/python",
"args": [
"/full/path/to/your/project/server.py"
]
}
}
}
After configuring the environment and the Claude Desktop integration, restart Claude Desktop to load the new MCP server setting.
Additional notes
First-time authentication is initiated by issuing any GA4 command from Claude Desktop. A browser window opens for you to authenticate and authorize access to GA4 data. You should see a token file created locally (for example, google_analytics_token.json) and your GA4 properties appear in Claude’s responses.
Security and maintenance
Store credentials and tokens locally with strict file permissions. Use environment variables for sensitive data in production. Regularly rotate tokens and monitor API usage in Google Cloud Console to stay within quotas.
Troubleshooting
If authentication fails, re-authenticate by triggering the GA4 command again and ensure the token file is present. If the server cannot connect, verify the Claude config and that the MCP server is reachable at the expected path or port.
Usage examples
Common GA4 queries you can run through the MCP interface include listing GA4 properties, retrieving page views, active users, events, and traffic sources, and creating custom reports with specific metrics and dimensions.
Available tools
list_properties
List all GA4 accounts and properties.
get_page_views
Get page view metrics for a property over a date range.
get_active_users
Get active users metrics by date range and optional dimensions.
get_events
Get event metrics for a property over a date range.
get_traffic_sources
Get traffic source data over a date range with optional dimensions.
get_device_metrics
Get device-based metrics with optional dimensions.
run_report
Create comprehensive custom reports with metrics, dimensions, and filters.