Skip to main content
Glama
aarcheco

GA4 MCP Server

by aarcheco

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 install

2. Set Up Credentials

  1. Copy the GA4 service account JSON file you downloaded to this folder:

    cp ~/Downloads/app-coaching-ga4-73c82846b5b0.json ./credentials.json
  2. Create a .env file:

    cp .env.example .env
  3. Update .env with your GA4 Property ID:

    GA4_CREDENTIALS_PATH=./credentials.json
    GA4_PROPERTY_ID=544866887

3. Add Service Account to GA4

In Google Analytics:

  1. Go to Admin → Property Access Management

  2. Click + (Add user)

  3. Paste: ga4-mcp-server@app-coaching-ga4.iam.gserviceaccount.com

  4. Assign Viewer role

  5. 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

Deployment Options

Option 1: Replit (Easiest)

  1. Create a new Replit

  2. Import from GitHub (clone this repo) or upload files

  3. Set environment variables in Replit Secrets:

    • GA4_CREDENTIALS_PATH=./credentials.json

  4. Upload credentials.json to Replit

  5. Run: npm install && npm run build && npm run dev

  6. Replit gives you a live URL

  7. Connect to Claude using that URL

Option 2: Railway

  1. Create a Railway project

  2. Upload this repo via GitHub

  3. Add credentials.json as a config file

  4. Set env var: GA4_CREDENTIALS_PATH=./credentials.json

  5. Deploy

  6. Get the URL from Railway

  7. 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.json is in the project root

  • Check GA4_CREDENTIALS_PATH env 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 implementation

  • package.json — Dependencies and scripts

  • tsconfig.json — TypeScript configuration

  • credentials.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 tools
get_top_pagesB

Get top pages by views for a date range

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of top pages to return (default 10)
endDateYesEnd date in YYYY-MM-DD format
startDateYesStart date in YYYY-MM-DD format
propertyIdYesGA4 Property ID

TDQS

B3.3/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters3/5

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.

Purpose5/5

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.

Usage Guidelines2/5

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.)

ParametersJSON Schema
NameRequiredDescriptionDefault
endDateYesEnd date in YYYY-MM-DD format
startDateYesStart date in YYYY-MM-DD format
propertyIdYesGA4 Property ID

TDQS

B3.1/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters3/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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)

ParametersJSON Schema
NameRequiredDescriptionDefault
endDateYesEnd date in YYYY-MM-DD format
startDateYesStart date in YYYY-MM-DD format
propertyIdYesGA4 Property ID (e.g., 544866887)

TDQS

A3.5/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters3/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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)

ParametersJSON Schema
NameRequiredDescriptionDefault
endDateYesEnd date in YYYY-MM-DD format
startDateYesStart date in YYYY-MM-DD format
propertyIdYesGA4 Property ID

TDQS

C2.9/5.0
Behavior2/5

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.

Conciseness4/5

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.

Completeness2/5

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.

Parameters3/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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.

  1. 4 tool updatesv1.0.0
    • First observedget_top_pages
    • First observedget_traffic_sources
    • First observedget_traffic_summary
    • First observedget_user_engagement

TDQS

A3.5/5.0
Disambiguation5/5

Each tool targets a distinct aspect of GA4: top pages, traffic sources, overall traffic summary, and user engagement. No overlapping purposes.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern ('get_<metric_group>'), making them predictable and easy to navigate.

Tool Count4/5

With 4 tools, the set is lean but covers core reporting needs. Slightly under-scoped for a full analytics server, but still reasonable.

Completeness3/5

Covers basic traffic, pages, sources, and engagement, but missing key GA4 reports like events, conversions, and user demographics, limiting agent capabilities.

Maintenance

ActivitySlowing
ResponsivenessSyncing

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

Related MCP Servers

  • A
    license
    A
    quality
    B
    maintenance
    Connects 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.
    10
    240
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Enables 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.
    20
    2
    MIT
  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Connects 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
    -
  • A
    license
    A
    quality
    B
    maintenance
    Connects 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.
    7
    MIT

Latest Blog Posts

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