Builders: list your MCP server or AI tool for free.Submit a listing

How to connect Google Analytics 4 to Claude with the official MCP server

3D bar chart blocks and a trend ribbon flowing through a cable into a speech bubble

You can connect GA4 to Claude by running Google’s official Google Analytics MCP server on your computer and adding it to the Claude desktop app or Claude Code. Once it is connected, you ask questions such as “Which channels drove key events last week?” and Claude runs the report against your own property. Plan for 30 to 60 minutes the first time, most of it spent on Google Cloud credentials.

An MCP server is a small program that lets an AI client use another tool. This one, listed as the Google Analytics MCP server, reads data through the Google Analytics Admin API and Data API. It is read-only unless you deliberately switch on write tools.

Before you start

  • A GA4 property and a Google account with access to it. Universal Analytics is not supported.
  • A Google Cloud project where you can enable APIs. Ask your IT or data team if you do not have one.
  • Claude installed: the Claude desktop app, or Claude Code in a terminal.
  • About an hour and permission to install two command-line tools: pipx and the Google Cloud CLI (gcloud).
  • Approval to connect company data. If your team has rules for AI tools, run through our MCP security checklist for marketing teams first.

Step 1: Install pipx

The server is a Python package, and pipx runs it without any manual Python setup. On a Mac with Homebrew, open Terminal and run:

brew install pipx
pipx ensurepath

On Windows or Linux, follow the pipx install guide. Close and reopen your terminal afterwards so it picks up the change.

Step 2: Enable the two Google Analytics APIs

In the Google Cloud console, pick your project and enable both of these:

  • Google Analytics Admin API
  • Google Analytics Data API

Note the project ID shown on the project dashboard. It looks like my-marketing-project-123456, and you need it in step 4.

Step 3: Create your Google credentials

The server signs in to Google with Application Default Credentials (ADC), a credentials file that Google’s tools store on your computer. You create it with the Google Cloud CLI.

  1. Install the Google Cloud CLI.
  2. In your Cloud project, create an OAuth client of the desktop type and download its JSON file. Google’s Manage OAuth Clients guide walks through it. You may be asked to set up the consent screen first.
  3. Run this command, replacing YOUR_CLIENT_JSON_FILE with the path to the file you downloaded:
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 GA4 properties and approve access. The terminal then prints a line that starts with Credentials saved to file:. Copy that path. You need it in the next step.

If your company prefers a service account, the project’s GitHub page also shows a version of the command that uses service account impersonation.

Step 4: Add the server to Claude

Pick the option for the Claude app you use. You can do both.

Option A: Claude desktop app

Claude desktop reads local servers from a file called claude_desktop_config.json. To open it, go to Settings, then Developer, and click Edit Config. In newer versions of the app, local servers sit under Settings, then Desktop app, in the Local MCP servers section of the Extensions page. You can also open the file directly:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Add this block, replacing the two placeholder values with your credentials path from step 3 and your project ID from step 2:

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

If the file already lists other servers, add the analytics-mcp entry inside the existing mcpServers block instead of pasting a second one. On Windows, write each backslash in the path twice, as in C:\\Users\\you\\....

Save the file, then quit Claude completely and open it again. Closing the window is not enough.

Option B: Claude Code

Run this in your terminal, with the same two values replaced:

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

The --scope user part makes the server available in every project on your computer. The -- separates Claude Code’s own options from the command that starts the server. Run claude mcp list afterwards, and the server should show as connected.

Check that it works

In Claude desktop, click the “+” button in the chat box and open Connectors. You should see analytics-mcp with its tools. In Claude Code, type /mcp inside a session.

Then try these prompts, one at a time:

List the Google Analytics accounts and GA4 properties you can see.
For the property named "Main website", compare sessions, engaged sessions and key events by session default channel group for the last 28 days against the previous 28 days. Tell me which dimensions, metrics and date ranges you used.
Which key events and custom dimensions are set up on this property?

A good first answer lists your account and property names with their property IDs. Claude may ask you to approve each tool call. Read what it plans to run, then allow it. For the second prompt, a good answer is a small table by channel plus a plain note of the metrics and dates used, so you can match it in GA4 before you share it.

Common problems

Why doesn’t Claude desktop show the server?

The most common causes are a typo in the JSON (a missing comma or quote), an app that was not fully restarted, or Claude not finding pipx. Desktop apps often do not see the same command paths as your terminal. Run which pipx in Terminal and put the full path it prints, such as /opt/homebrew/bin/pipx, in the command field. On macOS, logs live in ~/Library/Logs/Claude, and the file named after the server shows its errors.

Why does Claude say it has no access or the API is disabled?

Check three things. Both APIs must be enabled in the same project as your GOOGLE_CLOUD_PROJECT value. The login command must include the analytics.readonly scope, so re-run it if you left the scope out. And the Google account you signed in with needs access to the property, which you can check in GA4 under Admin, then Property access management.

What does a “Failed to resolve” DNS error mean?

On macOS, a VPN or company DNS setup can stop the server from reaching Google’s APIs, even when your browser works fine. Google’s troubleshooting guide suggests adding "GRPC_DNS_RESOLVER": "native" to the env block, or -e "GRPC_DNS_RESOLVER=native" to the Claude Code command. Only add it if you see this error.

What to do next

Start with read-only questions for a week before you consider write tools such as annotations. To decide whether a hosted setup would suit your team better, read local vs remote MCP servers. For report ideas, try our six marketing tasks to try first with MCP servers. Search data pairs well with GA4, so the Search Console MCP server is a natural next connection.

Frequently asked questions

Do I need to pay for the Google Analytics MCP server?

No. Google publishes it as free, open-source software. You use your existing GA4 property and a Google Cloud project, and the normal Google Analytics Data API quotas apply to your requests.

Can Claude change my GA4 settings through this server?

Not with the setup in this guide. The server only runs read tools unless you start it with the --allow-write flag and give your credentials the analytics.edit scope.

Does this work in Claude on the web?

Not as set up here. This guide runs the server on your own computer, which works in the Claude desktop app and Claude Code. Claude on the web connects to remote servers added as custom connectors, and hosting Google's server that way needs engineering help.

Which Google account should I sign in with?

Use an account that already has access to the GA4 properties you want to query. The server can see exactly what that account can see, so an account limited to one or two properties is a sensible choice for a first try.

Why does Claude give a different number from the GA4 interface?

Usually the date range, metric or dimension differs, such as users instead of sessions. Ask Claude which settings it used and match them in GA4. Data from the last 24 to 48 hours can also still change while Google processes it.

About the author. The Marketing MCP Hub team writes the guides on this blog and checks every listing against the publisher's own documentation before it goes live. Found an error? Email editors@marketingmcphub.com. Read how we work in our listing policy.