Programmatically analyze chat usage and user engagement data
The Chat Analytics API provides direct access to analyze chat usage patterns, user engagement metrics, and export analytics data. These endpoints allow you to build custom analytics dashboards or integrate chat metrics into your existing reporting systems.
// Get analytics for a specific componentconst componentAnalytics = await client.v1.chatAnalytics.getComponent({ componentId: 'chat-component-789', startDate: new Date('2024-01-01'), endDate: new Date('2024-01-31'), userId: 'user-456', // Optional: filter by user groupIds: ['group-1'], // Optional: filter by groups modelKey: 'gpt-4.1-2025-04-14' // Optional: filter by model});console.log(`Component: ${componentAnalytics.componentId}`);console.log(`Total messages: ${componentAnalytics.summary.totalMessages}`);console.log(`Natural language summary: ${componentAnalytics.summary.summary}`);// User-level statistics for this componentcomponentAnalytics.userStats.forEach(stat => { console.log(`User ${stat.userId}: ${stat.totalMessages} messages`);});