Skip to main content
Glama
googleanalytics

Google Analytics MCP Server

Official

get_custom_dimensions_and_metrics

Retrieve custom dimensions and metrics from a Google Analytics property to analyze user-defined data points and track specific business metrics.

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

TableJSON Schema
NameRequiredDescriptionDefault
property_idYes

Implementation Reference

  • Handler function for the 'get_custom_dimensions_and_metrics' tool. It retrieves custom dimensions and metrics for a given Google Analytics property ID by calling the Data API metadata endpoint. Includes @mcp.tool decorator which registers the tool, type hints for input/output schema, and full implementation logic.
    @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,
        }

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/googleanalytics/google-analytics-mcp'

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