getUserBehavior
Retrieve user behavior metrics such as session duration and bounce rate from Google Analytics 4 data for specified date ranges to analyze website engagement patterns.
Instructions
Get user behavior metrics like session duration and bounce rate
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format |
Implementation Reference
- src/index.ts:352-370 (handler)Handler for the getUserBehavior tool. Extracts date range from arguments, validates it, and fetches analytics data for average session duration, bounce rate, sessions per user, grouped by date.
case "getUserBehavior": { const { startDate, endDate } = args as { startDate: string; endDate: string; }; validateDateRange(startDate, endDate); return fetchAnalyticsData({ dateRanges: [{ startDate, endDate }], metrics: [ { name: "averageSessionDuration" }, { name: "bounceRate" }, { name: "sessionsPerUser" }, ], dimensions: [{ name: "date" }], }); } - src/index.ts:240-258 (registration)Registration of the getUserBehavior tool in the listTools handler, including name, description, and input schema requiring startDate and endDate.
{ name: "getUserBehavior", description: "Get user behavior metrics like session duration and bounce rate", 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", }, }, required: ["startDate", "endDate"], }, },