
Ga4
io.github.mharnettPublished by GitHub account mharnettv2.0.1Updated Oct 24, 2026
Google Analytics 4 MCP: reports, realtime data, custom dimensions, data streams.
Overview
A local MCP server that lets an assistant query Google Analytics 4 properties: run reports, read realtime data, and inspect or create custom dimensions and data
- What you can do
- Run standard GA4 reports with chosen dimensions, metrics, date ranges and filters, including relative dates such as 7daysAgo or 30daysAgo, and query realtime data for the last 30 minutes. List custom dimensions and custom metrics for the property, and create a new custom dimension. List web and app data streams with their measurement IDs. Report the active property ID and client name, and send feedback or improvement suggestions on query results.
- When to use it
- Useful when you want an assistant to pull GA4 traffic, page, campaign or device figures and summarize them in conversation, or to check realtime activity and property configuration without opening the Analytics interface.
- Requirements
- Runs locally via npm (npx mcp-ga4 or a global install) and needs Node.js. Requires GA4_PROPERTY_ID and one credential family: a service-account keyfile path in GOOGLE_APPLICATION_CREDENTIALS, or the OAuth trio GA4_CLIENT_ID, GA4_CLIENT_SECRET and GA4_REFRESH_TOKEN. The service account must be granted access on the GA4 property; OAuth needs a Google Cloud desktop client with the Analytics Data API enabled. Network access to Google APIs is required.
Installation
In SourceWeft
- Open Ga4 in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
mcp-ga4
MCP server for Google Analytics 4 -- run reports, realtime data, custom dimensions, and property management via Claude.
Features
- 9 tools covering reporting, realtime data, custom dimensions/metrics, data streams, and feedback
- Two configuration modes: single-property (env vars) and multi-client (config.json)
- Supports both service account and OAuth credentials
- Relative date support (today, yesterday, 7daysAgo, 30daysAgo, 90daysAgo)
- Built on official Google SDKs with resilience patterns
Quick start
-
Get credentials -- a service-account keyfile, or a user-OAuth refresh token (see Authentication).
-
Register the server with every Claude client on this machine:
The wizard detects Claude Desktop (
~/Library/Application Support/Claude/claude_desktop_config.jsonon macOS,%APPDATA%\Claude\claude_desktop_config.jsonon Windows) and the Claude Code CLI (claudeon PATH) and registersga4with each one it finds. Other servers and settings in the Desktop config are preserved; an invalid config file is left untouched and the wizard stops. Re-running is safe. Use--claude-desktop-onlyor--claude-code-onlyto target one client. -
Fully quit and reopen Claude Desktop (Cmd+Q), or restart your
claudesession.
Installation
Or clone the repository:
Authentication
mcp-ga4 supports two credential families. Selection is deterministic and
happens once, at startup: an explicit keyfile / service account wins, then
user OAuth, and if neither is configured the server exits with a loud
onboarding error naming both options. There is no machine-local credentials
path baked into the code and no silent runtime failover -- the only
credential inputs are environment variables and (optionally) your own per-user
config.json. (A later 403 therefore surfaces as the API error, not as a
silent switch to the other credential family.)
Precedence: when both families are configured, the keyfile / service account takes precedence over user OAuth.
Option A: Service account (recommended for unattended / server use)
Use this for any always-on or server deployment. Point
GOOGLE_APPLICATION_CREDENTIALS (or config.json credentials_file) at a JSON
keyfile. The service account must be granted access on the GA4 property
(Admin → Property Access Management → add the service-account email with at least
Viewer). No refresh token is involved -- the server hands the keyfile to the GA4
SDKs directly:
The keyfile may be a real service-account key or an authorized_user OAuth
token dump -- both are accepted via the keyFile option.
Option B: User OAuth (personal / interactive use)
Use this if you want the server to act as a Google user (your own GA4 login). You bring your own Google OAuth client and mint a refresh token once.
-
In Google Cloud Console, create an OAuth 2.0 Client ID of type Desktop app. Enable the Google Analytics Data API (and the Admin API if you use the custom-dimension tools).
-
Export your client credentials and run the token helper (uses PKCE, opens a browser, prints the token to stdout):
Do not redirect this command's stdout to a shared log -- the refresh token is printed there by design.
-
Copy the printed
GA4_REFRESH_TOKEN=...into your environment. At runtime the server reads these three env vars:
The scope requested is read from config.json oauth.scope (see below), so the
helper and the running server never disagree on what you granted.
Scopes (minimum grant)
Scopes live in config.json under oauth.scope. The committed default is:
analytics.edit is required because ga4_create_custom_dimension mutates the
property via the Admin API. If you only need read access, override oauth.scope
in your own config.json to analytics.readonly alone and re-run the helper.
Configuration
Security: Never share your .mcp.json file or commit it to git -- it may contain API credentials. Add .mcp.json to your .gitignore.
Mode 1: Single Property (env vars)
Set a property ID plus one of the auth families above:
Mode 2: Multi-Client (config.json)
Create a config.json in the project root to map multiple GA4 properties to
project directories. The server auto-detects which property to use based on the
caller's working directory. Credentials come from the environment (Option A/B
above); config.json may optionally carry a credentials_file service-account
path for a config-only SA setup.
Usage
Manual configuration
mcp-ga4-setup (see Quick start) writes this for you. To manage
the entry by hand, the single-property shape is:
Multi-client mode:
The same mcpServers shape is used by Claude Code project configs and by Claude Desktop's claude_desktop_config.json.
Common Query Patterns
Top pages:
dimensions=pagePath, metrics=screenPageViews, order_by=screenPageViews
Traffic sources:
dimensions=sessionSource,sessionMedium, metrics=sessions,totalUsers
Daily trend:
dimensions=date, metrics=sessions,totalUsers
Campaign performance:
dimensions=sessionCampaignName, metrics=sessions,conversions
Device breakdown:
dimensions=deviceCategory, metrics=sessions,totalUsers
Tools
Date Formats
Use YYYY-MM-DD for absolute dates, or these relative shortcuts:
todayyesterday7daysAgo30daysAgo90daysAgo
Common Dimensions and Metrics
Dimensions: date, dateHour, eventName, pagePath, pageTitle, sessionSource, sessionMedium, sessionCampaignName, country, city, deviceCategory, browser, operatingSystem, landingPage, pageReferrer, newVsReturning, firstUserSource, firstUserMedium, firstUserCampaignName
Metrics: sessions, totalUsers, newUsers, activeUsers, screenPageViews, eventCount, conversions, engagedSessions, engagementRate, averageSessionDuration, bounceRate, sessionsPerUser, screenPageViewsPerSession, userEngagementDuration
Data Freshness
- Standard reports: 24-48 hour delay
- Realtime reports: last 30 minutes only
Architecture
Built on:
@google-analytics/data-- GA4 Data API for reports@google-analytics/admin-- GA4 Admin API for property managementcockatiel-- resilience (retry, circuit breaker)pino-- structured logging
License
MIT
Author
Built by Mark Harnett / drak-marketing
Source: README.md at commit e44f8b0
Tools
0Version history
1- v2.0.1LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts