Update session replay payload to use { type, payload } format

This commit is contained in:
Mike Cao
2026-03-23 16:30:53 -07:00
parent aea373ca56
commit 7582aed67b
3 changed files with 14 additions and 7 deletions
+7 -4
View File
@@ -16,9 +16,12 @@ interface Cache {
} }
const schema = z.object({ const schema = z.object({
website: z.uuid(), type: z.literal('record'),
events: z.array(z.any()).max(200), payload: z.object({
timestamp: z.coerce.number().int().optional(), website: z.uuid(),
events: z.array(z.any()).max(200),
timestamp: z.coerce.number().int().optional(),
}),
}); });
export async function POST(request: Request) { export async function POST(request: Request) {
@@ -29,7 +32,7 @@ export async function POST(request: Request) {
return error(); return error();
} }
const { website: websiteId, events, timestamp } = body; const { website: websiteId, events, timestamp } = body.payload;
if (!events?.length) { if (!events?.length) {
return json({ ok: true }); return json({ ok: true });
+1
View File
@@ -99,6 +99,7 @@ export const COLLECTION_TYPE = {
event: 'event', event: 'event',
identify: 'identify', identify: 'identify',
performance: 'performance', performance: 'performance',
record: 'record',
} as const; } as const;
export const WEB_VITALS_THRESHOLDS = { export const WEB_VITALS_THRESHOLDS = {
+6 -3
View File
@@ -39,9 +39,12 @@ import { record } from 'rrweb';
if (!session?.cache) return; if (!session?.cache) return;
const body = JSON.stringify({ const body = JSON.stringify({
website, type: 'record',
events, payload: {
timestamp: Math.floor(Date.now() / 1000), website,
events,
timestamp: Math.floor(Date.now() / 1000),
},
}); });
// keepalive has a 64KB body limit — only use it for small payloads on unload // keepalive has a 64KB body limit — only use it for small payloads on unload