Google Analytics

Google Analytics

Power integration with Google Analytics to analyse web traffic and conversion funnel data

Power integration with Google Analytics to analyse web traffic and conversion funnel data

4

min read

Overview

The Google Analytics 4 (GA4) MCP (Model Context Protocol) tools provides seamless access to your website and app performance data. This server enables you to retrieve detailed insights about user behavior, traffic sources, conversions, and much more through Google Analytics 4's powerful reporting API.

Key Benefits:

  • Complete Analytics Access: Connect to all your GA4 properties and retrieve comprehensive performance data

  • Real-time Insights: Access up-to-date user behavior, traffic, and conversion metrics

  • Advanced Analysis: Perform funnel analysis, cohort studies, and custom reporting

  • Flexible Reporting: Create custom reports with any combination of dimensions and metrics

  • Multi-Property Management: Manage and analyze multiple GA4 properties from a single interface

Tool Reference

1. List Analytics Properties

Purpose: Discover and access all Google Analytics 4 properties available to your account.

What it does: Retrieves a complete hierarchical structure showing all your Google Analytics accounts and their associated GA4 properties, including property IDs needed for reporting.

Key Parameters:

  • account_id (optional): Specific GA account to list properties for

Property Information Retrieved:

  • Property ID (required for all other tools)

  • Display name and type

  • Time zone and currency settings

  • Industry category

  • Creation date

Sample Use Cases:

  • Initial setup to discover available properties

  • Property access verification

  • Multi-account management

Example Request:

Example Output:

{
  "summary": {
    "totalAccounts": 2,
    "totalProperties": 4
  },
  "accounts": [
    {
      "accountId": "123456789",
      "accountName": "My Business Analytics",
      "propertyCount": 2,
      "properties": [
        {
          "propertyId": "987654321",
          "displayName": "My Website",
          "propertyType": "PROPERTY_TYPE_ORDINARY",
          "timeZone": "America/New_York",
          "currencyCode": "USD"
        }
      ]
    }
  ]
}
2. Get Active Users

Purpose: Monitor current user engagement and activity levels on your website or app.

What it does: Retrieves active user metrics and new user counts for any specified date range, helping you understand your audience growth and engagement patterns.

Key Parameters:

  • property_id (required): GA4 property ID (e.g., "987654321")

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

Metrics Retrieved:

  • Active Users: Users who had an engaged session or event

  • New Users: First-time visitors to your site/app

Sample Use Cases:

  • Daily user activity monitoring

  • Growth tracking and trend analysis

  • User acquisition performance

  • Audience engagement assessment

Example Request:


Example Output:

{
  "dimensionHeaders": [{"name": "date"}],
  "metricHeaders": [
    {"name": "activeUsers", "type": "TYPE_INTEGER"},
    {"name": "newUsers", "type": "TYPE_INTEGER"}
  ],
  "rows": [
    {
      "dimensionValues": [{"value": "20240101"}],
      "metricValues": [
        {"value": "2847"},
        {"value": "1203"}
      ]
    }
  ]
}
3. Get Page Views

Purpose: Analyze which pages are most popular and how users navigate through your website.

What it does: Retrieves detailed page view metrics, allowing you to understand content performance and user navigation patterns across your website.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

  • dimensions (optional): Additional dimensions for grouping (defaults to pagePath)

Available Dimensions:

  • pagePath: URL path of the page

  • pageTitle: Title of the page

  • country: User's country

  • deviceCategory: Desktop, mobile, tablet

Sample Use Cases:

  • Content performance analysis

  • Popular page identification

  • Navigation pattern analysis

  • Geographic content preferences

Example Request:


Example Output:

{
  "dimensionHeaders": [
    {"name": "pagePath"},
    {"name": "pageTitle"}
  ],
  "metricHeaders": [{"name": "screenPageViews"}],
  "rows": [
    {
      "dimensionValues": [
        {"value": "/products/widget-a"},
        {"value": "Premium Widget A - Features & Pricing"}
      ],
      "metricValues": [{"value": "5247"}]
    }
  ]
}
4. Get Traffic Sources

Purpose: Understand how users discover and arrive at your website.

