get-clicks
Analyze and track outbound click activity from your WordPress site by specifying a URL, credentials, time period, and limit. Optimize links and monitor user behavior effectively.
Instructions
View a site's outbound clicks
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of click items to return | |
| password | Yes | WordPress application password | |
| period | No | Time period for stats | |
| siteId | Yes | WordPress site ID | |
| siteUrl | Yes | WordPress site URL | |
| username | Yes | WordPress username |
Implementation Reference
- src/index.ts:1601-1650 (registration)Registration of the 'get-clicks' tool, including schema and inline handler function.server.tool( "get-clicks", "View a site's outbound clicks", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), siteId: z.number().describe("WordPress site ID"), period: z.enum(["day", "week", "month", "year"]).optional().describe("Time period for stats"), limit: z.number().min(1).max(100).optional().describe("Maximum number of click items to return"), }, async ({ siteUrl, username, password, siteId, period = "week", limit = 10 }) => { try { const clicksData = await makeWPRequest<any>({ siteUrl, endpoint: `sites/${siteId}/stats/clicks`, auth: { username, password }, params: { period, limit } }); // Format will depend on the actual API response const clicksText = Array.isArray(clicksData.clicks) && clicksData.clicks.length > 0 ? clicksData.clicks.map((click: any) => `${click.name || click.url || "Unknown URL"} Clicks: ${click.clicks || 0} URL: ${click.url || "No URL"} ---` ).join("\n") : "No outbound clicks found"; return { content: [ { type: "text", text: `Outbound Clicks for site #${siteId} (${period}):\n\n${clicksText}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving clicks data: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- src/index.ts:1612-1649 (handler)The handler function that executes the tool logic: fetches outbound clicks stats from Jetpack Stats API endpoint `sites/${siteId}/stats/clicks`, formats the response, and returns it as text content.async ({ siteUrl, username, password, siteId, period = "week", limit = 10 }) => { try { const clicksData = await makeWPRequest<any>({ siteUrl, endpoint: `sites/${siteId}/stats/clicks`, auth: { username, password }, params: { period, limit } }); // Format will depend on the actual API response const clicksText = Array.isArray(clicksData.clicks) && clicksData.clicks.length > 0 ? clicksData.clicks.map((click: any) => `${click.name || click.url || "Unknown URL"} Clicks: ${click.clicks || 0} URL: ${click.url || "No URL"} ---` ).join("\n") : "No outbound clicks found"; return { content: [ { type: "text", text: `Outbound Clicks for site #${siteId} (${period}):\n\n${clicksText}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving clicks data: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:1605-1611 (schema)Input schema using Zod for validating parameters: siteUrl, username, password, siteId, period (optional), limit (optional).siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), siteId: z.number().describe("WordPress site ID"), period: z.enum(["day", "week", "month", "year"]).optional().describe("Time period for stats"), limit: z.number().min(1).max(100).optional().describe("Maximum number of click items to return"), },