Content
# Google Analytics Data API MCP Server
Provides an interface to access the Google Analytics Data API using the Model Context Protocol (MCP) server.
## Features
This MCP server offers tools and resources to access the main functionalities of the Google Analytics Data API:
### Tools
- **get_report**: Retrieves reports based on the specified date range, metrics, and dimensions.
- **get_realtime_data**: Retrieves real-time data.
### Resources
- **ga4://property/{propertyId}/metadata**: Accesses metadata for Google Analytics properties.
## Setup
### Prerequisites
1. Create a Google Cloud project and enable the Analytics Data API.
2. Create a service account and download the credentials JSON file.
3. Grant the service account appropriate access to the GA4 property.
For detailed setup instructions, please refer to the [Setup Guide](docs/setup-guide.md).
### Installation
```bash
# Clone the repository
git clone https://github.com/eno-graph/mcp-server-google-analytics.git
cd mcp-server-google-analytics
# Install dependencies
npm install
# Build
npm run build
```
### Setting Environment Variables
You need to set the following environment variables:
```bash
export GOOGLE_CLIENT_EMAIL="your-service-account@project.iam.gserviceaccount.com"
export GOOGLE_PRIVATE_KEY="your-private-key"
export GA_PROPERTY_ID="your-ga4-property-id"
```
## Usage
### Starting the Server
```bash
npm start
```
Alternatively, you can use the provided script:
```bash
./run-server.sh
```
### Configuration in Claude Desktop
Add the following to the configuration file of Claude Desktop:
```json
{
"mcpServers": {
"google-analytics": {
"command": "node",
"args": ["/path/to/mcp-server-google-analytics/build/index.js"],
"env": {
"GOOGLE_CLIENT_EMAIL": "your-service-account@project.iam.gserviceaccount.com",
"GOOGLE_PRIVATE_KEY": "your-private-key",
"GA_PROPERTY_ID": "your-ga4-property-id"
}
}
}
}
```
For detailed configuration examples, please refer to [claude-desktop-config-sample.json](claude-desktop-config-sample.json).
## Example Usage of Tools
### Retrieving Reports
```
Use the get_report tool to retrieve the number of active users and page views for the past 7 days.
Arguments:
{
"startDate": "7daysAgo",
"endDate": "today",
"metrics": ["activeUsers", "screenPageViews"],
"dimensions": ["date"],
"limit": 10
}
```
### Retrieving Real-Time Data
```
Use the get_realtime_data tool to retrieve the current number of active users.
Arguments:
{
"metrics": ["activeUsers"],
"dimensions": ["deviceCategory"],
"limit": 10
}
```
## Example Usage of Resources
```
Access the ga4://property/123456789/metadata resource to check the available metrics and dimensions.
```
## Usage Examples
For usage examples in Claude, please refer to [Claude Usage Examples](examples/claude-usage-examples.md).
## License
MIT
Connection Info
You Might Also Like
MarkItDown MCP
Converting files and office documents to Markdown.
Filesystem
Model Context Protocol Servers
Sequential Thinking
Offers a structured approach to dynamic and reflective problem-solving,...
TrendRadar
🎯 Say goodbye to information overload. AI helps you understand news hotspots...
Github
GitHub's official MCP Server
opik
Debug, evaluate, and monitor your LLM applications, RAG systems, and agentic...