AI-Powered SEO & CRO · stuseo.uk
Setting Up Google Analytics 4 MCP with Claude
Connect Claude directly to your GA4 data in 15 minutes
AI-POWERED SEO & CRO WITH CLAUDE — 9-PART SERIES
You are reading Part 2 of 9. Start from the beginning if you haven’t read the introduction yet.
Why GA4 + Claude Is a Game Changer
Google Analytics 4 holds a tremendous amount of insight about your site — but unlocking that insight typically means writing complex custom reports, building Looker Studio dashboards, or exporting CSV files and pasting them into a spreadsheet. It’s slow, manual, and you usually already know what question you’re trying to answer before you start, which limits what you discover.
When Claude connects directly to your GA4 property via MCP, all of that changes. You describe what you want to understand in plain English, and Claude queries your actual live data, interprets the results, and surfaces the things worth acting on — including things you didn’t think to ask about.
In this post I’ll walk you through the exact steps to set up the GA4 MCP server in the Claude desktop app. It takes about 15 minutes.
What the GA4 MCP Server Can Do
Once connected, Claude can query your GA4 property for metrics including sessions, users, bounce rate, engagement rate, average session duration, and conversion events. It can break these down by dimension — page, channel, device, country, landing page, and more — and compare across date ranges.
It can also access your custom dimensions and metrics, your goal completions, your funnel data, and your real-time report. Essentially anything you can pull through the GA4 Data API is available to Claude.
Step 1: Enable the Google Analytics Data API
First, you need to enable API access to your GA4 property. Go to the Google Cloud Console, create a new project (or use an existing one), and enable the Google Analytics Data API.
Next, create a service account under IAM & Admin → Service Accounts. Download the JSON key file — you’ll need this in a moment. Then go to your GA4 property settings, click on Account Access Management, and add the service account email as a Viewer.
Step 2: Install the GA4 MCP Server
With Node.js installed on your machine, open your terminal and install the GA4 MCP server package. The most widely used one is @modelcontextprotocol/server-google-analytics — check the MCP server registry for the latest recommended package, as the ecosystem moves quickly.
Place your downloaded JSON key file somewhere accessible, for example ~/.config/ga4-mcp/credentials.json.
Step 3: Configure the Claude Desktop App
Open the Claude desktop app and go to Settings → Developer → Edit Config. This opens your claude_desktop_config.json file. Add an entry for the GA4 server inside the mcpServers object:
{
"mcpServers": {
"google-analytics": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-google-analytics"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/Users/yourname/.config/ga4-mcp/credentials.json",
"GA4_PROPERTY_ID": "properties/YOUR_PROPERTY_ID"
}
}
}
}
Replace the credentials path with where you saved your JSON key file, and replace YOUR_PROPERTY_ID with your GA4 property ID (found in GA4 → Admin → Property Settings — it’s the number after “properties/”).
Step 4: Restart Claude and Verify the Connection
Save the config file and restart the Claude desktop app. You should see a small tools icon in the chat interface indicating MCP servers are active. Click it to confirm Google Analytics appears in the list.
Test the connection with a simple question: “How many sessions did my site get last week?” If Claude returns your actual GA4 data, you’re connected.
What to Ask Claude Once Connected
The real power comes from how you ask questions. Because Claude understands context and can reason across multiple queries, you can ask nuanced questions that would take hours to answer manually:
- “Which of my organic landing pages have the highest engagement rate but lowest conversion rate this month?”
- “Show me my top 10 pages by sessions over the last 90 days, and flag any that have declined by more than 20% compared to the same period last year.”
- “What’s my mobile vs desktop conversion rate split, and has it changed significantly in the past three months?”
- “Which traffic channels drive the most engaged users — high session duration, multiple pages per session — even if they’re not the top channels by raw volume?”
We’ll cover a full library of high-value prompts in Part 6 (SEO prompts) (pending) and Part 7 (CRO prompts) (pending).
Troubleshooting Common Issues
If Claude isn’t returning GA4 data, check these in order. First, verify the service account has been added to the GA4 property — it can take a few minutes to propagate. Second, confirm the property ID is formatted correctly (it should be the numeric ID only, without “properties/” if the server config already includes that prefix — check your specific package’s documentation). Third, check that Node.js is installed and the npx command works in your terminal. Finally, look at the Claude desktop app logs under Help → View Logs for any MCP connection errors.
When Your GA4 Connection Stops Working: Reauthentication
Even after a successful setup, you may find that Claude stops returning GA4 data at some point. The most common cause is that your Google credentials have expired. This happens periodically with application default credentials and is completely normal.
Signs You Need to Reauthenticate
- Claude returns an error mentioning “Reauthentication is needed” or “Getting metadata from plugin failed”.
- The GA4 MCP tool appears in Claude’s tools list but returns no data, or returns an authentication error when queried.
- The connection worked previously but has stopped without you changing anything.
- You see a 503 error or a message referencing
application-default login.
What to Do
Open a Command Prompt or PowerShell on Windows and run the following (updating the path to your actual JSON file):
gcloud auth application-default login --client-id-file="/path/to/your/oauth_client.json" --scopes="https://www.googleapis.com/auth/analytics,https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/analytics.manage.users.readonly,https://www.googleapis.com/auth/analytics.edit,https://www.googleapis.com/auth/cloud-platform"
This opens a browser window asking you to sign in with the Google account that has access to your GA4 property. Once you approve, the credentials are refreshed immediately — no restart of the Claude desktop app is needed.
If gcloud is not recognised as a command, the Google Cloud SDK may not be on your system PATH. Install it from cloud.google.com/sdk — there’s a Windows installer (.exe) — then open a new Command Prompt and run the command above.
If you used a service account JSON key file rather than application default credentials, the key itself does not expire — but check that the service account still has at least Viewer access to your GA4 property in GA4 → Admin → Account Access Management.
Next up: Part 3 — Setting Up Google Search Console MCP so Claude can see your search performance data alongside your analytics.
SERIES NAVIGATION
- Introduction to the AI-Powered SEO & CRO Stack
- Setting Up Google Analytics 4 MCP ← You are here
- Setting Up Google Search Console MCP
- Setting Up FreeCrawl: Your AI-Ready Site Crawler (pending)
- Running Multiple Microsoft Clarity Projects (pending)
- Powerful SEO Prompts Using Your MCP Stack (pending)
- Powerful CRO Prompts Using Your MCP Stack (pending)
- Clever SEO Automations with Claude (pending)
- Clever CRO Automations with Claude (pending)


Leave a Reply