What it does: Provides comprehensive traffic source analysis showing which channels, sources, and mediums drive the most valuable traffic to your site.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

Traffic Data Retrieved:

  • Session Source: Specific source (google, facebook, newsletter)

  • Session Medium: Traffic medium (organic, cpc, email, social)

  • Sessions: Number of sessions from each source

  • Total Users: Unique users from each source

  • Page Views: Total page views generated

Sample Use Cases:

  • Marketing channel effectiveness

  • Traffic source optimization

  • Campaign performance analysis

  • Budget allocation decisions

Example Request:


Example Output:

{
  "dimensionHeaders": [
    {"name": "sessionSource"},
    {"name": "sessionMedium"}
  ],
  "metricHeaders": [
    {"name": "sessions"},
    {"name": "totalUsers"},
    {"name": "screenPageViews"}
  ],
  "rows": [
    {
      "dimensionValues": [
        {"value": "google"},
        {"value": "organic"}
      ],
      "metricValues": [
        {"value": "15847"},
        {"value": "12394"},
        {"value": "47582"}
      ]
    }
  ]
}
5. Get Device Metrics

Purpose: Analyze user device preferences and optimize experiences for different platforms.

What it does: Provides detailed insights into the devices and browsers your users prefer, helping you prioritize development and design efforts.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

Device Data Retrieved:

  • Device Category: Desktop, mobile, tablet

  • Browser: Chrome, Safari, Firefox, etc.

  • Sessions: Sessions per device/browser combination

  • Total Users: Unique users per device type

  • Page Views: Total page views per device

Sample Use Cases:

  • Mobile optimization prioritization

  • Browser compatibility planning

  • User experience optimization

  • Technical requirements planning

Example Request:


Example Output:

{
  "dimensionHeaders": [
    {"name": "deviceCategory"},
    {"name": "browser"}
  ],
  "metricHeaders": [
    {"name": "sessions"},
    {"name": "totalUsers"},
    {"name": "screenPageViews"}
  ],
  "rows": [
    {
      "dimensionValues": [
        {"value": "mobile"},
        {"value": "Chrome"}
      ],
      "metricValues": [
        {"value": "8947"},
        {"value": "7234"},
        {"value": "24891"}
      ]
    }
  ]
}
6. Get User Behavior

Purpose: Understand how users interact with your website and identify engagement patterns.

What it does: Retrieves key behavioral metrics that help you understand user engagement quality, session depth, and overall site stickiness.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

Behavior Metrics Retrieved:

  • Average Session Duration: How long users spend on your site

  • Bounce Rate: Percentage of single-page sessions

  • Sessions Per User: How frequently users return

Sample Use Cases:

  • Content engagement analysis

  • User experience optimization

  • Site stickiness assessment

  • Content strategy development

Example Request:


Example Output:

{
  "dimensionHeaders": [{"name": "date"}],
  "metricHeaders": [
    {"name": "averageSessionDuration"},
    {"name": "bounceRate"},
    {"name": "sessionsPerUser"}
  ],
  "rows": [
    {
      "dimensionValues": [{"value": "20240115"}],
      "metricValues": [
        {"value": "185.7"},
        {"value": "0.4234"},
        {"value": "1.47"}
      ]
    }
  ]
}
7. Get Events

Purpose: Track and analyze specific user actions and interactions on your website or app.

What it does: Provides detailed event tracking data, allowing you to measure user engagement with specific features, content, or conversion points.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

  • event_name (optional): Filter for specific events

Event Data Retrieved:

  • Event Name: Name of the tracked event

  • Event Count: Number of times the event occurred

  • Date: When events occurred

Common GA4 Events:

  • page_view: Page views

  • click: Button/link clicks

  • scroll: Page scrolling

  • file_download: File downloads

  • form_start: Form interactions

  • purchase: E-commerce transactions

  • sign_up: User registrations

Sample Use Cases:

  • Conversion tracking

  • Feature usage analysis

  • User engagement measurement

  • A/B testing analysis

Example Request:


Example Output:

