Request
const res = await fetch("/api/analytics/heartbeat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
sessionId,
currentTimeSeconds: 134.56,
eventType: "heartbeat",
segments: [{
startSecond: 12.34,
endSecond: 78.90,
playbackRate: 1.0,
clientSegmentId: "0f9c...",
wallClockSeconds: 66.56,
segmentStartedAt: "2026-10-22T09:12:03.114Z",
segmentEndedAt: "2026-10-22T09:13:09.674Z",
}],
counts: { play: 1, pause: 0, seek: 0, ratechange: 0 },
}),
});
Response
{
"ok": true,
"segmentsReceived": 3,
"acceptedSegmentIds": ["a", "b"],
"duplicateSegmentIds": ["c"],
"rejectedSegments": [],
"summary": {
"videoDurationSeconds": 600,
"totalWatchedSeconds": 300,
"uniqueWatchedSeconds": 280,
"repeatWatchedSeconds": 20,
"completionPercentage": 46.67
}
}