GA4 MCP Server
Connects Claude to Google Analytics 4 for querying website analytics via natural language, enabling traffic summaries, top pages, traffic sources, and user engagement.
README
GA4 MCP Server
A Model Context Protocol server that connects Claude to Google Analytics 4, enabling natural language queries of your website analytics data.
Features
- get_traffic_summary — Sessions, users, page views, bounce rate, avg session duration
- get_top_pages — Most visited pages with engagement metrics
- get_traffic_sources — Traffic breakdown by source (organic, direct, referral, etc.)
- get_user_engagement — Engaged sessions, bounce rate, screen counts per session
Quick Start
1. Install Dependencies
npm install
2. Set Up Credentials
-
Copy the GA4 service account JSON file you downloaded to this folder:
cp ~/Downloads/app-coaching-ga4-73c82846b5b0.json ./credentials.json -
Create a
.envfile:cp .env.example .env -
Update
.envwith your GA4 Property ID:GA4_CREDENTIALS_PATH=./credentials.json GA4_PROPERTY_ID=544866887
3. Add Service Account to GA4
In Google Analytics:
- Go to Admin → Property Access Management
- Click + (Add user)
- Paste:
ga4-mcp-server@app-coaching-ga4.iam.gserviceaccount.com - Assign Viewer role
- Save
4. Build & Test
npm run build
npm run dev
You should see: GA4 MCP Server started
5. Test with MCP Inspector
In a new terminal:
npm run inspect
This opens an interactive tool to test the server. Try:
- Tool:
get_traffic_summary - Inputs:
- propertyId:
544866887 - startDate:
2026-07-01 - endDate:
2026-07-10
- propertyId:
Deployment Options
Option 1: Replit (Easiest)
- Create a new Replit
- Import from GitHub (clone this repo) or upload files
- Set environment variables in Replit Secrets:
GA4_CREDENTIALS_PATH=./credentials.json
- Upload
credentials.jsonto Replit - Run:
npm install && npm run build && npm run dev - Replit gives you a live URL
- Connect to Claude using that URL
Option 2: Railway
- Create a Railway project
- Upload this repo via GitHub
- Add
credentials.jsonas a config file - Set env var:
GA4_CREDENTIALS_PATH=./credentials.json - Deploy
- Get the URL from Railway
- Connect to Claude
Option 3: Local (for testing only)
Run npm run dev locally, then in Claude's MCP settings add:
{
"name": "ga4-mcp",
"type": "stdio",
"command": "node",
"args": ["dist/index.js"]
}
Usage in Claude
Once deployed, ask Claude things like:
- "What's the traffic summary for appcoaching.io for the last 7 days?"
- "Which pages on my site get the most traffic?"
- "What's driving traffic to appcoaching.io? Organic or direct?"
- "What's the engagement rate on my site?"
Claude will automatically call the appropriate GA4 tools and analyze the data.
Troubleshooting
"Credentials file not found"
- Ensure
credentials.jsonis in the project root - Check
GA4_CREDENTIALS_PATHenv var is set correctly
"Unauthorized" or "Permission denied"
- Verify the service account email is added to GA4 with Viewer role
- Check that the correct Property ID is being used (544866887)
"No data available"
- Ensure the date range has actual GA4 data
- GA4 can take 24-48 hours to start collecting data on a new property
Files
src/index.ts— Main MCP server implementationpackage.json— Dependencies and scriptstsconfig.json— TypeScript configurationcredentials.json— GA4 service account (keep secure!)
Security
Never commit credentials.json to GitHub. Add to .gitignore:
credentials.json
.env
node_modules/
dist/
The credentials file is sensitive—treat it like a password.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.