get_custom_dimensions_and_metrics
Retrieve custom dimensions and metrics for a Google Analytics property by specifying the property ID. Simplify data extraction and analysis for tailored insights.
Instructions
Returns the property's custom dimensions and metrics.
Args:
property_id: The Google Analytics property ID. Accepted formats are:
- A number
- A string consisting of 'properties/' followed by a number
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| property_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"property_id": {
"anyOf": [
{
"type": "integer"
},
{
"type": "string"
}
],
"title": "Property Id"
}
},
"required": [
"property_id"
],
"title": "get_custom_dimensions_and_metricsArguments",
"type": "object"
}
Implementation Reference
- The main handler function decorated with @mcp.tool for registration. It retrieves custom dimensions and metrics for the given GA4 property ID using the Data API's get_metadata method, filtering for custom definitions and converting to dicts.@mcp.tool( title="Retrieves the custom Core Reporting dimensions and metrics for a specific property" ) async def get_custom_dimensions_and_metrics( property_id: int | str, ) -> Dict[str, List[Dict[str, Any]]]: """Returns the property's custom dimensions and metrics. Args: property_id: The Google Analytics property ID. Accepted formats are: - A number - A string consisting of 'properties/' followed by a number """ metadata = await create_data_api_client().get_metadata( name=f"{construct_property_rn(property_id)}/metadata" ) custom_metrics = [ proto_to_dict(metric) for metric in metadata.metrics if metric.custom_definition ] custom_dimensions = [ proto_to_dict(dimension) for dimension in metadata.dimensions if dimension.custom_definition ] return { "custom_dimensions": custom_dimensions, "custom_metrics": custom_metrics, }