get_page_traffic
Retrieve traffic analytics for a specific webpage by providing its URL and date range to analyze visitor data and page performance metrics.
Instructions
Get traffic data for a specific page by filtering with its URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | End date in YYYY-MM-DD format | |
| start_date | Yes | Start date in YYYY-MM-DD format | |
| url | Yes | Full URL or path of the page to get traffic for (e.g., https://example.com/path or /path) |
Implementation Reference
- src/tools/get-page-traffic.ts:29-60 (handler)The primary handler function for the 'get_page_traffic' tool. It constructs the date range from input arguments, fetches traffic data using ClickyClient.getPageTraffic, formats the JSON response, and handles errors appropriately.export async function handleGetPageTraffic( args: { url: string; start_date: string; end_date: string }, clickyClient: ClickyClient ) { try { const dateRange: DateRange = { startDate: args.start_date, endDate: args.end_date }; const data = await clickyClient.getPageTraffic(args.url, dateRange); return { content: [ { type: 'text', text: JSON.stringify(data, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching page traffic: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } }
- src/tools/get-page-traffic.ts:4-27 (schema)Tool definition including name, description, and detailed input schema for validating arguments: url (string), start_date and end_date (YYYY-MM-DD strings).export const getPageTrafficTool: Tool = { name: 'get_page_traffic', description: 'Get traffic data for a specific page by filtering with its URL', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'Full URL or path of the page to get traffic for (e.g., https://example.com/path or /path)' }, start_date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$', description: 'Start date in YYYY-MM-DD format' }, end_date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$', description: 'End date in YYYY-MM-DD format' } }, required: ['url', 'start_date', 'end_date'] } };
- src/index.ts:91-99 (registration)Registers the getPageTrafficTool in the list of available tools returned by ListToolsRequest.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ getTotalVisitorsTool, getDomainVisitorsTool, getTopPagesTool, getTrafficSourcesTool, getPageTrafficTool, ], }));
- src/index.ts:118-119 (registration)Dispatches calls to 'get_page_traffic' to the handleGetPageTraffic function in the CallToolRequest handler.case 'get_page_traffic': return await handleGetPageTraffic(args as any, this.clickyClient);
- src/clicky-client.ts:136-164 (helper)Supporting method in ClickyClient that performs the actual API request to retrieve page traffic data using the 'pages' type with a 'filter' parameter for the URL path.async getPageTraffic(url: string, dateRange: DateRange): Promise<any> { this.validateDateRange(dateRange); // Extract path from URL and encode it let path: string; try { const urlObj = new URL(url); path = urlObj.pathname; } catch (error) { // If URL parsing fails, assume it's already a path path = url.startsWith('/') ? url : '/' + url; } // Use raw path - Axios will handle the URL encoding automatically const filterPath = path; const response = await this.client.get('', { params: { site_id: this.siteId, sitekey: this.siteKey, type: 'pages', filter: filterPath, date: `${dateRange.startDate},${dateRange.endDate}`, output: 'json' } }); return response.data; }