Perfect for non-coders, marketers, analysts, and founders who want to integrate GA4 insights into Claude Desktop using a Python-powered MCP server — all locally and securely.
What is an MCP Server?
MCP (Model Context Protocol) servers allow AI tools like Claude to interact with real-world data and tools via a standard protocol. Think of it like a bridge between your local data (like GA4 or Shopify) and Claude’s chat interface — so Claude can ask for data and act on it using well-defined tools, all running securely on your machine.
If you want to know more about How Marketers can use MCP servers, here’s a detailed guide, The End-to-End Model Context Protocol (MCP) Guide for Marketers
What You’ll Achieve
- Pull GA4 reports via Claude (e.g., “Show traffic for the last 7 days”)
- Run everything locally (no cloud or third-party hosting)
- Use Claude as a smart assistant connected to your actual GA4 data
Tools You’ll Need 🛠️
Tool | Why You Need It |
Claude Desktop | To access and chat with tools |
Python (3.10+) | To run the MCP server locally |
Git (optional) | To clone the project repository |
GA4 Access | Your credentials to connect to your property |
🚀 Need Help With the Setup?
If the setup feels too technical, our team is here to help.
Don’t worry, we’ve got your back!
👉 Click here to get expert assistance now!
Step 1: Install Python + Add to PATH
- Download Python from: https://www.python.org/downloads
- Run the installer
- Important: ✅ Check “Add Python to PATH”
- Click Install Now
To confirm it’s installed:
Open your command line:
- Windows: Press Win + R, type cmd, and press Enter
- macOS: Press Cmd + Space, type Terminal, and hit Enter
- Linux: Press Ctrl + Alt + T, or open Terminal from your applications menu
Then run this text below:
python --version
If installed correctly, you should see it return something like: Python 3.10.13
( Note: the number next to python might differ based on the version you have downloaded )
Step 2: Download the GA4 MCP Project
Option A: Clone with Git (Recommended)
git clone <https://github.com/smacient/mcp-ga4.git>
cd mcp-ga4
Option B: Download ZIP
- Visit: https://github.com/smacient/mcp-ga4
- Click Code → Download ZIP
- Extract to a folder (e.g., Documents/mcp-ga4)
Step 3: Set Up Python Virtual Environment
- Open Command Prompt (CMD)
- Navigate to the project folder:
cd C : \\Users\\YourName\\Documents\\mcp-ga4\\mcp-ga4-main
1. Create a virtual environment by using the line below:
python -m venv .venv
2. Activate it:
.venv\\Scripts\\activate
Your CMD should now show: (.venv) before the prompt
Step 4: Install MCP + Dependencies
Inside the same activated terminal:
pip install uv
uv sync
You should see a lot of dependencies being downloaded, and the sync would have given
Step 5: Get Your GA4 Credentials
Getting your credentials is the only step where you’ll need to log into the Google Cloud Console. Follow this carefully — it’s easier than it sounds!
- Visit https://console.cloud.google.com and log in with your Google account.
- Click “Select a project” (top menu) → “New Project”, and give it a name like “Claude GA4 MCP”
- After it’s created, click “APIs & Services → Library” in the sidebar
- Search for “Google Analytics Data API”, click it, and press Enable
- Next, go to “Credentials” in the sidebar
- Click “Create Credentials → Service Account”, and fill in a name like “Claude GA4 Bot”
- Skip roles/permissions for now (you can click Done)
- After creation, click into your new service account → Go to the “Keys” tab → Click “Add Key → Create New Key” → Choose JSON and download the file
- Rename this downloaded file to credentials.json
- Move this file into the main folder of your project (where ga4_server.py is located)
- Then in your Google Analytics property settings, share access with the email address shown in the JSON file (it ends with @<project>.iam.gserviceaccount.com) and give it Viewer or Analyst access
Step 6: Add a .env File
- Open the mcp-ga4-main folder where you extracted or cloned the project.
- Go inside the localserver folder.
- Right-click in the folder → choose New → Text Document → name it exactly .env (delete the .txt extension if it appears).
- Open this file and paste the following line:
GOOGLE_APPLICATION_CREDENTIALS=C:\\Users\\YourName\\Documents\\mcp-ga4\\mcp-ga4-main\\credentials.json
Tip: On Windows, this line works as-is. You don’t need to double the slashes like you would in Python scripts.
Step 7: Install the Server into Claude
Run this in your terminal (with the virtual env still active):
uv run mcp install localserver/ga4_server.py
This registers the server with Claude Desktop.
Step 8: Configure Claude Desktop
Open Claude → Settings → Developer → Edit Config
- A folder will open and Add this script below inside claude.json under “mcpServers”:
Step 9 : Ask Claude!
( Pro Tip : After saving the claude.json document, close Claude completely. Make sure you remove any instance of Claude running. You can use the task manager to ensure this. )
Launch Claude Desktop and ask:
Get a GA4 report for the last 7 days.
“Google Analytics 4”: {
“command”: “uv”,
“args”: [
“run”,
“–with”,
“mcp[cli]”,
“mcp”,
“run”,
“C:\\Users\\YourName\\Documents\\mcp-ga4\\mcp-ga4-main\\localserver\\ga4_server.py”
],
“env”: {
“VIRTUAL_ENV”: “C:\\Users\\YourName\\Documents\\mcp-ga4\\mcp-ga4-main\\.venv”,
“PATH”: “C:\\Users\\YourName\\Documents\\mcp-ga4\\mcp-ga4-main\\.venv\\Scripts;${PATH}”,
“GOOGLE_APPLICATION_CREDENTIALS”: “C:\\Users\\YourName\\Documents\\mcp-ga4\\mcp-ga4-main\\credentials.json”
}
}
Claude will:
- Detect the GA4 MCP server
- Ask for permission to use it
- Fetch your data using tools like get_report, compare_report_metrics, etc.
Troubleshooting Tips
❌ No tools visible in Claude? → Double-check your claude.json paths and restart Claude
❌ Env not loaded? → Confirm .env is in the right folder and dotenv.config() is in the script
❌ Permission error from GA4? → Make sure your service account has correct GA4 access in GA settings
That’s It!
You now have a fully running local Python-powered GA4 analytics server talking to Claude. Secure, private, and easy to modify — no cloud hosting required.
Check out our other blogs for more information on MCP servers and various other tools that will end up making your life easy:
- The End-to-End Model Context Protocol (MCP) Guide for Marketers
- Top AI Tool Libraries To Find the Best AI Tools
- Notebook LM: A Guide with Use Cases and Examples
FAQs
The Model Context Protocol (MCP) Server acts as a bridge between Google Analytics 4 and Claude Desktop, enabling seamless context-aware data flow for enhanced tracking and analysis.
Not necessarily. While basic familiarity with APIs and configuration files is helpful, this guide breaks down the integration steps in a user-friendly, non-technical manner.
You’ll be able to access behavioral insights, user events, traffic sources, and engagement metrics, all contextualised within Claude Desktop’s AI-driven interface.
Yes, when configured properly, the integration follows GA4’s data privacy standards and MCP’s secure data transfer protocols, ensuring compliance with GDPR and similar regulations.