# Google Analytics MCP

> Google Analytics connects your AI client directly to GA4 data streams. Run reports, analyze user funnels, and check real-time site activity using natural conversation. You query custom metrics like active users or screen page views across all properties without touching the web interface.

## Overview
- **Category:** industry-titans
- **Price:** Free
- **Tags:** web-analytics, user-behavior, conversion-tracking, real-time-data, funnel-analysis, audience-insights

## Description

Your AI client connects straight into your Google Analytics 4 data streams. You run reports, check user funnels, and see real-time site activity just by talking to it. It lets you query specific metrics—like active users or screen page views—across all your properties without ever touching the GA web interface.

To get started, you'll first need to know what data you're dealing with. You can use `list_accounts` to see every Google Analytics account associated with your login. Then, running `list_properties` gives you a list of all individual websites or apps—the properties—within those accounts, giving you the IDs you need to target. If you want specific configuration details for one property, call `get_property`. When you're ready to see what data fields are even available, run `get_metadata`; that lists every single metric and dimension your property tracks, including custom ones.

When it comes time to build reports, you don't have to build 'em manually. You can use `run_report` for a standard custom report by specifying metrics, dimensions, and the date range. If you need several different reports loaded up fast, `batch_run_reports` runs multiple distinct reports in one API call. Before running any big query, though, check your work with `check_compatibility`; this verifies that the specific metrics and dimensions you picked can actually be combined successfully into a single report. You also get immediate data on current site traffic by using `run_realtime_report`, which displays live analytics for users, events, and traffic sources over the last 30 to 60 minutes.

For deep user analysis, you've got two main options. To map out conversion paths and see exactly where people drop off—like during a checkout flow—you run `run_funnel_report`. If you want to track one specific person's journey, you can use `get_user_activity` to get the full history of interactions (pageviews, events) for just that user ID. You also monitor audience list generation using export tools; call `list_audience_exports` to see the current status—whether it’s CREATING or FAILED—for every audience export job run on a property, and use `get_audience_export` to track the progress of one specific job.

## Tools

### batch_run_reports
Runs multiple, different reports in a single API call for efficient dashboard loading.

### check_compatibility
Verifies if your chosen metrics and dimensions can be combined successfully in a report.

### get_audience_export
Monitors the status of an audience export job, allowing you to track user list generation progress.

### get_metadata
Lists all available metrics and dimensions for your property so you know what data is trackable.

### get_property
Retrieves detailed configuration information about a specific GA4 property.

### get_user_activity
Gets the full history of interactions (pageviews, events) for one specific user ID.

### list_accounts
Lists all Google Analytics accounts available to you, which contain multiple properties.

### list_audience_exports
Shows the current status (like CREATING or FAILED) for every audience export job run on a property.

### list_properties
Lists all individual websites or apps (properties) within an account, providing their necessary IDs.

### run_funnel_report
Analyzes the steps users take through a process to show where they abandon the flow.

### run_realtime_report
Displays live analytics data for traffic, events, and users over the last 30-60 minutes.

### run_report
Runs a standard custom report using specific metrics, dimensions, and date ranges.

## Prompt Examples

**Prompt:** 
```
Show me the number of active users and pageviews by country for the last 7 days for property 123456789.
```

**Response:** 
```
I've run the report for the last 7 days. Top countries by active users: United States — 45,230 active users, 189,450 pageviews; United Kingdom — 12,890 active users, 52,340 pageviews; Germany — 8,560 active users, 34,120 pageviews; Brazil — 6,780 active users, 28,900 pageviews; India — 5,420 active users, 21,560 pageviews. Total: 156,420 active users across 645,890 pageviews. Would you like a breakdown by device category or traffic source?
```

**Prompt:** 
```
What's happening on the site right now? Show me realtime users by traffic source.
```

**Response:** 
```
Realtime data (last 30 minutes): 847 active users right now. Top traffic sources: Organic Search — 412 users; Direct — 198 users; Social — 124 users; Paid Search — 78 users; Email — 35 users. Top pages being viewed: Homepage (/) — 234 users; Product page (/products/xyz) — 156 users; Checkout (/checkout) — 89 users. Engagement rate is 68% with average session duration of 2m 34s.
```

**Prompt:** 
```
Run a funnel analysis for our checkout flow: step 1 = viewed product, step 2 = added to cart, step 3 = started checkout, step 4 = completed purchase. Show me where users drop off.
```

**Response:** 
```
I've analyzed your checkout funnel. Here's the conversion flow:

1. **Viewed Product** — 12,450 users entered
2. **Added to Cart** — 4,980 users (40.0% conversion from step 1)
3. **Started Checkout** — 2,340 users (47.0% conversion from step 2)
4. **Completed Purchase** — 1,560 users (66.7% conversion from step 3)

**Overall funnel conversion rate: 12.5%** (1,560 out of 12,450)

**Biggest drop-off**: Between 'Viewed Product' and 'Added to Cart' — 60% of users leave here. This suggests product pages may need clearer CTAs, better pricing visibility, or faster load times.
```

## Capabilities

### Run Custom Reports
Execute detailed analytics reports by specifying metrics (e.g., sessions) and dimensions (e.g., country).

### Monitor Real-Time Activity
Get immediate data on current site traffic, including live user counts and top sources for the last hour.

### Analyze User Funnels
Map out conversion paths to identify specific steps in a process where users drop off (e.g., checkout flow).

### Inspect Property Scope
List all available properties and accounts, ensuring you run reports against the correct data source.

