MCP Server for Google Analytics 4
HosakaKeigo
README
MCP Server for Google Analytics 4
[!NOTE] This is a work in progress. The server is not yet fully tested. Use at your own discretion.
Key Features
This server provides the following MCP functionalities:
Tools
get-page-views
: Fetches page view metrics for a specified date range.get-active-users
: Fetches active user metrics for a specified date range.get-events
: Fetches event metrics for a specified date range.get-user-behavior
: Fetches user behavior metrics such as session duration and bounce rate.
Resources
ga4://property-info
: Metadata for the GA4 property including available dimensions, metrics and comparisons.
The followings are more lightweight resources.
ga4://dimensions
: List of available GA4 dimensions.ga4://filters-help
: Help documentation on using GA4 filters.ga4://metrics
: List of available GA4 metrics.
Prompts
analyze-data
: Data analysis assistant.create-report
: Report generation template.select-dimensions
: Assists in selecting appropriate dimensions for analysis goals.
Setup
Prerequisites
- A Google Analytics 4 property.
- A Google Cloud service account with access to the GA4 API.
- Node.js 20 or higher.
- pnpm package manager.
Installation
# Clone the repository
git clone https://github.com/yourusername/mcp-server-ga4.git
cd mcp-server-ga4
# Install dependencies using pnpm
pnpm install
# Create the .env file
cp .env.example .env
# Edit the .env file and set your credentials
# GOOGLE_CLIENT_EMAIL=your-service-account-email@example.iam.gserviceaccount.com
# GOOGLE_PRIVATE_KEY=your-private-key
# GA_PROPERTY_ID=your-ga4-property-id
Auth
If GOOGLE_CLIENT_EMAIL
and GOOGLE_PRIVATE_KEY
are set, the server will authenticate with the service account. If not, it will use the default credentials.
Make sure your project enables the Google Analytics API and that your service account has the necessary permissions.(https://www.googleapis.com/auth/analytics.readonly
)
Here's how to set up Google Application Default Credentials:
- Install the Google Cloud SDK.
- Run the following command to authenticate:
gcloud auth application-default login --scopes=openid,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly
# If you want to set a quota project
gcloud auth application-default set-quota-project <my-quota-project>
Build and Run
# Build the server
pnpm run build
# Run the server
pnpm start
Usage
Integration with Claude for Desktop
Add the following to your claude_desktop_config.json
file:
{
"mcpServers": {
"ga4": {
"command": "node",
"args": ["/path/to/mcp-server-ga4/dist/index.js"],
"env": {
"GOOGLE_PROJECT_ID": "your-project-id",
"GOOGLE_CLIENT_EMAIL": "your-service-account-email@example.iam.gserviceaccount.com",
"GOOGLE_PRIVATE_KEY": "your-private-key",
"GA_PROPERTY_ID": "your-ga4-property-id"
}
}
}
}
If you want to use the default credentials, set GOOGLE_APPLICATION_CREDENTIALS
in your environment:
{
"mcpServers": {
"ga4": {
"command": "node",
"args": ["/path/to/mcp-server-ga4/dist/index.js"],
"env": {
"GOOGLE_PROJECT_ID": "your-project-id",
"GA_PROPERTY_ID": "your-ga4-property-id",
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/credentials.json"
}
}
}
}
Filtering
You can use the filter
parameter with all tools to narrow down results:
{
"dimension": [
{
"name": "pagePath",
"stringEquals": "/blog/article-1"
}
],
"metric": [
{
"name": "screenPageViews",
"greaterThan": 100
}
],
"operator": "AND"
}
Pagination
When dealing with large amounts of data, use the limit
and offset
parameters:
// First page (items 1-50)
get-page-views with limit=50, offset=0
// Second page (items 51-100)
get-page-views with limit=50, offset=50
Troubleshooting
- Authentication errors: Check your service account key and permissions.
- No data showing: Verify the date range and property ID are correct.
- Connection errors: Check your network settings and firewall.
Testing
Test using the MCP Inspector:
pnpm dlx @modelcontextprotocol/inspector node /path/to/mcp-server-ga4/dist/index.js
(Note: pnpm dlx
is the equivalent of npx
for executing packages)
License
MIT
Thanks
- https://github.com/lapras-inc/lapras-mcp-server/tree/main
- Owes to a class based structure of mcp implementation.
- https://github.com/ruchernchong/mcp-server-google-analytics
- Relies on basic implementation of Google Analytics API.
Recommended Servers
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.

Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Mathematica Documentation MCP server
A server that provides access to Mathematica documentation through FastMCP, enabling users to retrieve function documentation and list package symbols from Wolfram Mathematica.
kb-mcp-server
An MCP server aimed to be portable, local, easy and convenient to support semantic/graph based retrieval of txtai "all in one" embeddings database. Any txtai embeddings db in tar.gz form can be loaded
Research MCP Server
The server functions as an MCP server to interact with Notion for retrieving and creating survey data, integrating with the Claude Desktop Client for conducting and reviewing surveys.