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
| Name | Required | Description | Default |
|---|---|---|---|
| propertyId | Yes | The Google Analytics property ID |
Implementation Reference
- src/tools/reporting.ts:186-216 (handler)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 === trueexport 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); } }
- src/tools/index.ts:228-241 (registration)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"], }, },
- src/tools/index.ts:296-297 (registration)Tool routing logic that maps the ga4_custom_dimensions_metrics tool name to the getCustomDimensionsAndMetrics handler functioncase "ga4_custom_dimensions_metrics": return await getCustomDimensionsAndMetrics(args.propertyId as string);