/** * Analytics Tools */ import type { SquarespaceClient } from '../clients/squarespace.js'; export function createAnalyticsTools(client: SquarespaceClient) { return [ { name: 'squarespace_get_analytics', description: 'Get analytics data for a site', inputSchema: { type: 'object', properties: { siteId: { type: 'string', description: 'The site ID', }, startDate: { type: 'string', description: 'Start date (ISO 8601)', }, endDate: { type: 'string', description: 'End date (ISO 8601)', }, metrics: { type: 'array', description: 'Metrics to retrieve', items: { type: 'string', enum: ['pageViews', 'uniqueVisitors', 'revenue', 'orders', 'conversionRate'], }, }, }, required: ['siteId', 'startDate', 'endDate'], }, handler: async (args: { siteId: string; startDate: string; endDate: string; metrics?: string[]; }) => { const analytics = await client.getAnalytics(args.siteId, { startDate: args.startDate, endDate: args.endDate, metrics: args.metrics, }); return { content: [ { type: 'text', text: JSON.stringify(analytics, null, 2), }, ], }; }, }, { name: 'squarespace_get_top_pages', description: 'Get top performing pages by views', inputSchema: { type: 'object', properties: { siteId: { type: 'string', description: 'The site ID', }, startDate: { type: 'string', description: 'Start date (ISO 8601)', }, endDate: { type: 'string', description: 'End date (ISO 8601)', }, limit: { type: 'number', description: 'Number of results (default: 10)', }, }, required: ['siteId', 'startDate', 'endDate'], }, handler: async (args: { siteId: string; startDate: string; endDate: string; limit?: number; }) => { const analytics = await client.getAnalytics(args.siteId, { startDate: args.startDate, endDate: args.endDate, }); const topPages = (analytics.topPages || []).slice(0, args.limit || 10); return { content: [ { type: 'text', text: JSON.stringify(topPages, null, 2), }, ], }; }, }, { name: 'squarespace_get_top_products', description: 'Get top selling products by revenue', inputSchema: { type: 'object', properties: { siteId: { type: 'string', description: 'The site ID', }, startDate: { type: 'string', description: 'Start date (ISO 8601)', }, endDate: { type: 'string', description: 'End date (ISO 8601)', }, limit: { type: 'number', description: 'Number of results (default: 10)', }, }, required: ['siteId', 'startDate', 'endDate'], }, handler: async (args: { siteId: string; startDate: string; endDate: string; limit?: number; }) => { const analytics = await client.getAnalytics(args.siteId, { startDate: args.startDate, endDate: args.endDate, }); const topProducts = (analytics.topProducts || []).slice(0, args.limit || 10); return { content: [ { type: 'text', text: JSON.stringify(topProducts, null, 2), }, ], }; }, }, { name: 'squarespace_get_revenue_report', description: 'Get revenue summary for a period', inputSchema: { type: 'object', properties: { siteId: { type: 'string', description: 'The site ID', }, startDate: { type: 'string', description: 'Start date (ISO 8601)', }, endDate: { type: 'string', description: 'End date (ISO 8601)', }, }, required: ['siteId', 'startDate', 'endDate'], }, handler: async (args: { siteId: string; startDate: string; endDate: string }) => { const analytics = await client.getAnalytics(args.siteId, { startDate: args.startDate, endDate: args.endDate, metrics: ['revenue', 'orders', 'conversionRate'], }); return { content: [ { type: 'text', text: JSON.stringify( { period: `${args.startDate} to ${args.endDate}`, revenue: analytics.metrics.revenue, orders: analytics.metrics.orders, averageOrderValue: analytics.metrics.averageOrderValue, conversionRate: analytics.metrics.conversionRate, }, null, 2 ), }, ], }; }, }, ]; }