### Check Data Field Compatibility
Validate that your chosen metrics and dimensions work together before running a report to avoid API errors.

## Use Cases

### Investigating a Traffic Dip
A support team member notices a dip in traffic from 'Organic Search'. Instead of manually building an ad-hoc report, they ask their agent to run `run_realtime_report` for the last 60 minutes. The agent provides immediate data showing the drop is isolated to one specific city, allowing the team to check local campaigns.

### Optimizing Signups
A Product Manager suspects users are leaving during checkout. They use `run_funnel_report` on the signup flow. The report shows a massive drop-off between 'Started Checkout' and 'Completed Purchase,' confirming they need to fix payment options.

### Audience Segmentation
Marketing wants a list of users who viewed Product X but didn't buy in the last 30 days. They use `list_audience_exports` and then trigger `get_audience_export` to get the ID, automating their user segment creation.

### Pre-Flight Check
A Data Analyst needs a complex report combining 'eventCount' and 'deviceCategory.' Before running the main query, they use `check_compatibility`. The tool flags that these two metrics cannot be combined in one view, saving hours of debugging.

## Benefits

- **Funnel Analysis:** Use `run_funnel_report` to see exactly where users drop off during checkout or sign-up. This pinpoints conversion roadblocks immediately.
- **Realtime Visibility:** Ask for a report using `run_realtime_report` and get live counts of active users by country, without waiting for the next day's data sync.
- **Scope Check:** Need to know which reports you can run? Use `get_metadata` first. It lists every trackable metric and dimension in your property.
- **Efficiency Boost:** Don't call the API multiple times. Group complex requests into one go using `batch_run_reports` for faster dashboard loading.
- **Deep User Dive:** Investigate a single problematic customer by calling `get_user_activity`, retrieving their entire journey history by user ID.

## How It Works

The bottom line is, you treat the GA4 API like a function call within your conversation flow.

1. Subscribe to the server and input your Google Analytics API key from Google Cloud Console.
2. Ask your AI agent to perform an action (e.g., 'Run a funnel report for checkout').
3. The agent calls the necessary tool (`run_funnel_report`) and returns structured data containing the calculated metrics.

## Frequently Asked Questions

**How do I find out what metrics are available using `get_metadata`?**
`get_metadata` lists all available standard and custom metrics/dimensions for your property. This is the first tool you should run if you don't know the exact field names required for a report.

**What is the difference between `run_report` and `batch_run_reports`?**
`run_report` executes one single, custom query. Use `batch_run_reports` when you need to run several different report configurations (different metrics/dimensions) in a single API call for efficiency.

**Can I see what a specific user did with `get_user_activity`?**
Yes, but you must provide the correct `userId`. This tool pulls every recorded event, pageview, and conversion associated only with that unique ID.

**How do I check if my metrics will work together? Should I use `check_compatibility`?**
Yes, always run `check_compatibility`. It verifies your chosen metrics and dimensions before you waste time running a report that will fail due to data conflict.

**I want to see what is happening on my site right now. Which tool should I use?**
Use `run_realtime_report`. This function bypasses standard historical reporting and provides live metrics for the last 30-60 minutes, perfect for checking immediate traffic spikes.

**How do I find all available properties in an account before running a report with `list_properties`?**
You use `list_properties` to retrieve a list of property IDs. This is crucial because every report, whether custom or real-time, requires the specific property ID as its primary input.

**I just ran an audience export job; how can I check its current status using `get_audience_export`?**
The `get_audience_export` tool confirms the progress of your data extraction. It returns the current state—whether the job is CREATING, ACTIVE, or FAILED—so you know when to expect the user list.

**If my organization has multiple divisions, how do I see all top-level containers using `list_accounts`?**
`list_accounts` shows every Google Analytics account associated with your credentials. This gives you a high-level view of which business units or properties groups are available to query.

**How do I get a Google Analytics API key and what type of credentials do I need?**
You need an API Key from Google Cloud Console. Go to **console.cloud.google.com** → Select or create a project → Enable the **Google Analytics Data API v1** → Navigate to **APIs & Services > Credentials** → Click **Create Credentials > API Key**. Copy the key (starts with `AIzaSy...`). Then, in Google Analytics Admin, add the service account email with Viewer or Analyst role to your GA4 property. Paste the API key below.

**What metrics and dimensions are available in GA4 and how do I find them?**
Use the `get_metadata` tool with your property_id to list all available metrics and dimensions. Common metrics include: `activeUsers`, `screenPageViews`, `sessions`, `eventCount`, `engagementRate`, `averageSessionDuration`, `conversions`. Common dimensions include: `city`, `country`, `deviceCategory`, `sessionDefaultChannelGrouping`, `pageTitle`, `pagePath`, `streamName`. The metadata response shows descriptions, types, and whether each field is a metric or dimension.

**Can I get realtime data and how far back does it go?**
Yes! Use the `run_realtime_report` tool to get data from the last 30-60 minutes. Realtime reports show active users, events, and traffic sources as they happen on your site. This is useful for monitoring campaign launches, tracking live events, or checking if tracking is working correctly. Unlike standard reports which can take 24-48 hours to process, realtime data is available within minutes.

**How do I analyze funnel conversion rates and identify drop-off points?**
Use the `run_funnel_report` tool with a funnel_spec JSON object defining your conversion steps. Each step includes a stepName, filterExpression (e.g., eventName equals 'page_view'), and optional breakdown settings. The response shows how many users entered each step, how many completed it, and where the biggest drop-offs occurred. This helps identify friction points in checkout flows, signup processes, or any multi-step user journey.