Skip to main content
Glama
wonyoungseong

GA4 MCP Server

ga4_custom_dimensions_metrics

Retrieve custom dimensions and metrics from a GA4 property to discover available definitions before running reports.

Instructions

Retrieves the custom dimensions and metrics defined for a GA4 property. Use this to discover what custom definitions are available before running reports.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdYesThe Google Analytics property ID

Implementation Reference

  • The actual implementation of getCustomDimensionsAndMetrics function that retrieves custom dimensions and metrics for a GA4 property by calling the Analytics Data API's getMetadata endpoint and filtering for customDefinition === true
    export async function getCustomDimensionsAndMetrics(propertyId: string): Promise<ToolResponse> { try { const client = await getAnalyticsDataClient(); const propertyName = constructPropertyResourceName(propertyId); const response = await client.properties.getMetadata({ name: `${propertyName}/metadata`, }); const data = response.data; // Filter for custom dimensions and metrics const customDimensions = (data.dimensions || []).filter( dim => dim.customDefinition === true ); const customMetrics = (data.metrics || []).filter( metric => metric.customDefinition === true ); return createSuccessResponse({ propertyId: propertyName, customDimensions: customDimensions, customMetrics: customMetrics, customDimensionsCount: customDimensions.length, customMetricsCount: customMetrics.length, }); } catch (error) { return createErrorResponse(`Failed to get custom dimensions and metrics for ${propertyId}`, error); } }
  • Tool registration definition for ga4_custom_dimensions_metrics with name, description, and input schema specifying propertyId as required parameter
    { name: "ga4_custom_dimensions_metrics", description: "Retrieves the custom dimensions and metrics defined for a GA4 property. Use this to discover what custom definitions are available before running reports.", inputSchema: { type: "object" as const, properties: { propertyId: { type: "string", description: "The Google Analytics property ID", }, }, required: ["propertyId"], }, },
  • Tool routing logic that maps the ga4_custom_dimensions_metrics tool name to the getCustomDimensionsAndMetrics handler function
    case "ga4_custom_dimensions_metrics": return await getCustomDimensionsAndMetrics(args.propertyId as string);

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/wonyoungseong/ga4-mcp-server'

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