Access Google Analytics 4 data with a customizable MCP server for metrics on user behavior and page views
The Google Analytics MCP Server, part of the Model Context Protocol (MCP) ecosystem, is a robust implementation designed to enable AI applications such as Claude Desktop, Continue, Cursor, and others to seamlessly access Google Analytics 4 (GA4) data through the standardized MCP protocol. This server leverages the Model Context Protocol TypeScript SDK to provide a flexible framework for extracting valuable insights from GA4 metrics, including page views, user behavior, and specific event tracking.
The Google Analytics MCP Server offers several key features that enhance AI application functionalities by integrating data directly into their workflows:
Get Page View Metrics with Customizable Dimensions: Users can fetch detailed insights such as page views, broken down by various dimensions like page
, country
, and more.
Track Active and New Users Over Time: Monitor the growth or decline of active users within a defined date range, helping to understand user engagement over time.
Analyze Specific Events and Their Metrics: Detailed event tracking is supported for specific actions within your application or website, enabling fine-grained analysis of user interactions.
Monitor User Behavior Metrics: Real-time insights into session duration, bounce rates, and other critical metrics that guide strategic decision-making.
Flexible Date Range Selection for All Queries: Easily specify custom date ranges to explore historical data with precision, facilitating trend analysis and reporting.
The protocol flow diagram illustrates the communication path between an AI application (MCP Client) and the Google Analytics MCP Server, showcasing how data is seamlessly transmitted from the server to the tool provider for further processing. This architecture ensures that all interactions are standardized, making it easier to integrate various AI tools with a range of backend services.
graph TB
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server Google Analytics]
C --> D[GA4 Data Source]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
The configuration in Claude Desktop is straightforward, allowing seamless setup without manual coding. Users can add the MCP server to their configurations by specifying the command and environment variables required.
To install Google Analytics Server for Claude Desktop automatically through Smithery:
npx -y @smithery/cli install mcp-server-google-analytics --client claude
Alternatively, users can install it manually using pnpm
:
pnpm install mcp-server-google-analytics
In an e-commerce platform, real-time user behavior analysis is crucial for enhancing the shopping experience and personalizing product recommendations. By integrating Google Analytics MCP Server into the application, developers can quickly set up metrics such as session duration and bounce rates, providing insights that help refine recommendation algorithms.
# Example of a Python snippet to fetch session duration data from MCP Server
response = get_user_behavior({
"startDate": "2024-05-16",
"endDate": "2024-05-31"
})
print(response.json())
For marketing teams managing email campaigns, Google Analytics MCP Server enables the tracking of specific events (e.g., button clicks, form submissions) to automate marketing actions based on user behavior. This integration allows for real-time decision-making and personalized customer experiences.
{
"startDate": "2024-06-01",
"endDate": "2024-06-30",
"eventName": "purchase"
}
The Google Analytics MCP Server is designed to be fully compatible with the following MCP clients:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
Users can deploy the Google Analytics MCP Server on various platforms, including local servers and cloud environments like AWS or Google Cloud. The following table summarizes its compatibility:
Platform | Node.js 20+ | Python 3.7+ |
---|---|---|
Local Deployment | ✅ | ✅ |
Cloud AWS | ✅ | ✅ |
Hosting GCP | ✅ |
Security is a critical aspect of any data-driven application. The server adheres to strict security practices, including the use of environment variables for sensitive credentials and appropriate CORS settings.
Environment Variables: Always set environment variables using export
.
export GOOGLE_CLIENT_EMAIL="[email protected]"
export GOOGLE_PRIVATE_KEY="your-private-key"
export GA_PROPERTY_ID="your-ga4-property-id"
CORS Settings: Proper CORS configuration is essential to ensure only authorized clients can interact with the server.
Least Privilege Principle: Service accounts are granted access based on a need-to-know basis, minimizing potential risks.
Rotation of Credentials: Regularly updating service account credentials ensures ongoing security and compliance.
How do I setup Google Analytics MCP Server with Claira Desktop?
What are the supported date formats for query parameters?
Can I integrate Google Analytics MCP Server with multiple API clients at once?
How often should I rotate the service account credentials?
What metrics are supported by the Google Analytics MCP Server?
Contributions to the project are encouraged. To contribute, please follow our Contribution Guide which outlines our code of conduct and details on how to submit pull requests.
Explore more about the Model Context Protocol ecosystem through these resources:
By leveraging the Google Analytics MCP Server, developers can seamlessly integrate data insights into their AI applications, enhancing user experiences and operational efficiency.
Analyze search intent with MCP API for SEO insights and keyword categorization
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Connect your AI with your Bee data for seamless conversations facts and reminders
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions
Expose Chicago Public Schools data with a local MCP server accessing SQLite and LanceDB databases