BlogGuide

Google Analytics MCP: how to set it up with Claude

In this guide, we show you how to connect Google Analytics 4 to Claude Code or Gemini CLI with Google's own MCP server, in six steps.

Google publishes its own MCP server for Google Analytics. Once it's running, you can ask Claude about your GA4 traffic in plain English and get answers from the live Data API, with no report to build first.

Setting it up is another matter. Most of the work happens in Google Cloud, which is where people get stuck, so we go through it in the order you'll meet it, one screen at a time. There are six steps:

  1. Enable the two Analytics APIs
  2. Create an OAuth client
  3. Sign in with gcloud
  4. Add the server to your AI app
  5. Ask your first questions
  6. Allow changes, if you want them

We checked every step against Google's README on 12 November 2026.

1. Enable the two Analytics APIs

Open the Google Cloud console and pick a project, or create one. Any project works. It only holds the API access and the OAuth client, so a fresh one named after this job keeps things tidy when you come back to it later.

Under APIs & Services → Library, enable the Google Analytics Admin API and the Google Analytics Data API. The server needs both. Admin lists your accounts and properties, and Data runs the reports.

Note the project ID for step 4.

2. Create an OAuth client

The server signs in as you, so it needs an OAuth client in that project. Under APIs & Services → Credentials, choose Create credentials → OAuth client ID. Pick Desktop app.

Google may ask you to set up the consent screen first. Do it, choosing External if your account isn't part of a Google Workspace, and add your own email as a test user, because without that the sign-in in the next step is refused.

Download the client's JSON file and keep it somewhere you'll remember. If a screen looks different from this, Google's Manage OAuth clients page walks through each one.

3. Sign in with gcloud

Install the Google Cloud CLI and pipx. You also need Python 3.10 or newer. Then run this, with the path to the file from step 2:

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

A browser window opens. Sign in with the Google account that can see your Analytics properties, and approve the scopes it asks for.

When it finishes, gcloud prints a line starting Credentials saved to file:. Copy that path, because step 4 needs it.

4. Add the server to your AI app

Claude Code. Run this once, with your credentials path and project ID:

claude mcp add analytics-mcp \
  --scope user \
  -e "GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_CREDENTIALS_JSON" \
  -e "GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID" \
  -- pipx run analytics-mcp

Gemini CLI. Add this to ~/.gemini/settings.json:

{
  "mcpServers": {
    "analytics-mcp": {
      "command": "pipx",
      "args": ["run", "analytics-mcp"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
        "GOOGLE_CLOUD_PROJECT": "YOUR_PROJECT_ID"
      }
    }
  }
}

Other apps that run local MCP servers take the same command and the same two variables, and most of them only pick up a new server after a restart.

5. Ask your first questions

Start with "what can the analytics-mcp server do?" so the app lists its tools. Then ask for your accounts and properties. Every report runs against one property, so it helps to name it early in the conversation, or the app will keep asking which one you mean.

From there, ask the way you'd ask a colleague:

  • "Which channels brought the most users in the last 30 days?"
  • "Compare sessions this month with the same month last year."
  • "What are the most popular events in this property over the last 180 days?"
  • "Run a funnel from the pricing page to sign_up."

The server runs standard, funnel, conversion and realtime reports. Your event names are your own, so if an answer comes back as zero, ask it to list the property's events and custom dimensions before you trust the number.

6. Allow changes, if you want them

By default the server only reads. It can also create annotations, custom dimensions and key events, but only when you start it with --allow-write and sign in again in step 3 with https://www.googleapis.com/auth/analytics.edit added to the scopes.

Your Google account also needs the right role on the property, and unless you have a job for those tools, read-only is the safer default.

Final thoughts

Connecting Google Analytics to Claude takes six steps:

  1. Enable the two Analytics APIs
  2. Create an OAuth client
  3. Sign in with gcloud
  4. Add the server to your AI app
  5. Ask your first questions
  6. Allow changes, if you want them

The Cloud console part is a one-time job, and after that the server reuses the saved sign-in every time your app starts it.

If you'd rather skip Google Cloud altogether, Spreelytics, which we make, runs a hosted MCP server that Claude or ChatGPT connects to with one address and a sign-in, on every plan, the free one included. It's a separate analytics tool. You add its script to your site and it counts from that day. The MCP docs list what it can do, and how we compare with GA4 covers the rest.

For more on asking an AI about your numbers, see how to ask Claude Code or Cursor about your analytics.

See your own numbers today.

Free up to 1M events a month · no credit card

Contact

Tell us what you need.

A real person reads these. We usually reply within one working day.

Or email us directly at contact@spreelytics.com.