Google Analytics MCP Server: AI-Powered Analytics for GA4
Google Analytics MCP server enables AI models to interact with Google Analytics 4 for reports, user behavior analysis, event tracking, and real-time data access.
Overview
The Google Analytics MCP Server bridges AI models and analytics by enabling language models to interact directly with Google Analytics 4 data. It's part of the Model Context Protocol (MCP) ecosystem, providing secure, read-only access to your analytics data for natural language queries and AI-powered insights.
Official Server:
Developed and maintained by Google Analytics
Key Features
Comprehensive Reporting
Execute custom reports with flexible dimensions, metrics, and date ranges
Real-Time Analytics
Access live user activity and events as they happen on your site
Secure Read-Only Access
Safe data exploration without risk of modifying your analytics configuration
Natural Language Queries
Ask questions about your data in plain English and get instant insights
Available Tools
Quick Reference
| Tool | Purpose | Category |
|---|---|---|
get_account_summaries | List GA accounts and properties | Account |
get_property_details | Get property configuration | Account |
list_google_ads_links | List linked Google Ads accounts | Integration |
run_report | Execute custom analytics reports | Reporting |
get_custom_dimensions_and_metrics | List custom fields | Schema |
run_realtime_report | Get real-time analytics data | Reporting |
Detailed Usage
get_account_summaries�
Retrieves information about your Google Analytics accounts and properties, including property IDs and display names.
use_mcp_tool({
server_name: "google-analytics",
tool_name: "get_account_summaries",
arguments: {}
});
Use this to discover available properties before running reports.
get_property_details�
Returns detailed configuration information for a specific Google Analytics property.
use_mcp_tool({
server_name: "google-analytics",
tool_name: "get_property_details",
arguments: {
property_name: "properties/123456789"
}
});
Get timezone, currency, industry category, and other property settings.
run_report�
Execute custom analytics reports with flexible dimensions, metrics, date ranges, and filters.
// Get user and session metrics by country
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_report",
arguments: {
property_id: "123456789",
date_ranges: [{
start_date: "7daysAgo",
end_date: "today"
}],
dimensions: [{ name: "country" }],
metrics: [
{ name: "activeUsers" },
{ name: "sessions" }
],
order_bys: [{
metric: { metric_name: "activeUsers" },
desc: true
}],
limit: 10
}
});
Supports 200+ dimensions and metrics for comprehensive analysis.
run_realtime_report�
Access real-time analytics data showing current user activity on your site.
// Get current active users by page
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_realtime_report",
arguments: {
property_id: "123456789",
dimensions: [{ name: "unifiedScreenName" }],
metrics: [{ name: "activeUsers" }],
limit: 10
}
});
Data reflects activity from the last 30 minutes.
get_custom_dimensions_and_metrics�
Retrieves all custom dimensions and metrics configured for your property.
use_mcp_tool({
server_name: "google-analytics",
tool_name: "get_custom_dimensions_and_metrics",
arguments: {
property_name: "properties/123456789"
}
});
Discover custom fields for use in reports.
list_google_ads_links�
Lists all Google Ads accounts linked to your Analytics property.
use_mcp_tool({
server_name: "google-analytics",
tool_name: "list_google_ads_links",
arguments: {
property_name: "properties/123456789"
}
});
View advertising integrations for cross-platform analysis.
Installation
Prerequisites
Before installing, you need to:
-
Enable required APIs in your Google Cloud Console:
- Google Analytics Admin API
- Google Analytics Data API
-
Set up Application Default Credentials with the Analytics scope:
gcloud auth application-default login \ --scopes=https://www.googleapis.com/auth/analytics.readonly -
Set environment variables:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json" export GOOGLE_PROJECT_ID="your-project-id"
Install with pipx
pipx install google-analytics-mcp
Configuration
Add to your MCP settings file (e.g., ~/.gemini/settings.json or Claude Desktop config):
{
"mcpServers": {
"google-analytics": {
"command": "pipx",
"args": ["run", "google-analytics-mcp"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/credentials.json",
"GOOGLE_PROJECT_ID": "your-project-id"
}
}
}
}
Common Use Cases
1. Traffic Analysis
Get insights about website traffic and user behavior:
// Find top pages by users in the last 7 days
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_report",
arguments: {
property_id: "123456789",
date_ranges: [{ start_date: "7daysAgo", end_date: "today" }],
dimensions: [{ name: "pagePath" }, { name: "pageTitle" }],
metrics: [
{ name: "activeUsers" },
{ name: "screenPageViews" }
],
order_bys: [{ metric: { metric_name: "activeUsers" }, desc: true }],
limit: 20
}
});
2. User Acquisition Sources
Understand where your traffic is coming from:
// Analyze traffic sources and conversion rates
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_report",
arguments: {
property_id: "123456789",
date_ranges: [{ start_date: "30daysAgo", end_date: "today" }],
dimensions: [
{ name: "sessionSource" },
{ name: "sessionMedium" }
],
metrics: [
{ name: "sessions" },
{ name: "conversions" },
{ name: "engagementRate" }
],
order_bys: [{ metric: { metric_name: "sessions" }, desc: true }]
}
});
3. Event Tracking
Monitor specific user interactions and events:
// Get most popular events
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_report",
arguments: {
property_id: "123456789",
date_ranges: [{ start_date: "7daysAgo", end_date: "today" }],
dimensions: [{ name: "eventName" }],
metrics: [
{ name: "eventCount" },
{ name: "eventCountPerUser" }
],
order_bys: [{ metric: { metric_name: "eventCount" }, desc: true }],
limit: 25
}
});
4. Real-Time Monitoring
Watch current activity on your site:
// Monitor active users by device
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_realtime_report",
arguments: {
property_id: "123456789",
dimensions: [{ name: "deviceCategory" }],
metrics: [{ name: "activeUsers" }]
}
});
5. Geographic Analysis
See where your users are located:
// Users by country and city
use_mcp_tool({
server_name: "google-analytics",
tool_name: "run_report",
arguments: {
property_id: "123456789",
date_ranges: [{ start_date: "30daysAgo", end_date: "today" }],
dimensions: [
{ name: "country" },
{ name: "city" }
],
metrics: [
{ name: "activeUsers" },
{ name: "averageSessionDuration" }
],
order_bys: [{ metric: { metric_name: "activeUsers" }, desc: true }],
limit: 50
}
});
Authentication Setup
Step 1: Create Service Account
- Go to Google Cloud Console
- Create or select a project
- Navigate to IAM & Admin > Service Accounts
- Click Create Service Account
- Add name and description, click Create
- Grant Viewer role, click Continue
- Click Done
Step 2: Create Key
- Click on the service account you created
- Go to Keys tab
- Click Add Key > Create new key
- Select JSON format
- Click Create (the key file will download automatically)
Step 3: Grant Analytics Access
- Go to Google Analytics
- Navigate to Admin (gear icon)
- Under Account or Property, click Account Access Management or Property Access Management
- Click + button to add users
- Enter your service account email (looks like
[email protected]) - Assign Viewer role
- Click Add
Step 4: Enable APIs
- In Google Cloud Console, navigate to APIs & Services > Library
- Search for and enable:
- Google Analytics Admin API
- Google Analytics Data API (GA4)
Example Natural Language Queries
Once configured, you can ask questions like:
- "What were my top 10 pages by users yesterday?"
- "Show me real-time active users by device"
- "Which traffic sources drove the most conversions last month?"
- "What are my most popular events this week?"
- "Compare user engagement between mobile and desktop users"
Sources
Related Articles
Supavec MCP Server: Vector Database for AI Applications
Supavec MCP servers enable AI models to interact with vector databases, providing capabilities for storing, searching, and managing vector embeddings for AI applications.
ArangoDB MCP Server
ArangoDB MCP servers enable AI models to interact with ArangoDB databases, providing capabilities for document operations, graph queries, AQL queries, and multi-model data management.
MongoDB MCP Server
MongoDB MCP servers enable AI models to interact with MongoDB databases and MongoDB Atlas, providing capabilities for document operations, aggregation pipelines, cloud database management, and natural language queries.