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
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | End date in YYYY-MM-DD format | |
| eventName | No | Specific event name to filter by (optional) | |
| startDate | Yes | Start date in YYYY-MM-DD format |
Implementation Reference
- src/index.ts:328-350 (handler)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"], }, },
- src/index.ts:221-238 (schema)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"], },
- src/index.ts:47-68 (helper)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", ); } }