smartlead_get_campaign_analytics_by_date
Retrieve campaign performance metrics for a specified date range to analyze email marketing effectiveness and track key engagement data.
Instructions
Fetch campaign analytics for a specific date range.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| campaign_id | Yes | ID of the campaign to fetch analytics for | |
| end_date | Yes | End date in YYYY-MM-DD format | |
| start_date | Yes | Start date in YYYY-MM-DD format |
Implementation Reference
- src/handlers/campaign.ts:501-541 (handler)The core handler function that validates input parameters using isGetCampaignAnalyticsByDateParams, extracts campaign_id and date params, makes a GET request to the Smartlead API endpoint `/campaigns/${campaign_id}/analytics-by-date`, and returns the formatted response or error.async function handleGetCampaignAnalyticsByDate( args: unknown, apiClient: AxiosInstance, withRetry: <T>(operation: () => Promise<T>, context: string) => Promise<T> ) { if (!isGetCampaignAnalyticsByDateParams(args)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid arguments for smartlead_get_campaign_analytics_by_date' ); } const { campaign_id, ...params } = args; try { const response = await withRetry( async () => apiClient.get(`/campaigns/${campaign_id}/analytics-by-date`, { params }), 'get campaign analytics by date' ); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], isError: false, }; } catch (error: any) { return { content: [{ type: 'text', text: `API Error: ${error.response?.data?.message || error.message}` }], isError: true, }; } }
- src/tools/campaign.ts:305-329 (schema)Defines the tool's metadata including name, description, category (CAMPAIGN_MANAGEMENT), and detailed inputSchema with properties for campaign_id (number), start_date and end_date (date strings), marking all as required.export const GET_CAMPAIGN_ANALYTICS_BY_DATE_TOOL: CategoryTool = { name: 'smartlead_get_campaign_analytics_by_date', description: 'Fetch campaign analytics for a specific date range.', category: ToolCategory.CAMPAIGN_MANAGEMENT, inputSchema: { type: 'object', properties: { campaign_id: { type: 'number', description: 'ID of the campaign to fetch analytics for', }, start_date: { type: 'string', format: 'date', description: 'Start date in YYYY-MM-DD format', }, end_date: { type: 'string', format: 'date', description: 'End date in YYYY-MM-DD format', }, }, required: ['campaign_id', 'start_date', 'end_date'], }, };
- src/index.ts:197-199 (registration)Registers the array of campaign tools (including this tool via campaignTools import) into the ToolRegistry if campaignManagement category is enabled in configuration. The registerTools() function is called at line 244.if (enabledCategories.campaignManagement) { toolRegistry.registerMany(campaignTools); }
- src/index.ts:346-348 (registration)In the main CallToolRequestHandler (lines 270-392), routes tools in CAMPAIGN_MANAGEMENT category to the specific handleCampaignTool dispatcher based on tool name.case ToolCategory.CAMPAIGN_MANAGEMENT: return await handleCampaignTool(name, toolArgs, apiClient, withRetry); // case ToolCategory.EMAIL_ACCOUNT_MANAGEMENT:
- src/handlers/campaign.ts:60-62 (handler)The dispatcher switch case in handleCampaignTool that routes to the specific handler function for this tool name.case 'smartlead_get_campaign_analytics_by_date': { return handleGetCampaignAnalyticsByDate(args, apiClient, withRetry); }