What is GA4 - Google Analytics MCP Server?
GA4 - Google Analytics MCP Server is a standalone server that exposes Google Analytics 4's reporting capabilities through the standardized Model Context Protocol. It acts as a secure bridge between your GA4 property and any MCP-compatible AI tools, enabling fast analytics lookup, reporting, and integration into AI workflows through pre-defined functions.
How to Configure
-
Google Setup
- Enable the Google Analytics Data API in your Google Cloud project.
- Create a Service Account in "IAM & Admin > Service Accounts" and generate a JSON credentials key.
- Grant the Service Account "Viewer" access to your GA4 property in Google Analytics.
-
Server Environment
- Configure environment variables:
GOOGLE_CLIENT_EMAIL
: Service account email from the credential JSONGOOGLE_PRIVATE_KEY
: Service account private key from the credential JSONGA_PROPERTY_ID
: Your GA4 Property ID
- Configure environment variables:
-
Installation
- Install globally:
npm install -g mcp-server-google-analytics
- Or use with npx:
npx mcp-server-google-analytics
- Or install via Smithery for Claude Desktop integration.
- Install globally:
-
Configuration for AI Tools (e.g., Claude Desktop)
- Add the appropriate command and environment variables to your tool’s configuration under MCP servers.
How to Use
-
Start the Server
- Run
pnpm start
,npx mcp-server-google-analytics
, or launch from your tool integration.
- Run
-
Call Functions/Tools
- AI tools or LLM agents can invoke functions such as
runReport
,getPageViews
,getActiveUsers
,getEvents
, orgetUserBehavior
via the MCP interface. - Pass the required fields (e.g., date ranges, dimensions, metrics) as function arguments.
- AI tools or LLM agents can invoke functions such as
-
Example: Querying Page Views
- Use the
getPageViews
tool by providing a date range and optional dimensions to get page view metrics.
- Use the
-
Integration
- Incorporate the server with any AI client or automation system that supports MCP for dynamic analytics access.
Key Features
- Access to real-time GA4 analytics data via standard MCP function calls.
- Customizable reporting: Choose specific metrics, dimensions, filters, and periods.
- Multiple pre-defined tools: Page views, user metrics, event metrics, and behavior analysis.
- Secure service account authentication, with minimal permissions needed.
- Easy installation and configuration for both standalone and integrated use (e.g., in Claude Desktop).
- Designed to be extensible for future analytics needs.
Use Cases
- Integrate GA4 metrics directly into AI-driven dashboards, reporting tools, or assistant workflows.
- Enable chatbots or AI agents to answer questions about website/app usage, traffic trends, or user engagement.
- Automate the generation of analytics summaries, cohort analysis, or event-based reports.
- Monitor campaign performance and user behavior in real-time from within AI-enabled products.
FAQ
Q1: What GA4 permissions are required for the service account?
A: The service account only needs "Viewer" access to the target GA4 property, which allows read-only access to analytics data.
Q2: Is my private key secure during operation?
A: Yes, your private key and credentials are kept only in server-side environment variables; never expose keys to the client or public repositories.
Q3: Can I use this with any AI tool or workflow?
A: Yes, as long as the tool supports MCP integration, you can connect the server and access analytics functions.
Q4: What happens if my credentials are invalid or not set up properly?
A: The server will fail to authenticate with Google Analytics, and function calls will return errors indicating credential issues; ensure you follow setup instructions closely.
Q5: Is it possible to extend or customize the available tools?
A: Yes, the project is open-source, and you can contribute or adapt the server to support additional GA4 queries or custom reporting logic.