Analytics API
Access usage analytics, performance metrics, and query insights for your bots.
Get Bot Analytics
/analytics/bots/{agentId}/Get comprehensive analytics for a specific bot including query counts, response times, and popular questions.
Query Parameters
periodstringdefault: weekTime period: day, week, or month
Example Request
-purple-500">curl https://api.ragchats.ai/api/analytics/bots/AGENT_ID/?period=week \
-H -green-500">"Authorization: Bearer YOUR_TOKEN"Response
{
"totalQueries": 1250,
"averageLatencyMs": 890,
"successRate": 0.98,
"topQueries": [
{
"query": "What is the return policy?",
"count": 45
},
{
"query": "How do I track my order?",
"count": 38
},
{
"query": "What payment methods do you accept?",
"count": 32
},
{
"query": "How do I contact support?",
"count": 28
},
{
"query": "What are your shipping options?",
"count": 25
}
],
"queriesPerDay": [
{ "date": "2024-01-08", "count": 150 },
{ "date": "2024-01-09", "count": 175 },
{ "date": "2024-01-10", "count": 200 },
{ "date": "2024-01-11", "count": 180 },
{ "date": "2024-01-12", "count": 165 },
{ "date": "2024-01-13", "count": 190 },
{ "date": "2024-01-14", "count": 190 }
]
}Response Fields
BotAnalytics
totalQueriesintegerTotal number of queries in the period
averageLatencyMsnumberAverage response time in milliseconds
successRatenumberPercentage of successful responses (0-1)
topQueriesarrayMost frequently asked questions
querystringQuestion text
countintegerNumber of times asked
queriesPerDayarrayDaily query counts
datedateDate (YYYY-MM-DD)
countintegerQueries on that date
Understanding Metrics
Total Queries
The total number of queries sent to your bot during the selected period. This includes both successful and failed queries.
Average Latency
The average time in milliseconds from when a query is received to when the response is fully generated. This includes:
- Document retrieval time
- Reranking (if enabled)
- LLM response generation
Target: Under 2,000ms for good user experience.
Success Rate
The percentage of queries that returned a successful response. A query is considered successful if:
- No errors occurred
- Relevant context was found
- An answer was generated
Target: Above 95%.
Top Queries
The most frequently asked questions. Use this to:
- Identify common customer needs
- Ensure documentation covers these topics
- Improve answers for popular questions
Period Options
dayperiodLast 24 hours, hourly breakdown
weekperiodLast 7 days, daily breakdown
monthperiodLast 30 days, daily breakdown
Use Cases
Build a Dashboard
500">class=500">class="text-green-500">"text-muted-foreground">// Fetch analytics 500">for dashboard
500">async 500">function getAnalytics(agentId, period = 500">class="text-green-500">'week') {
500">const response = 500">await fetch(
500">class="text-green-500">`https:500">class="text-muted-foreground500">class="text-green-500">">//api.ragchats.ai/api/analytics/bots/${agentId}/?period=${period}`,
{
headers: { 500">class="text-green-500">"Authorization": 500">class="text-green-500">`Bearer ${token}` }
}
);
500">return response.json();
}
500">class=500">class="text-green-500">"text-muted-foreground">// Display metrics
500">const analytics = 500">await getAnalytics(500">class="text-green-500">'bot_123', 500">class="text-green-500">'week');
console.log(500">class="text-green-500">`Queries 500">this week: ${analytics.totalQueries}`);
console.log(500">class="text-green-500">`Avg latency: ${analytics.averageLatencyMs}ms`);
console.log(500">class="text-green-500">`Success rate: ${(analytics.successRate * 100).toFixed(1)}%`);Monitor Performance
500">class=500">class="text-green-500">"text-muted-foreground">// Alert 500">if latency is too high
500">const analytics = 500">await getAnalytics(500">class="text-green-500">'bot_123');
500">if (analytics.averageLatencyMs > 3000) {
sendAlert(500">class="text-green-500">'Bot latency is high: ' + analytics.averageLatencyMs + 500">class="text-green-500">'ms');
}
500">if (analytics.successRate < 0.95) {
sendAlert(500">class="text-green-500">'Bot success rate dropped to ' + (analytics.successRate * 100) + 500">class="text-green-500">'%');
}Identify Content Gaps
500">class=500">class="text-green-500">"text-muted-foreground">// Find questions that might need better documentation
500">const analytics = 500">await getAnalytics(500">class="text-green-500">'bot_123', 500">class="text-green-500">'month');
console.log(500">class="text-green-500">'Top questions to review:');
analytics.topQueries.slice(0, 10).forEach((q, i) => {
console.log(500">class="text-green-500">`${i + 1}. "${q.query}500">class="text-green-500">" (asked ${q.count} times)`);
});