{
  "dimensionHeaders": [
    {"name": "eventName"},
    {"name": "date"}
  ],
  "metricHeaders": [{"name": "eventCount"}],
  "rows": [
    {
      "dimensionValues": [
        {"value": "purchase"},
        {"value": "20240115"}
      ],
      "metricValues": [{"value": "47"}]
    }
  ]
}
8. Run Custom Report

Purpose: Create fully customized analytics reports with any combination of metrics and dimensions.

What it does: Provides maximum flexibility for creating tailored reports that meet your specific analysis needs, supporting all GA4 metrics and dimensions.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

  • metrics (required): Array of metric names

  • dimensions (optional): Array of dimension names

  • limit (optional): Maximum rows to return

  • order_bys (optional): Sorting configuration

Popular Metrics:

  • sessions, totalUsers, activeUsers, newUsers

  • screenPageViews, bounceRate, engagementRate

  • averageSessionDuration, userEngagementDuration

  • conversions, totalRevenue, purchaseRevenue

  • eventCount, eventsPerSession

Popular Dimensions:

  • country, city, region, continent

  • deviceCategory, operatingSystem, browser

  • source, medium, campaignName, sessionDefaultChannelGroup

  • pagePath, pageTitle, landingPage

  • date, month, year, hour, dayOfWeek

Sample Use Cases:

  • Executive dashboard creation

  • Custom KPI tracking

  • Advanced segmentation analysis

  • Performance benchmarking

Example Request:

Property ID: 987654321
Start Date: 2024-01-01
End Date: 2024-01-31
Metrics: ["sessions", "totalUsers", "screenPageViews", "conversions"]
Dimensions: ["country", "deviceCategory"]

Example Output:

{
  "dimensionHeaders": [
    {"name": "country"},
    {"name": "deviceCategory"}
  ],
  "metricHeaders": [
    {"name": "sessions"},
    {"name": "totalUsers"},
    {"name": "screenPageViews"},
    {"name": "conversions"}
  ],
  "rows": [
    {
      "dimensionValues": [
        {"value": "United States"},
        {"value": "mobile"}
      ],
      "metricValues": [
        {"value": "12847"},
        {"value": "9234"},
        {"value": "38591"},
        {"value": "284"}
      ]
    }
  ]
}
9. Run Funnel Analysis

Purpose: Analyze user progression through multi-step processes to identify conversion bottlenecks.

What it does: Provides advanced funnel analysis showing how users move through defined steps (like a purchase process), revealing drop-off points and conversion rates between each step.

Key Parameters:

  • property_id (required): GA4 property ID

  • start_date (required): Start date in YYYY-MM-DD format

  • end_date (required): End date in YYYY-MM-DD format

  • funnel_steps (required): Array of funnel step definitions (minimum 2 steps)

  • breakdown_dimension (optional): Segment funnel by dimension

Funnel Step Types:

  • Event-based: Filter by specific events (recommended)

  • Field-based: Filter by dimension values

  • Mixed: Combine both approaches

Common Funnel Examples:

  • E-commerce: Product view → Add to cart → Checkout → Purchase

  • Lead Generation: Landing page → Form start → Form submit → Thank you

  • Content: Article view → Scroll 50% → Newsletter signup

  • SaaS: Signup → Onboarding → First feature use → Upgrade

Sample Use Cases:

  • Conversion optimization

  • User journey analysis

  • A/B testing impact measurement

  • Process improvement identification

Example Request:

{
  "property_id": "987654321",
  "start_date": "2024-01-01",
  "end_date": "2024-01-31",
  "funnel_steps": [
    {
      "name": "Product View",
      "event_names": ["view_item"]
    },
    {
      "name": "Add to Cart", 
      "event_names": ["add_to_cart"]
    },
    {
      "name": "Begin Checkout",
      "event_names": ["begin_checkout"]
    },
    {
      "name": "Purchase",
      "event_names": ["purchase"]
    }
  ],
  "breakdown_dimension": "deviceCategory"
}

Example Output:

{
  "funnelTable": {
    "headers": [
      {"name": "funnelStepName"},
      {"name": "activeUsers"},
      {"name": "conversionRate"}
    ],
    "rows": [
      {
        "values": ["Product View", "15847", "100%"]
      },
      {
        "values": ["Add to Cart", "4251", "26.8%"]
      },
      {
        "values": ["Begin Checkout", "1847", "43.4%"]
      },
      {
        "values": ["Purchase", "1284", "69.5%"]
      }
    ]
  },
  "funnelVisualization": {
    "steps": [
      {
        "stepName": "Product View",
        "activeUsers": "15847",
        "conversionRate": "1.0"
      }
    ]
  }
}

