getPageViews
Retrieve page view metrics from Google Analytics 4 for a specified date range. Analyze website traffic by grouping data with dimensions like page or country to understand visitor behavior patterns.
Instructions
Get page view metrics for a specific date range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dimensions | No | Dimensions to group by (e.g., page, country) | |
| endDate | Yes | End date in YYYY-MM-DD format | |
| startDate | Yes | Start date in YYYY-MM-DD format |
Implementation Reference
- src/index.ts:293-311 (handler)Handler implementation for the getPageViews tool. Extracts parameters, validates date range, and fetches analytics data for page views using the screenPageViews metric, grouped by specified dimensions (default: page).case "getPageViews": { const { startDate, endDate, dimensions = ["page"], } = args as { startDate: string; endDate: string; dimensions?: string[]; }; validateDateRange(startDate, endDate); return fetchAnalyticsData({ dateRanges: [{ startDate, endDate }], dimensions: dimensions.map((dimension) => ({ name: dimension })), metrics: [{ name: "screenPageViews" }], }); }
- src/index.ts:177-199 (schema)Schema definition for the getPageViews tool, registered in the listTools response. Includes input schema requiring startDate and endDate, with optional dimensions.{ name: "getPageViews", description: "Get page view 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", }, dimensions: { type: "array", items: { type: "string" }, description: "Dimensions to group by (e.g., page, country)", }, }, required: ["startDate", "endDate"], }, },