intermediate
Build an Analytics Dashboard
Use the analytics and CSAT endpoints to build a team performance dashboard showing ticket metrics, agent stats, and customer satisfaction.
Prerequisites
- A cStar account with a secret API key
- Some resolved tickets for data
1
Fetch the analytics overview
Get ticket, customer, and CSAT metrics for any time period.
import { CStarClient } from '@cstar.help/js';
const cstar = new CStarClient({
apiKey: process.env.CSTAR_SECRET_KEY,
teamId: process.env.CSTAR_TEAM_ID,
});
// Get this week's metrics
const { data: overview } = await cstar.analytics.overview({ period: 'week' });
console.log('Tickets this week:', overview.tickets.total);
console.log('Open:', overview.tickets.open);
console.log('Resolved:', overview.tickets.resolved);
console.log('CSAT:', overview.csat.average);2
Get per-agent performance
See how each agent is performing.
const { data: agents } = await cstar.analytics.agents({ period: 'week' });
for (const agent of agents) {
console.log(`${agent.name}: ${agent.ticketsResolved} resolved, ${agent.csatAverage} CSAT`);
}3
Add the game leaderboard
Show the gamification leaderboard alongside traditional metrics.
// Game leaderboard — unique to cStar
const { data: leaderboard } = await cstar.game.leaderboard({ period: 'weekly' });
for (const entry of leaderboard) {
console.log(`#${entry.rank} ${entry.name} — Level ${entry.level}, Score: ${entry.score}`);
}
// Boss status
const { data: boss } = await cstar.game.boss.current();
if (boss.active) {
console.log(`Active boss: ${boss.name} (${boss.healthPercent}% HP)`);
}