GA4 MCP Server
Provides tools for querying Google Analytics 4 data, including traffic summary, top pages, traffic sources, and user engagement metrics.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GA4 MCP Server What's the traffic summary for the last week?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
Related MCP server: GA4 MCP Server
Quick Start
1. Install Dependencies
npm install2. Set Up Credentials
Copy the GA4 service account JSON file you downloaded to this folder:
cp ~/Downloads/app-coaching-ga4-73c82846b5b0.json ./credentials.jsonCreate a
.envfile:cp .env.example .envUpdate
.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.comAssign Viewer role
Save
4. Build & Test
npm run build
npm run devYou should see: GA4 MCP Server started
5. Test with MCP Inspector
In a new terminal:
npm run inspectThis opens an interactive tool to test the server. Try:
Tool:
get_traffic_summaryInputs:
propertyId:
544866887startDate:
2026-07-01endDate:
2026-07-10
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 ReplitRun:
npm install && npm run build && npm run devReplit 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 fileSet env var:
GA4_CREDENTIALS_PATH=./credentials.jsonDeploy
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 rootCheck
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.
Available Tools
4 toolsget_top_pagesB
Get top pages by views for a date range
Inputs: endDate (required), startDate (required), propertyId (required), limit.
get_traffic_sourcesB
Get traffic breakdown by source (organic, direct, referral, etc.)
Inputs: endDate (required), startDate (required), propertyId (required).
get_traffic_summaryA
Get overall traffic summary for a date range (sessions, users, page views, bounce rate, avg session duration)
Inputs: endDate (required), startDate (required), propertyId (required).
get_user_engagementC
Get user engagement metrics (engaged sessions, bounce rate, avg session duration, screens per session)
Inputs: endDate (required), startDate (required), propertyId (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool targets a distinct aspect of GA4: top pages, traffic sources, overall traffic summary, and user engagement. No overlapping purposes.
All tools follow a consistent verb_noun pattern ('get_<metric_group>'), making them predictable and easy to navigate.
With 4 tools, the set is lean but covers core reporting needs. Slightly under-scoped for a full analytics server, but still reasonable.
Covers basic traffic, pages, sources, and engagement, but missing key GA4 reports like events, conversions, and user demographics, limiting agent capabilities.
Maintenance
Related MCP Connectors
GA4, Google Ads and Search Console in Claude. Read-only OAuth, multi-account for agencies.
Connect Google Analytics to ChatGPT. Query GA4 data in plain English and get instant insights.
Read-only Google Ads, GA4 and Search Console data for Claude, with no Google Cloud setup.
GA4 conversion analyst inside Claude — funnel drops, traffic anomalies, device gaps, with numbers.
Related MCP Servers
- AlicenseAqualityBmaintenanceConnects Google Analytics 4 data to Claude, Cursor and other MCP clients, enabling natural language queries of website traffic, user behavior, and analytics data with access to 200+ GA4 dimensions and metrics.122,370 PyPI244MIT
- AlicenseAqualityCmaintenanceConnects MCP clients like Claude Desktop to Google Analytics 4 Data API, enabling natural language queries for reports, top pages, traffic sources, conversions, realtime users, and period comparisons.764 PyPIMIT
- FlicenseNot gradedqualityDmaintenanceEnables interactive Google Analytics 4 visualizations inside Claude conversations, supporting ad-hoc queries with line, bar, pie charts and data tables.-
- FlicenseAqualityDmaintenanceEnables natural language querying of Google Analytics 4, Google Search Console, Meta Ads, and Google Ads data through Claude.23-