← Back

Google Analytics MCP with Claude Code

Shawn Carrillo·
Claude CodeMCPGoogle Analytics

Official Google Documentation

Why this document?

The official resources left me with a few questions, this document attempts to fill in the blanks.

Prerequisites

Install pipx

Install pipx and ensure it's available on your $PATH. To understand why you don't need to explicitly install the Google Analytics MCP, check out What is pipx? at the end of this document.

Enable Google APIs

Follow the instructions to enable these APIs in your Google Cloud project (w/Billing Enabled):

Create an OAuth client

  1. Go to the Auth Dashboard
  2. Create a new client
  3. Download the client ID JSON file

Generate credentials

Run the following, replacing --client-id-file with the path to your downloaded JSON:

gcloud auth application-default login \
  --scopes https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform \
  --client-id-file=/path/to/client-id.apps.googleusercontent.com.json

This opens a browser to log in with your Google account and authorize permissions. After accepting, a credentials file is generated:

Credentials saved to file: /Users/USER/.config/gcloud/application_default_credentials.json

Note this path for the next step.

Claude Code MCP Configuration

Add analytics-mcp to your Claude settings file: ~/.claude.json

Note: The config file is ~/.claude.json, not ~/.claude/settings.json.

"mcpServers": {
  "analytics-mcp": {
    "command": "pipx",
    "args": [
      "run",
      "analytics-mcp"
    ],
    "env": {
      "GOOGLE_APPLICATION_CREDENTIALS": "/Users/USER/.config/gcloud/application_default_credentials.json",
      "GOOGLE_PROJECT_ID": "your-project-id"
    }
  }
}

Replace the two env values:

  • GOOGLE_APPLICATION_CREDENTIALS: Path to the generated credentials file. Default: /Users/USER/.config/gcloud/application_default_credentials.json
  • GOOGLE_PROJECT_ID: The Google Cloud project where you enabled the Analytics APIs. Used for billing.

Note: The MCP will have access to all Google Analytics accounts associated with your Google account. You can ask Claude to list them and then query specific properties.

Restart your Claude session and try it out. Something like:

List my Google Analytics projects please.

What is pipx?

pipx is a tool for running Python applications in isolated environments, like the Google Analytics MCP.

When Claude makes MCP calls, pipx downloads and executes the analytics-mcp package on demand using pipx run. The package is cached locally (typically ~/.local/pipx/.cache/) for 14 days before re-downloading. Same concept as npx in the Node/npm world.

Optionally, analytics-mcp can be installed permanently:

pipx install analytics-mcp

To inspect the installed package:

pipx list
pipx runpip analytics-mcp show analytics-mcp

Tradeoffs: pipx install pins you to the installed version until you manually run pipx upgrade analytics-mcp. With pipx run, the 14 day cache expiry means you get updates automatically. For MCP servers, pipx run is the better fit. You get updates without thinking about it.