Skip to main content
Glama
ruchernchong

mcp-server-google-analytics

by ruchernchong

getEvents

Retrieve Google Analytics event metrics for a specified date range to analyze user interactions and track specific events on your website or application.

Instructions

Get event metrics for a specific date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endDateYesEnd date in YYYY-MM-DD format
eventNameNoSpecific event name to filter by (optional)
startDateYesStart date in YYYY-MM-DD format

Implementation Reference

  • Handler function for the 'getEvents' tool. Extracts startDate, endDate, and optional eventName from arguments, validates the date range, and invokes fetchAnalyticsData with appropriate dimensions (eventName, date), metric (eventCount), and optional dimension filter for the eventName.
    case "getEvents": { const { startDate, endDate, eventName } = args as { startDate: string; endDate: string; eventName?: string; }; validateDateRange(startDate, endDate); return fetchAnalyticsData({ dateRanges: [{ startDate, endDate }], dimensions: [{ name: "eventName" }, { name: "date" }], metrics: [{ name: "eventCount" }], ...(eventName && { dimensionFilter: { filter: { fieldName: "eventName", stringFilter: { value: eventName }, }, }, }), }); }
  • src/index.ts:218-239 (registration)
    Registration of the 'getEvents' tool in the listTools response, including its name, description, and input schema definition.
    { name: "getEvents", description: "Get event metrics for a specific date range", inputSchema: { type: "object", properties: { startDate: { type: "string", description: "Start date in YYYY-MM-DD format", }, endDate: { type: "string", description: "End date in YYYY-MM-DD format", }, eventName: { type: "string", description: "Specific event name to filter by (optional)", }, }, required: ["startDate", "endDate"], }, },
  • Input schema for the 'getEvents' tool, defining properties for startDate, endDate (required), and optional eventName.
    inputSchema: { type: "object", properties: { startDate: { type: "string", description: "Start date in YYYY-MM-DD format", }, endDate: { type: "string", description: "End date in YYYY-MM-DD format", }, eventName: { type: "string", description: "Specific event name to filter by (optional)", }, }, required: ["startDate", "endDate"], },
  • Helper function validateDateRange used by getEvents (and other tools) to ensure valid date formats and logical range.
    function validateDateRange(startDate: string, endDate: string): void { if (!validateDateFormat(startDate)) { throw new McpError( ErrorCode.InvalidParams, `Invalid startDate format. Expected YYYY-MM-DD, got: ${startDate}`, ); } if (!validateDateFormat(endDate)) { throw new McpError( ErrorCode.InvalidParams, `Invalid endDate format. Expected YYYY-MM-DD, got: ${endDate}`, ); } if (new Date(startDate) > new Date(endDate)) { throw new McpError( ErrorCode.InvalidParams, "startDate cannot be after endDate", ); } }

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

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