Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Merge branch 'dev' of https://github.com/umami-software/umami into dev

Mike Caob389c417de84
diff --cc prisma/schema.prisma
index 92cdc649b,59fad07ee..2783fe229
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@@ -397,8 -397,8 +397,9 @@@ model SessionReplay
@@index([websiteId])
@@index([sessionId])
+ @@index([visitId])
@@index([websiteId, sessionId])
+ @@index([websiteId, visitId])
@@index([websiteId, createdAt])
@@index([sessionId, chunkIndex])
@@map("session_replay")
diff --cc src/app/api/record/route.ts
index b47e95f0d,9ab25f1c4..390b25b49
--- a/src/app/api/record/route.ts
+++ b/src/app/api/record/route.ts
@@@ -8,13 -7,8 +7,13 @@@ import { parseToken } from '@/lib/jwt'
import { parseRequest } from '@/lib/request';
import { badRequest, forbidden, json, serverError } from '@/lib/response';
import { getWebsite } from '@/queries/prisma';
- import { saveReplayChunk } from '@/queries/sql';
+ import { saveRecording } from '@/queries/sql';
+interface Cache {
+ sessionId: string;
+ visitId: string;
+}
+
const schema = z.object({
website: z.uuid(),
events: z.array(z.any()).max(200),
@@@ -74,20 -68,12 +73,16 @@@ export async function POST(request: Req
// Compute timestamps from events
const eventTimestamps = events
- .map((e: any) => e.timestamp)
- .filter((t: any) => typeof t === 'number');
+ .map((e: any) => Number(e?.timestamp))
+ .filter((t: number) => Number.isFinite(t) && t > 0);
+
+ const fallbackMs = (timestamp || Math.floor(Date.now() / 1000)) * 1000;
+ const minTimestamp = eventTimestamps.length ? Math.min(...eventTimestamps) : fallbackMs;
+ const maxTimestamp = eventTimestamps.length ? Math.max(...eventTimestamps) : fallbackMs;
- const startedAt = new Date(Math.min(...eventTimestamps));
- const endedAt = new Date(Math.max(...eventTimestamps));
+ const startedAt = new Date(minTimestamp);
+ const endedAt = new Date(maxTimestamp);
- // Compress events
- const eventsJson = JSON.stringify(events);
- const compressed = gzipSync(Buffer.from(eventsJson, 'utf-8'));
-
// Use timestamp-based chunk index for ordering
const chunkIndex = timestamp || Math.floor(Date.now() / 1000);
diff --cc src/recorder/index.js
index ad964a858,ce40b0b87..4d670ac4b
--- a/src/recorder/index.js
+++ b/src/recorder/index.js
@@@ -7,14 -7,13 +7,14 @@@ import { record } from 'rrweb'
const _data = 'data-';
const attr = currentScript.getAttribute.bind(currentScript);
-
- const website = attr(`${_data}website-id`);
- const hostUrl = attr(`${_data}host-url`);
- const sampleRate = parseFloat(attr(`${_data}sample-rate`) || '0.15');
- const maskLevel = attr(`${_data}mask-level`) || 'moderate';
- const maxDuration = parseInt(attr(`${_data}max-duration`) || '300000', 10);
- const blockSelector = attr(`${_data}block-selector`) || '';
+ const config = value => attr(`${_data}${value}`);
+
+ const website = config(`website-id`);
+ const hostUrl = config(`host-url`);
+ const sampleRate = parseFloat(config(`sample-rate`) || '0.15');
- const maskLevel = config(`mask-level`) || 'strict';
++ const maskLevel = config(`mask-level`) || 'moderate';
+ const maxDuration = parseInt(config(`max-duration`) || '300000', 10);
+ const blockSelector = config(`block-selector`) || '';
if (!website) return;