GA4 MCP Server
Provides tools for querying Google Analytics 4 data, including traffic summary, top pages, traffic sources, and user engagement metrics.
Click on "Install 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 ServerWhat'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
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of top pages to return (default 10) | |
| endDate | Yes | End date in YYYY-MM-DD format | |
| startDate | Yes | Start date in YYYY-MM-DD format | |
| propertyId | Yes | GA4 Property ID |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, and the description only states basic functionality without disclosing behavior like pagination, sorting, or error handling. Minimal transparency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Single clear sentence with no wasted words. Appropriate length for the tool's simplicity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given low complexity and full schema coverage, the description is adequate but missing usage guidance. Completeness is average.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so baseline is 3. The description adds no additional parameter meaning beyond what the schema provides.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool retrieves top pages by views for a date range, using a specific verb and resource. It differentiates from siblings like get_traffic_sources or get_user_engagement.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance on when to use this tool versus siblings, no exclusions or prerequisites mentioned. The description lacks any usage context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_traffic_sourcesB
Get traffic breakdown by source (organic, direct, referral, etc.)
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | End date in YYYY-MM-DD format | |
| startDate | Yes | Start date in YYYY-MM-DD format | |
| propertyId | Yes | GA4 Property ID |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden. It indicates a read operation (getting data) but discloses no behavioral traits such as whether data is aggregated, paginated, or time-bounded beyond the date range. No side effects or permissions are mentioned.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence that conveys the core purpose without any fluff. Every word is necessary and earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the lack of output schema and annotations, the description is minimal. It covers the basic purpose but does not provide enough context for an agent to understand the response format, pagination, or any limitations. For a simple list tool, it is adequate but not comprehensive.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema has 100% coverage with descriptions for all three parameters (propertyId, startDate, endDate). The tool description adds no additional semantic meaning beyond what the schema already provides, so baseline 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'Get' and the resource 'traffic breakdown by source', listing examples like organic, direct, referral. However, it does not distinguish this tool from its sibling 'get_traffic_summary', which might have overlapping functionality.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus alternatives like 'get_traffic_summary' or 'get_top_pages'. The description merely states what it does without context or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_traffic_summaryA
Get overall traffic summary for a date range (sessions, users, page views, bounce rate, avg session duration)
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | End date in YYYY-MM-DD format | |
| startDate | Yes | Start date in YYYY-MM-DD format | |
| propertyId | Yes | GA4 Property ID (e.g., 544866887) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, so description must convey behavioral traits. It does not disclose whether the operation is read-only, permission requirements, rate limits, or data freshness. The term 'Get' implies non-destructive, but without explicit statement, the agent lacks confidence about side effects.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Single sentence that efficiently conveys the tool's purpose and key deliverables. No extraneous information, front-loaded with the main action and resource.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
No output schema is provided, so the description should elaborate on return format or pagination. It lists metrics but not their units or aggregation level. Additionally, lacks context on date range behavior (e.g., inclusive/exclusive). Adequate for basic understanding but incomplete for advanced usage.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100% with clear parameter descriptions (dates in YYYY-MM-DD, property ID as string). The description does not add additional semantic context beyond what the schema already provides, so a baseline score of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Description clearly identifies the verb 'Get' and the resource 'overall traffic summary', listing specific metrics (sessions, users, page views, bounce rate, avg session duration). It distinguishes from sibling tools like get_top_pages which focus on specific dimensions.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No explicit guidance on when to use this tool versus alternatives. While the purpose implies it's for high-level overview, there is no mention of prerequisites, constraints, or when not to use it, such as for detailed per-page analysis.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_user_engagementC
Get user engagement metrics (engaged sessions, bounce rate, avg session duration, screens per session)
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | End date in YYYY-MM-DD format | |
| startDate | Yes | Start date in YYYY-MM-DD format | |
| propertyId | Yes | GA4 Property ID |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, and description lacks behavioral details such as read-only nature, authentication requirements, data aggregation granularity, or rate limits. The description gives no insight into tool behavior beyond returning a list of metrics.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Description is short and front-loaded with the purpose. It is efficient but could be slightly more structured with a use-case statement.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no output schema or annotations, the description should provide more context about the nature of the metrics, possible date ranges, data freshness, or typical use cases. Currently insufficient for a comprehensive understanding.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema provides full 100% coverage for all three parameters with clear descriptions (dates format, property ID). Description adds no additional semantic value beyond confirming what the tool returns.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Description clearly states verb 'get' and resource 'user engagement metrics' with specific metrics listed (engaged sessions, bounce rate, etc.). However, it does not differentiate from siblings like get_traffic_sources which also return metrics.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance on when to use this tool versus alternatives (e.g., get_traffic_summary). No context on prerequisites, property setup, or metric interpretations.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
4 tool updates
v1.0.0- First observed
get_top_pages - First observed
get_traffic_sources - First observed
get_traffic_summary - First observed
get_user_engagement
TDQS
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
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Connect Google Analytics to ChatGPT. Query GA4 data in plain English and get instant insights.
GA4 conversion analyst inside Claude — funnel drops, traffic anomalies, device gaps, with numbers.
Ask Claude about your ads: Meta, Google, TikTok, LinkedIn, GA4 & Shopify. No AI credits.
SEO & marketing toolkit for AI agents: GA4, Search Console, AdSense, GTM, PageSpeed, Trends.
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.10240MIT
- AlicenseAqualityDmaintenanceEnables Claude to retrieve and analyze Google Analytics 4 data through 20+ analysis tools, providing insights on traffic, user behavior, conversions, and engagement metrics in Japanese-formatted output.202MIT
- AlicenseNot gradedqualityNot gradedmaintenanceConnects Claude AI to Google Search Console with OAuth 2.0 authentication, enabling users to analyze search performance, inspect URLs, manage sitemaps, and export analytics data through natural language conversations.2-
- AlicenseAqualityBmaintenanceConnects 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.7MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/aarcheco/ga4-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server