ai-referral-analysis
How to track and measure traffic from ChatGPT, Claude, Perplexity, and Gemini in GA4. Exact dimension filters, regex patterns,…
Step-by-step GA4 service account setup. Generate Google Cloud JSON keys, enable the Data API, and grant Viewer permissions in Google Analytics Admin.
Claude Code
$ npx -y skills add surendranb/google-analytics-mcp --skill service-account-setup --agent claude-code
Codex
$ npx skills add surendranb/google-analytics-mcp --skill service-account-setup -a codex -y
Cursor
$ npx skills add surendranb/google-analytics-mcp --skill service-account-setup -a cursor -y
Gemini CLI
$ npx skills add surendranb/google-analytics-mcp --skill service-account-setup -a gemini-cli -y
GitHub Copilot
$ npx skills add surendranb/google-analytics-mcp --skill service-account-setup -a github-copilot -y
OpenCode
$ npx skills add surendranb/google-analytics-mcp --skill service-account-setup -a opencode -y
Windsurf
$ npx skills add surendranb/google-analytics-mcp --skill service-account-setup -a windsurf -y
name: service-account-setup titleTag: "GA4 Service Account Setup: JSON Key & IAM Guide" description: "Step-by-step GA4 service account setup. Generate Google Cloud JSON keys, enable the Data API, and grant Viewer permissions in Google Analytics Admin."
Step-by-step playbook to authenticate the GA4 MCP server using a Google Cloud Platform (GCP) Service Account.
This is the standard, enterprise-grade authentication method:
---
If you have the `gcloud` CLI installed, run these 4 commands in your terminal:
# 1. Set your target GCP Project ID
export GCP_PROJECT_ID="$(gcloud config get-value project)"
# 2. Enable the Google Analytics Data API v1beta
gcloud services enable analyticsdata.googleapis.com --project="$GCP_PROJECT_ID"
# 3. Create a dedicated Service Account for the MCP server
gcloud iam service-accounts create ga4-mcp-reader \
--display-name="GA4 MCP Reader" \
--description="Read-only service account for GA4 Model Context Protocol" \
--project="$GCP_PROJECT_ID"
# 4. Generate and download the JSON key file
mkdir -p ~/.config/ga4-mcp
gcloud iam service-accounts keys create ~/.config/ga4-mcp/service-account.json \
--iam-account="ga4-mcp-reader@${GCP_PROJECT_ID}.iam.gserviceaccount.com" \
--project="$GCP_PROJECT_ID"Your service account email will be: `ga4-mcp-reader@<YOUR_PROJECT_ID>.iam.gserviceaccount.com`
---
If you do not have `gcloud` CLI installed:
1. **Open Google Cloud Console**: Go to [console.cloud.google.com](https://console.cloud.google.com) and create or select a project. 2. **Enable the API**: Navigate to **APIs & Services** > **Library**, search for **Google Analytics Data API**, and click **Enable**. 3. **Create Service Account**: Navigate to **IAM & Admin** > **Service Accounts**, click **+ Create Service Account**.
4. **Download JSON Key**: Click on the newly created service account > go to the **Keys** tab > click **Add Key** > **Create new key** > select **JSON** > click **Create**. Save the downloaded file to a permanent path, e.g.: `~/.config/ga4-mcp/service-account.json`
---
> ⚠️ **CRITICAL STEP**: The service account cannot read your analytics until you explicitly add its email as a Viewer in Google Analytics.
1. Open [analytics.google.com](https://analytics.google.com). 2. Click the gear icon (**Admin**) in the bottom-left corner. 3. Under the **Property** column, click **Property access management**. 4. Click the blue **+** button in the top-right corner and select **Add users**. 5. Enter the service account email (e.g. `ga4-mcp-reader@your-project.iam.gserviceaccount.com` or the `client_email` value inside your JSON key). 6. Under Standard roles, select **Viewer** (read-only). 7. Uncheck "Notify SDK users by email" and click **Add**.
---
GA4 requires the numeric **Property ID**, NOT the data stream Measurement ID:
**Where to find it**: 1. In Google Analytics, click **Admin** (gear icon). 2. Under Property, click **Property details**. 3. The numeric **Property ID** is displayed in the top right (e.g., `362847407`).
---
Update your client configuration file with the absolute path to your JSON key and your numeric Property ID.
File: `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows)
{
"mcpServers": {
"google-analytics": {
"command": "uvx",
"args": ["google-analytics-mcp"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/Users/YOUR_USER/.config/ga4-mcp/service-account.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}File: `~/.cursor/mcp.json` or `.cursor/mcp.json` in your workspace:
{
"mcpServers": {
"google-analytics": {
"command": "uvx",
"args": ["google-analytics-mcp"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/Users/YOUR_USER/.config/ga4-mcp/service-account.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}Run directly:
claude mcp add google-analytics -- uvx google-analytics-mcp -e GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json -e GA4_PROPERTY_ID=123456789
---
Run this one-liner in your terminal to verify end-to-end connectivity without restarting your IDE:
GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json" \ GA4_PROPERTY_ID="123456789" \ uvx google-analytics-mcp
**Expected output**:
Starting GA4 MCP server... Fetching schema for property '123456789'... Schema loaded successfully.
If you see `Schema loaded successfully`, your service account is 100% operational.
Model Context Protocol (MCP) server for Google Analytics 4: real-time query exploration, schema discovery, metric aggregation, and audience insights for AI agents. 🌐 Live Documentation & Web Portal:
How to track and measure traffic from ChatGPT, Claude, Perplexity, and Gemini in GA4. Exact dimension filters, regex patterns,…
Why session, user, and event metrics never match in GA4. Rules for pairing dimensions and metrics across user-scoped,…
Detect and filter automated bot spikes in Google Analytics 4. Patterns for datacenter ASN spikes, zero-second sessions, and…
How GA4 Default Channel Groups work, how to audit channel performance, and how to spot traffic falling into Unassigned or Direct…
Exact API field names for GA4 Data API queries. Avoid 400 errors from Universal Analytics names like ga:sessions or pageviews by…
Which dimensions and metrics can be queried together in GA4 without triggering incompatible scope errors. Matrix of user,…
Use this skill when the user requests to review, analyze, critique, or summarize academic papers, research articles, preprints,…
Research what people actually say about any topic in the last 30 days. Pulls posts and engagement from Reddit, X, YouTube,…
Estimates intracellular metabolic fluxes from steady-state carbon-13 isotope-tracing measurements using validated atom maps,…
Search literature across sources, verify or manage citations, and build MeSH strategies or citation-impact audits. Use for…