Skip to main content
Glama
wonyoungseong

GA4 MCP Server

ga4_property_details

Retrieve comprehensive configuration details for a Google Analytics 4 property, including name, time zone, currency, and industry settings, to understand and manage property setup.

Instructions

Returns details about a specific GA4 property including its name, display name, time zone, currency, industry category, and other settings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdYesThe Google Analytics property ID. Accepted formats: '123456789', '123456789', or 'properties/123456789'

Implementation Reference

  • The getPropertyDetails function that implements the ga4_property_details tool. It gets the Analytics Admin client, constructs the property resource name, and calls the GA4 Admin API to retrieve property details.
    /**
     * Returns details about a specific GA4 property.
     */
    export async function getPropertyDetails(propertyId: string): Promise<ToolResponse> {
      try {
        const client = await getAnalyticsAdminClient();
        const propertyName = constructPropertyResourceName(propertyId);
    
        const response = await client.properties.get({
          name: propertyName,
        });
    
        return createSuccessResponse(response.data);
      } catch (error) {
        return createErrorResponse(`Failed to get property details for ${propertyId}`, error);
      }
    }
  • Tool registration schema definition for ga4_property_details, including name, description, and input schema with propertyId parameter.
    {
      name: "ga4_property_details",
      description: "Returns details about a specific GA4 property including its name, display name, time zone, currency, industry category, and other settings.",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: {
            type: "string",
            description: "The Google Analytics property ID. Accepted formats: '123456789', '123456789', or 'properties/123456789'",
          },
        },
        required: ["propertyId"],
      },
    },
  • Tool routing case that maps the ga4_property_details tool name to the getPropertyDetails handler function.
    case "ga4_property_details":
      return await getPropertyDetails(args.propertyId as string);
  • Helper function that constructs a properly formatted property resource name from various input formats (numeric, string, or properties/ prefix) for use with GA4 API calls.
    /**
     * Constructs a property resource name in the format required by GA4 APIs.
     * Accepts formats: "123456789", 123456789, or "properties/123456789"
     * Returns: "properties/123456789"
     */
    export function constructPropertyResourceName(propertyId: string | number): string {
      let propertyNum: number | null = null;
    
      if (typeof propertyId === "number") {
        propertyNum = propertyId;
      } else if (typeof propertyId === "string") {
        const trimmed = propertyId.trim();
        if (/^\d+$/.test(trimmed)) {
          propertyNum = parseInt(trimmed, 10);
        } else if (trimmed.startsWith("properties/")) {
          const numericPart = trimmed.split("/")[1];
          if (numericPart && /^\d+$/.test(numericPart)) {
            propertyNum = parseInt(numericPart, 10);
          }
        }
      }
    
      if (propertyNum === null) {
        throw new Error(
          `Invalid property ID: ${propertyId}. ` +
          "A valid property value is either a number or a string starting " +
          "with 'properties/' and followed by a number."
        );
      }
    
      return `properties/${propertyNum}`;
    }
  • ToolResponse interface type definition that defines the standard response format for all MCP tools, including ga4_property_details.
    // Tool response type for MCP
    export interface ToolResponse {
      content: Array<{
        type: "text";
        text: string;
      }>;
      isError?: boolean;
    }

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