Skip to main content
Glama
surendranb

Google Analytics MCP Server

by surendranb

get_ga4_data

Retrieve Google Analytics 4 data with data volume protection, automatic aggregation, and intelligent sorting. Ensures safe queries by checking row estimates and providing warnings for large datasets.

Instructions

Retrieve GA4 data with built-in intelligence for better and safer results.

CRITICAL WORKFLOW INSTRUCTIONS FOR AI AGENTS: To ensure deterministic and successful data retrieval, you MUST follow this sequence:

  1. DISCOVER: NEVER guess dimension or metric names. Always call search_schema, list_dimension_categories, or list_metric_categories FIRST to verify the exact API names available for this property.

  2. RETRIEVE: Call this tool (get_ga4_data) using the verified dimensions and metrics.

  3. TROUBLESHOOT: If you receive a SchemaError, an Invalid Dimension/Metric error, or an error about dimension_filter structure, DO NOT RETRY BY GUESSING. You MUST immediately call get_troubleshooting_guide(topic='schema') to learn the correct structure and available fields.

Smart Features:

  • Data Volume Protection: Before running a query that could produce a huge number of rows, the tool runs a quick estimate. If the row count exceeds a safe threshold (2500 rows), it will return a warning with suggestions instead of the data. You can override this by setting proceed_with_large_dataset=True.

  • Automatic Server-Side Aggregation: If your query does not involve a time dimension (like 'date'), the tool automatically asks the GA4 API to return aggregated totals. This is more efficient and provides cleaner results. You can disable this by setting enable_aggregation=False.

  • Intelligent Sorting: Results are automatically sorted by date (most recent first) and the primary metric (highest value first) to show the most relevant data at the top.

Args: dimensions: List of GA4 dimensions (e.g., ["date", "city"]). MUST be verified via schema tools. metrics: List of GA4 metrics (e.g., ["totalUsers", "sessions"]). MUST be verified via schema tools. date_range_start: Start date in YYYY-MM-DD format or relative date ('7daysAgo'). date_range_end: End date in YYYY-MM-DD format or relative date ('yesterday'). dimension_filter: (Optional) A GA4 FilterExpression dictionary. Both camelCase and snake_case keys are transparently auto-translated and supported. Example simple filter structure: { "filter": { "fieldName": "sessionSource", "stringFilter": {"value": "google", "matchType": "CONTAINS"} } } Example logical group (andGroup, orGroup, notExpression): { "andGroup": { "expressions": [ {"filter": {"fieldName": "deviceCategory", "stringFilter": {"value": "mobile"}}}, {"filter": {"fieldName": "country", "stringFilter": {"value": "United States"}}} ] } } limit: (Optional) Maximum number of rows to return. Defaults to 1000. estimate_only: (Optional) If True, returns only the estimated row count without fetching the full dataset. proceed_with_large_dataset: (Optional) Set to True to bypass the data volume warning and execute the query anyway. enable_aggregation: (Optional) If True, uses server-side aggregation when beneficial. Defaults to True.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
metricsNo
dimensionsNo
estimate_onlyNo
date_range_endNoyesterday
date_range_startNo7daysAgo
dimension_filterNo
enable_aggregationNo
proceed_with_large_datasetNo
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses all behavioral traits: data volume protection with threshold and override, automatic aggregation with disable option, intelligent sorting. Also mentions error handling workflow. No annotations, so description carries full burden and delivers.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with summary, bold workflow, bulleted features, args list. Slightly lengthy but each part is valuable. Front-loaded with critical workflow.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Complete for a complex 9-parameter tool with no output schema and no annotations. Covers parameter meanings, smart features, error handling, integration with sibling tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema has 0% description coverage, but description compensates fully: explains dimensions/metrics must be verified, date format, dimension_filter structure with examples, limit default, estimate_only, proceed_with_large_dataset, enable_aggregation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Retrieve GA4 data' with specific verb and resource. Distinguishes from sibling tools by outlining a workflow where discovery tools must be called first, and troubleshooting tool for errors.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit step-by-step workflow: DISCOVER (using schema tools), RETRIEVE (this tool), TROUBLESHOOT (if errors). Also explains when to override features like data volume protection and aggregation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/surendranb/google-analytics-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server