Getting Started

Prerequisites
  • Active Google Analytics 4 property

  • Google Cloud Console project with Analytics API enabled

  • Valid OAuth2 credentials with appropriate scopes

  • Admin access to GA4 properties you want to analyze

Google Analytics MCP Tools

Basic Workflow
  1. Discovery: Start with "List Analytics Properties" to find your property IDs

  2. Overview Analysis: Use "Get Active Users" for high-level traffic trends

  3. Traffic Analysis: Examine sources with "Get Traffic Sources"

  4. Content Analysis: Review page performance with "Get Page Views"

  5. Behavior Analysis: Understand engagement with "Get User Behavior"

  6. Advanced Analysis: Create custom reports or funnel analysis

  7. Event Tracking: Monitor specific actions with "Get Events"

Common Analysis Workflows

Daily Monitoring Dashboard:

  1. Get Active Users for daily traffic trends

  2. Get Traffic Sources for channel performance

  3. Get User Behavior for engagement quality

  4. Get Events for conversion tracking

Content Performance Analysis:

  1. Get Page Views by page path

  2. Get User Behavior for engagement metrics

  3. Run Custom Report with content dimensions

  4. Get Device Metrics for optimization priorities

Conversion Optimization:

  1. Run Funnel Analysis for process optimization

  2. Get Events for specific conversion actions

  3. Run Custom Report with conversion metrics

  4. Get Traffic Sources for channel attribution

Best Practices

Data Retrieval
  • Use appropriate date ranges: GA4 data is typically available with a 24-48 hour delay

  • Start with standard reports: Use predefined tools before creating custom reports

  • Limit data scope: Use date ranges and filters to focus on relevant data

  • Understand GA4 metrics: Some metrics differ from Universal Analytics

Performance Optimization
  • Batch related requests: Group similar analysis into single custom reports

  • Use appropriate limits: Set reasonable row limits for large datasets

  • Cache frequently used data: Store commonly accessed metrics locally

  • Monitor API quotas: Be aware of GA4 API rate limits

Analysis Strategy
  • Start with questions: Define what you want to learn before choosing tools

  • Use funnel analysis: Understand user journeys and conversion paths

  • Segment your data: Use dimensions to understand different user groups

  • Compare time periods: Look at trends rather than single points in time

Common Pitfalls to Avoid
  • Metric confusion: Ensure you're using GA4 metrics (not Universal Analytics)

  • Property ID errors: Double-check property IDs are correct

  • Date format issues: Always use YYYY-MM-DD format for dates

  • Dimension limitations: Some dimensions can't be combined in reports

Troubleshooting

Common Error Messages

"No data found for property"

  • Verify property ID is correct and accessible

  • Check date range (data may not be available for recent dates)

  • Ensure property has tracking data for the specified period

"Google Analytics API error: 403"

  • Check OAuth2 credentials and scopes

  • Verify access to the specified property

  • Ensure Analytics API is enabled in Google Cloud Console

"Invalid metric/dimension name"

  • Use GA4 metric names (not Universal Analytics)

  • Check spelling and formatting of metric/dimension names

  • Refer to GA4 API documentation for valid names

Data Quality Issues

Missing Recent Data:

  • GA4 data typically has 24-48 hour processing delay

  • Use earlier date ranges for complete data

Unexpected Metric Values:

  • Understand GA4 vs Universal Analytics metric differences

  • Check for data filters or sampling

  • Verify property configuration and tracking setup

Empty Results:

  • Check if property has data for the specified time period

  • Verify tracking implementation

  • Review any applied filters or segments

Performance Issues

Slow Response Times:

  • Reduce date range scope

  • Limit number of dimensions

  • Use appropriate row limits

  • Consider breaking large requests into smaller chunks

API Rate Limits:

  • Implement request spacing

  • Use caching for frequently accessed data

  • Optimize query efficiency