first pass for self-hosted heatmap rrweb
This commit is contained in:
1 parent
475d9548de
commit
b51e4b5d12
8 files changed
+600
-33
No files matched your search
@@ -0,0 +1,38 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "heatmap_snapshot" ALTER COLUMN "created_at" DROP NOT NULL;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "heatmap_replay_preview" (
|
||||||
|
"preview_id" UUID NOT NULL,
|
||||||
|
"website_id" UUID NOT NULL,
|
||||||
|
"session_id" UUID NOT NULL,
|
||||||
|
"visit_id" UUID NOT NULL,
|
||||||
|
"url_path" VARCHAR(500) NOT NULL,
|
||||||
|
"viewport_w" INTEGER NOT NULL,
|
||||||
|
"viewport_h" INTEGER NOT NULL,
|
||||||
|
"replay_chunk_index" INTEGER NOT NULL,
|
||||||
|
"replay_event_index" INTEGER NOT NULL,
|
||||||
|
"replay_time_ms" BIGINT,
|
||||||
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMPTZ(6),
|
||||||
|
|
||||||
|
CONSTRAINT "heatmap_replay_preview_pkey" PRIMARY KEY ("preview_id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "heatmap_replay_preview_website_id_idx" ON "heatmap_replay_preview"("website_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "heatmap_replay_preview_visit_id_idx" ON "heatmap_replay_preview"("visit_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "heatmap_replay_preview_website_id_url_path_idx" ON "heatmap_replay_preview"("website_id", "url_path");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "heatmap_replay_preview_website_id_url_path_viewport_w_viewp_key" ON "heatmap_replay_preview"("website_id", "url_path", "viewport_w", "viewport_h");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "session_replay_visit_id_idx" ON "session_replay"("visit_id");
|
||||||
|
|
||||||
|
-- RenameIndex
|
||||||
|
ALTER INDEX "heatmap_event_website_id_visit_id_replay_chunk_index_replay_eve" RENAME TO "heatmap_event_website_id_visit_id_replay_chunk_index_replay_idx";
|
||||||
@@ -89,6 +89,7 @@ model Website {
|
|||||||
sessionReplays SessionReplay[]
|
sessionReplays SessionReplay[]
|
||||||
sessionReplaysSaved SessionReplaySaved[]
|
sessionReplaysSaved SessionReplaySaved[]
|
||||||
heatmapEvents HeatmapEvent[]
|
heatmapEvents HeatmapEvent[]
|
||||||
|
heatmapReplayPreviews HeatmapReplayPreview[]
|
||||||
heatmapSnapshots HeatmapSnapshot[]
|
heatmapSnapshots HeatmapSnapshot[]
|
||||||
|
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
@@ -434,6 +435,29 @@ model HeatmapEvent {
|
|||||||
@@map("heatmap_event")
|
@@map("heatmap_event")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model HeatmapReplayPreview {
|
||||||
|
id String @id() @map("preview_id") @db.Uuid
|
||||||
|
websiteId String @map("website_id") @db.Uuid
|
||||||
|
sessionId String @map("session_id") @db.Uuid
|
||||||
|
visitId String @map("visit_id") @db.Uuid
|
||||||
|
urlPath String @map("url_path") @db.VarChar(500)
|
||||||
|
viewportW Int @map("viewport_w") @db.Integer
|
||||||
|
viewportH Int @map("viewport_h") @db.Integer
|
||||||
|
replayChunkIndex Int @map("replay_chunk_index") @db.Integer
|
||||||
|
replayEventIndex Int @map("replay_event_index") @db.Integer
|
||||||
|
replayTimeMs BigInt? @map("replay_time_ms") @db.BigInt
|
||||||
|
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||||
|
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||||
|
|
||||||
|
website Website @relation(fields: [websiteId], references: [id])
|
||||||
|
|
||||||
|
@@unique([websiteId, urlPath, viewportW, viewportH])
|
||||||
|
@@index([websiteId])
|
||||||
|
@@index([visitId])
|
||||||
|
@@index([websiteId, urlPath])
|
||||||
|
@@map("heatmap_replay_preview")
|
||||||
|
}
|
||||||
|
|
||||||
model HeatmapSnapshot {
|
model HeatmapSnapshot {
|
||||||
id String @id() @map("snapshot_id") @db.Uuid
|
id String @id() @map("snapshot_id") @db.Uuid
|
||||||
websiteId String @map("website_id") @db.Uuid
|
websiteId String @map("website_id") @db.Uuid
|
||||||
|
|||||||
@@ -168,6 +168,28 @@
|
|||||||
-webkit-user-drag: none;
|
-webkit-user-drag: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.snapshotFrame {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.snapshotFrame :global(.replayer-wrapper) {
|
||||||
|
width: 100% !important;
|
||||||
|
height: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.snapshotFrame :global(.replayer-mouse),
|
||||||
|
.snapshotFrame :global(.replayer-mouse-tail) {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.snapshotFrame :global(iframe) {
|
||||||
|
width: 100% !important;
|
||||||
|
height: 100% !important;
|
||||||
|
border: 0;
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
.overlay {
|
.overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { Column, Grid, Heading, Loading, Row, Switch, Text } from '@umami/react-zen';
|
import { Column, Grid, Heading, Loading, Row, Switch, Text } from '@umami/react-zen';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||||
import { useResultQuery } from '@/components/hooks';
|
import { useReplayQuery, useResultQuery } from '@/components/hooks';
|
||||||
import { getClientAuthToken } from '@/lib/client';
|
import { getClientAuthToken } from '@/lib/client';
|
||||||
import { formatLongNumber } from '@/lib/format';
|
import { formatLongNumber } from '@/lib/format';
|
||||||
import type { HeatmapMode, HeatmapPoint, HeatmapResult, HeatmapSnapshot } from '@/queries/sql';
|
import type { HeatmapMode, HeatmapPoint, HeatmapResult, HeatmapSnapshot } from '@/queries/sql';
|
||||||
@@ -111,6 +111,7 @@ export function Heatmap({ websiteId, urlPath, onUrlPathChange, mode, search }: H
|
|||||||
{urlPath ? (
|
{urlPath ? (
|
||||||
mode === 'scroll' ? (
|
mode === 'scroll' ? (
|
||||||
<ScrollHeatmapView
|
<ScrollHeatmapView
|
||||||
|
websiteId={websiteId}
|
||||||
urlPath={urlPath}
|
urlPath={urlPath}
|
||||||
scroll={scroll}
|
scroll={scroll}
|
||||||
snapshot={snapshot}
|
snapshot={snapshot}
|
||||||
@@ -118,6 +119,7 @@ export function Heatmap({ websiteId, urlPath, onUrlPathChange, mode, search }: H
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ClickHeatmapView
|
<ClickHeatmapView
|
||||||
|
websiteId={websiteId}
|
||||||
urlPath={urlPath}
|
urlPath={urlPath}
|
||||||
points={points}
|
points={points}
|
||||||
snapshot={snapshot}
|
snapshot={snapshot}
|
||||||
@@ -232,11 +234,13 @@ function pickViewport(points: HeatmapPoint[]): ViewportBucket | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ClickHeatmapView({
|
function ClickHeatmapView({
|
||||||
|
websiteId,
|
||||||
urlPath,
|
urlPath,
|
||||||
points,
|
points,
|
||||||
snapshot,
|
snapshot,
|
||||||
isLoading,
|
isLoading,
|
||||||
}: {
|
}: {
|
||||||
|
websiteId: string;
|
||||||
urlPath: string;
|
urlPath: string;
|
||||||
points: HeatmapPoint[];
|
points: HeatmapPoint[];
|
||||||
snapshot: HeatmapSnapshot | null;
|
snapshot: HeatmapSnapshot | null;
|
||||||
@@ -262,11 +266,11 @@ function ClickHeatmapView({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const handleSnapshotReady = useCallback(() => setSnapshotReady(true), []);
|
const handleSnapshotReady = useCallback(() => setSnapshotReady(true), []);
|
||||||
const hasSnapshotImage = Boolean(snapshot?.imageUrl);
|
const hasSnapshot = Boolean(snapshot);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSnapshotReady(!(showPage && hasSnapshotImage));
|
setSnapshotReady(!(showPage && hasSnapshot));
|
||||||
}, [hasSnapshotImage, showPage, snapshot?.id]);
|
}, [hasSnapshot, showPage, snapshot?.id]);
|
||||||
const overlayGutter = Math.max(48, Math.round((viewport?.width ?? 1920) * 0.04));
|
const overlayGutter = Math.max(48, Math.round((viewport?.width ?? 1920) * 0.04));
|
||||||
const maxPointX = visible.reduce((max, point) => Math.max(max, point.pageX), 0);
|
const maxPointX = visible.reduce((max, point) => Math.max(max, point.pageX), 0);
|
||||||
const maxPointY = visible.reduce((max, point) => Math.max(max, point.pageY), 0);
|
const maxPointY = visible.reduce((max, point) => Math.max(max, point.pageY), 0);
|
||||||
@@ -278,7 +282,7 @@ function ClickHeatmapView({
|
|||||||
const canvasWidth = hasMeasuredWidth ? `min(100%, ${renderWidth}px)` : '100%';
|
const canvasWidth = hasMeasuredWidth ? `min(100%, ${renderWidth}px)` : '100%';
|
||||||
const overlayPageW = snapshot?.pageW ?? viewport?.pageW ?? baseWidth;
|
const overlayPageW = snapshot?.pageW ?? viewport?.pageW ?? baseWidth;
|
||||||
const overlayPageH = snapshot?.pageH ?? viewport?.pageH ?? baseHeight;
|
const overlayPageH = snapshot?.pageH ?? viewport?.pageH ?? baseHeight;
|
||||||
const showSnapshot = renderWidth > 0 && showPage && hasSnapshotImage;
|
const showSnapshot = renderWidth > 0 && showPage && hasSnapshot;
|
||||||
const showOverlay = !showSnapshot || snapshotReady;
|
const showOverlay = !showSnapshot || snapshotReady;
|
||||||
const totalClicks = visible.reduce((sum, point) => sum + point.count, 0);
|
const totalClicks = visible.reduce((sum, point) => sum + point.count, 0);
|
||||||
const showLoading = isLoading;
|
const showLoading = isLoading;
|
||||||
@@ -313,7 +317,7 @@ function ClickHeatmapView({
|
|||||||
)}
|
)}
|
||||||
</Column>
|
</Column>
|
||||||
|
|
||||||
{showPage && snapshot?.status === 'failed' && (
|
{showPage && snapshot?.kind === 'image' && snapshot.status === 'failed' && (
|
||||||
<Text color="muted" className={styles.snapshotMessage}>
|
<Text color="muted" className={styles.snapshotMessage}>
|
||||||
{SNAPSHOT_UNAVAILABLE_ERROR}
|
{SNAPSHOT_UNAVAILABLE_ERROR}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -336,8 +340,12 @@ function ClickHeatmapView({
|
|||||||
<>
|
<>
|
||||||
<div className={styles.snapshotClip}>
|
<div className={styles.snapshotClip}>
|
||||||
{showSnapshot && !snapshotReady && <CanvasLoading />}
|
{showSnapshot && !snapshotReady && <CanvasLoading />}
|
||||||
{showSnapshot && snapshot?.imageUrl && (
|
{showSnapshot && snapshot && (
|
||||||
<SnapshotImage snapshot={snapshot} onReady={handleSnapshotReady} />
|
<SnapshotPreview
|
||||||
|
websiteId={websiteId}
|
||||||
|
snapshot={snapshot}
|
||||||
|
onReady={handleSnapshotReady}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{showOverlay && (
|
{showOverlay && (
|
||||||
@@ -382,7 +390,7 @@ function ClickHeatmapView({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasSnapshotImage && (
|
{hasSnapshot && (
|
||||||
<Row justifyContent="center" className={styles.snapshotControlRow}>
|
<Row justifyContent="center" className={styles.snapshotControlRow}>
|
||||||
<Switch isSelected={showPage} onChange={setShowPage}>
|
<Switch isSelected={showPage} onChange={setShowPage}>
|
||||||
Show page
|
Show page
|
||||||
@@ -394,11 +402,13 @@ function ClickHeatmapView({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ScrollHeatmapView({
|
function ScrollHeatmapView({
|
||||||
|
websiteId,
|
||||||
urlPath,
|
urlPath,
|
||||||
scroll,
|
scroll,
|
||||||
snapshot,
|
snapshot,
|
||||||
isLoading,
|
isLoading,
|
||||||
}: {
|
}: {
|
||||||
|
websiteId: string;
|
||||||
urlPath: string;
|
urlPath: string;
|
||||||
scroll: HeatmapResult['scroll'] | undefined;
|
scroll: HeatmapResult['scroll'] | undefined;
|
||||||
snapshot: HeatmapSnapshot | null;
|
snapshot: HeatmapSnapshot | null;
|
||||||
@@ -407,11 +417,11 @@ function ScrollHeatmapView({
|
|||||||
const [showPage, setShowPage] = useState(true);
|
const [showPage, setShowPage] = useState(true);
|
||||||
const [snapshotReady, setSnapshotReady] = useState(false);
|
const [snapshotReady, setSnapshotReady] = useState(false);
|
||||||
const handleSnapshotReady = useCallback(() => setSnapshotReady(true), []);
|
const handleSnapshotReady = useCallback(() => setSnapshotReady(true), []);
|
||||||
const hasSnapshotImage = Boolean(snapshot?.imageUrl);
|
const hasSnapshot = Boolean(snapshot);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSnapshotReady(!(showPage && hasSnapshotImage));
|
setSnapshotReady(!(showPage && hasSnapshot));
|
||||||
}, [hasSnapshotImage, showPage, snapshot?.id]);
|
}, [hasSnapshot, showPage, snapshot?.id]);
|
||||||
const {
|
const {
|
||||||
buckets = [],
|
buckets = [],
|
||||||
totalSessions = 0,
|
totalSessions = 0,
|
||||||
@@ -426,7 +436,7 @@ function ScrollHeatmapView({
|
|||||||
const renderHeight = snapshot?.pageH ?? baseHeight;
|
const renderHeight = snapshot?.pageH ?? baseHeight;
|
||||||
const hasMeasuredWidth = Boolean(snapshot?.pageW || pageW);
|
const hasMeasuredWidth = Boolean(snapshot?.pageW || pageW);
|
||||||
const canvasWidth = hasMeasuredWidth ? `min(100%, ${renderWidth}px)` : '100%';
|
const canvasWidth = hasMeasuredWidth ? `min(100%, ${renderWidth}px)` : '100%';
|
||||||
const showSnapshot = renderWidth > 0 && showPage && hasSnapshotImage;
|
const showSnapshot = renderWidth > 0 && showPage && hasSnapshot;
|
||||||
const showOverlay = !showSnapshot || snapshotReady;
|
const showOverlay = !showSnapshot || snapshotReady;
|
||||||
const hasScrollData = Boolean(scroll && totalSessions > 0 && pageW && pageH && viewportW);
|
const hasScrollData = Boolean(scroll && totalSessions > 0 && pageW && pageH && viewportW);
|
||||||
const showLoading = isLoading;
|
const showLoading = isLoading;
|
||||||
@@ -478,7 +488,7 @@ function ScrollHeatmapView({
|
|||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{showPage && snapshot?.status === 'failed' && (
|
{showPage && snapshot?.kind === 'image' && snapshot.status === 'failed' && (
|
||||||
<Text color="muted" className={styles.snapshotMessage}>
|
<Text color="muted" className={styles.snapshotMessage}>
|
||||||
{SNAPSHOT_UNAVAILABLE_ERROR}
|
{SNAPSHOT_UNAVAILABLE_ERROR}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -500,8 +510,12 @@ function ScrollHeatmapView({
|
|||||||
) : (
|
) : (
|
||||||
<div className={styles.canvasClip}>
|
<div className={styles.canvasClip}>
|
||||||
{showSnapshot && !snapshotReady && <CanvasLoading />}
|
{showSnapshot && !snapshotReady && <CanvasLoading />}
|
||||||
{showSnapshot && snapshot?.imageUrl && (
|
{showSnapshot && snapshot && (
|
||||||
<SnapshotImage snapshot={snapshot} onReady={handleSnapshotReady} />
|
<SnapshotPreview
|
||||||
|
websiteId={websiteId}
|
||||||
|
snapshot={snapshot}
|
||||||
|
onReady={handleSnapshotReady}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{showOverlay && (
|
{showOverlay && (
|
||||||
<div className={styles.overlay}>
|
<div className={styles.overlay}>
|
||||||
@@ -536,7 +550,7 @@ function ScrollHeatmapView({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasSnapshotImage && (
|
{hasSnapshot && (
|
||||||
<Row justifyContent="center" className={styles.snapshotControlRow}>
|
<Row justifyContent="center" className={styles.snapshotControlRow}>
|
||||||
<Switch isSelected={showPage} onChange={setShowPage}>
|
<Switch isSelected={showPage} onChange={setShowPage}>
|
||||||
Show page
|
Show page
|
||||||
@@ -547,11 +561,28 @@ function ScrollHeatmapView({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SnapshotPreview({
|
||||||
|
websiteId,
|
||||||
|
snapshot,
|
||||||
|
onReady,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
snapshot: HeatmapSnapshot;
|
||||||
|
onReady: () => void;
|
||||||
|
}) {
|
||||||
|
if (snapshot.kind === 'replay') {
|
||||||
|
return <ReplaySnapshot websiteId={websiteId} snapshot={snapshot} onReady={onReady} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <SnapshotImage snapshot={snapshot} onReady={onReady} />;
|
||||||
|
}
|
||||||
|
|
||||||
function SnapshotImage({ snapshot, onReady }: { snapshot: HeatmapSnapshot; onReady: () => void }) {
|
function SnapshotImage({ snapshot, onReady }: { snapshot: HeatmapSnapshot; onReady: () => void }) {
|
||||||
const [src, setSrc] = useState<string | null>(null);
|
const [src, setSrc] = useState<string | null>(null);
|
||||||
|
const imageUrl = snapshot.kind === 'image' ? snapshot.imageUrl : null;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!snapshot.imageUrl) {
|
if (snapshot.kind !== 'image' || !imageUrl) {
|
||||||
setSrc(null);
|
setSrc(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -562,7 +593,7 @@ function SnapshotImage({ snapshot, onReady }: { snapshot: HeatmapSnapshot; onRea
|
|||||||
|
|
||||||
setSrc(null);
|
setSrc(null);
|
||||||
|
|
||||||
fetch(snapshot.imageUrl, {
|
fetch(imageUrl, {
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
headers: {
|
headers: {
|
||||||
...(token ? { authorization: `Bearer ${token}` } : {}),
|
...(token ? { authorization: `Bearer ${token}` } : {}),
|
||||||
@@ -589,7 +620,7 @@ function SnapshotImage({ snapshot, onReady }: { snapshot: HeatmapSnapshot; onRea
|
|||||||
URL.revokeObjectURL(objectUrl);
|
URL.revokeObjectURL(objectUrl);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [snapshot.id, snapshot.imageUrl]);
|
}, [imageUrl, onReady, snapshot.id, snapshot.kind]);
|
||||||
|
|
||||||
const handleLoad = useCallback(() => onReady(), [onReady]);
|
const handleLoad = useCallback(() => onReady(), [onReady]);
|
||||||
|
|
||||||
@@ -606,6 +637,85 @@ function SnapshotImage({ snapshot, onReady }: { snapshot: HeatmapSnapshot; onRea
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ReplaySnapshot({
|
||||||
|
websiteId,
|
||||||
|
snapshot,
|
||||||
|
onReady,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
snapshot: Extract<HeatmapSnapshot, { kind: 'replay' }>;
|
||||||
|
onReady: () => void;
|
||||||
|
}) {
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const replayerRef = useRef<any>(null);
|
||||||
|
const { data: replay, isLoading } = useReplayQuery(websiteId, snapshot.replayId, {
|
||||||
|
until: snapshot.replayTimeMs ?? undefined,
|
||||||
|
chunkIndex: snapshot.chunkIndex,
|
||||||
|
eventIndex: snapshot.eventIndex,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!replay?.events?.length || !containerRef.current) {
|
||||||
|
onReady();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cancelled = false;
|
||||||
|
|
||||||
|
import('rrweb')
|
||||||
|
.then(mod => {
|
||||||
|
if (cancelled || !containerRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
containerRef.current.innerHTML = '';
|
||||||
|
|
||||||
|
const replayer = new mod.Replayer(replay.events, {
|
||||||
|
root: containerRef.current,
|
||||||
|
loadTimeout: 0,
|
||||||
|
mouseTail: false,
|
||||||
|
pauseAnimation: true,
|
||||||
|
showWarning: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
replayerRef.current = replayer;
|
||||||
|
|
||||||
|
const firstTimestamp = Number(replay.events[0]?.timestamp ?? 0);
|
||||||
|
const lastTimestamp = Number(replay.events[replay.events.length - 1]?.timestamp ?? 0);
|
||||||
|
const timeOffset = Math.max(0, lastTimestamp - firstTimestamp);
|
||||||
|
|
||||||
|
replayer.pause(timeOffset);
|
||||||
|
replayer.wrapper.style.width = '100%';
|
||||||
|
replayer.wrapper.style.height = '100%';
|
||||||
|
replayer.wrapper.style.pointerEvents = 'none';
|
||||||
|
replayer.wrapper.style.overflow = 'hidden';
|
||||||
|
replayer.iframe.style.display = 'block';
|
||||||
|
replayer.iframe.style.width = '100%';
|
||||||
|
replayer.iframe.style.height = '100%';
|
||||||
|
replayer.iframe.style.border = '0';
|
||||||
|
|
||||||
|
onReady();
|
||||||
|
})
|
||||||
|
.catch(() => onReady());
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
replayerRef.current?.destroy?.();
|
||||||
|
replayerRef.current = null;
|
||||||
|
};
|
||||||
|
}, [isLoading, onReady, replay?.events, snapshot.id]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.snapshot}>
|
||||||
|
<div ref={containerRef} className={styles.snapshotFrame} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function CanvasLoading() {
|
function CanvasLoading() {
|
||||||
return (
|
return (
|
||||||
<div className={styles.canvasLoading}>
|
<div className={styles.canvasLoading}>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const SNAPSHOT_ERROR_MAX_LENGTH = 500;
|
|||||||
export type HeatmapSnapshotStatus = (typeof SNAPSHOT_STATUS)[keyof typeof SNAPSHOT_STATUS];
|
export type HeatmapSnapshotStatus = (typeof SNAPSHOT_STATUS)[keyof typeof SNAPSHOT_STATUS];
|
||||||
|
|
||||||
export interface HeatmapSnapshotImage {
|
export interface HeatmapSnapshotImage {
|
||||||
|
kind: 'image';
|
||||||
id: string;
|
id: string;
|
||||||
imageUrl: string | null;
|
imageUrl: string | null;
|
||||||
status: HeatmapSnapshotStatus;
|
status: HeatmapSnapshotStatus;
|
||||||
@@ -331,6 +332,7 @@ function getSnapshotImageUrl(websiteId: string, snapshotId: string) {
|
|||||||
|
|
||||||
function mapSnapshot(websiteId: string, row: SnapshotRecord): HeatmapSnapshotImage {
|
function mapSnapshot(websiteId: string, row: SnapshotRecord): HeatmapSnapshotImage {
|
||||||
return {
|
return {
|
||||||
|
kind: 'image',
|
||||||
id: row.id,
|
id: row.id,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
row.status === SNAPSHOT_STATUS.ready && row.hasImage
|
row.status === SNAPSHOT_STATUS.ready && row.hasImage
|
||||||
@@ -599,16 +601,12 @@ function getSnapshotErrorMessage(error: unknown) {
|
|||||||
async function createSnapshotBrowser() {
|
async function createSnapshotBrowser() {
|
||||||
const endpoint = process.env.PLAYWRIGHT_URL?.trim();
|
const endpoint = process.env.PLAYWRIGHT_URL?.trim();
|
||||||
|
|
||||||
if (endpoint) {
|
if (!endpoint) {
|
||||||
const { chromium } = await import('playwright-core');
|
return null;
|
||||||
return chromium.connect(endpoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { chromium } = await import('@playwright/test');
|
const { chromium } = await import('playwright-core');
|
||||||
return chromium.launch({
|
return chromium.connect(endpoint);
|
||||||
channel: 'chromium',
|
|
||||||
headless: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function captureSnapshot(
|
async function captureSnapshot(
|
||||||
@@ -618,6 +616,11 @@ async function captureSnapshot(
|
|||||||
pageW?: number,
|
pageW?: number,
|
||||||
): Promise<CaptureResult> {
|
): Promise<CaptureResult> {
|
||||||
const browser = await createSnapshotBrowser();
|
const browser = await createSnapshotBrowser();
|
||||||
|
|
||||||
|
if (!browser) {
|
||||||
|
throw new Error(SNAPSHOT_UNAVAILABLE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
const initialViewportW = viewportW;
|
const initialViewportW = viewportW;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -698,6 +701,10 @@ export async function ensureHeatmapSnapshot({
|
|||||||
return mapSnapshot(websiteId, existing);
|
return mapSnapshot(websiteId, existing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!process.env.PLAYWRIGHT_URL?.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const updatedAt = existing?.updatedAt ? new Date(existing.updatedAt) : null;
|
const updatedAt = existing?.updatedAt ? new Date(existing.updatedAt) : null;
|
||||||
const ageMs = updatedAt ? Date.now() - updatedAt.getTime() : Number.POSITIVE_INFINITY;
|
const ageMs = updatedAt ? Date.now() - updatedAt.getTime() : Number.POSITIVE_INFINITY;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
type HeatmapSnapshotImage,
|
type HeatmapSnapshotImage,
|
||||||
shouldSkipSnapshot,
|
shouldSkipSnapshot,
|
||||||
} from './ensureHeatmapSnapshot';
|
} from './ensureHeatmapSnapshot';
|
||||||
|
import { getHeatmapReplayPreview } from './getHeatmapReplayPreview';
|
||||||
|
|
||||||
const FUNCTION_NAME = 'getHeatmap';
|
const FUNCTION_NAME = 'getHeatmap';
|
||||||
|
|
||||||
@@ -47,7 +48,20 @@ export interface HeatmapScrollBucket {
|
|||||||
sessions: number;
|
sessions: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HeatmapSnapshot = HeatmapSnapshotImage;
|
export interface HeatmapSnapshotReplay {
|
||||||
|
kind: 'replay';
|
||||||
|
id: string;
|
||||||
|
replayId: string;
|
||||||
|
chunkIndex: number;
|
||||||
|
eventIndex: number;
|
||||||
|
replayTimeMs: number | null;
|
||||||
|
pageW: number;
|
||||||
|
pageH: number;
|
||||||
|
viewportW: number;
|
||||||
|
viewportH: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type HeatmapSnapshot = HeatmapSnapshotImage | HeatmapSnapshotReplay;
|
||||||
|
|
||||||
export interface HeatmapResult {
|
export interface HeatmapResult {
|
||||||
mode: HeatmapMode;
|
mode: HeatmapMode;
|
||||||
@@ -194,7 +208,7 @@ async function relationalQuery(
|
|||||||
viewportW: dim?.viewportW ?? null,
|
viewportW: dim?.viewportW ?? null,
|
||||||
viewportH: dim?.viewportH ?? null,
|
viewportH: dim?.viewportH ?? null,
|
||||||
};
|
};
|
||||||
const snapshot = await ensureHeatmapSnapshot({
|
const snapshot = await resolveHeatmapSnapshot({
|
||||||
websiteId,
|
websiteId,
|
||||||
urlPath,
|
urlPath,
|
||||||
viewportW: scroll.viewportW,
|
viewportW: scroll.viewportW,
|
||||||
@@ -258,7 +272,7 @@ async function relationalQuery(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const viewport = pickSnapshotViewport(rawPoints);
|
const viewport = pickSnapshotViewport(rawPoints);
|
||||||
const snapshot = await ensureHeatmapSnapshot({
|
const snapshot = await resolveHeatmapSnapshot({
|
||||||
websiteId,
|
websiteId,
|
||||||
urlPath,
|
urlPath,
|
||||||
viewportW: viewport?.width ?? null,
|
viewportW: viewport?.width ?? null,
|
||||||
@@ -510,6 +524,52 @@ function emptyScroll(): HeatmapResult['scroll'] {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveHeatmapSnapshot({
|
||||||
|
websiteId,
|
||||||
|
urlPath,
|
||||||
|
viewportW,
|
||||||
|
viewportH,
|
||||||
|
pageW,
|
||||||
|
pageH,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
urlPath: string;
|
||||||
|
viewportW: number | null;
|
||||||
|
viewportH: number | null;
|
||||||
|
pageW: number | null;
|
||||||
|
pageH: number | null;
|
||||||
|
}): Promise<HeatmapSnapshot | null> {
|
||||||
|
if (process.env.PLAYWRIGHT_URL?.trim()) {
|
||||||
|
return ensureHeatmapSnapshot({
|
||||||
|
websiteId,
|
||||||
|
urlPath,
|
||||||
|
viewportW,
|
||||||
|
viewportH,
|
||||||
|
pageW,
|
||||||
|
pageH,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const replayPreview = await getHeatmapReplayPreview(websiteId, urlPath, viewportW, viewportH);
|
||||||
|
|
||||||
|
if (replayPreview && pageW && pageH) {
|
||||||
|
return {
|
||||||
|
kind: 'replay',
|
||||||
|
id: replayPreview.id,
|
||||||
|
replayId: replayPreview.replayId,
|
||||||
|
chunkIndex: replayPreview.chunkIndex,
|
||||||
|
eventIndex: replayPreview.eventIndex,
|
||||||
|
replayTimeMs: replayPreview.replayTimeMs,
|
||||||
|
pageW,
|
||||||
|
pageH,
|
||||||
|
viewportW: replayPreview.viewportW,
|
||||||
|
viewportH: replayPreview.viewportH,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function pickSnapshotViewport(
|
function pickSnapshotViewport(
|
||||||
points: HeatmapPoint[],
|
points: HeatmapPoint[],
|
||||||
): { width: number; height: number; pageW: number; pageH: number } | null {
|
): { width: number; height: number; pageW: number; pageH: number } | null {
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import prisma from '@/lib/prisma';
|
||||||
|
|
||||||
|
export interface HeatmapReplayPreview {
|
||||||
|
id: string;
|
||||||
|
replayId: string;
|
||||||
|
chunkIndex: number;
|
||||||
|
eventIndex: number;
|
||||||
|
replayTimeMs: number | null;
|
||||||
|
viewportW: number;
|
||||||
|
viewportH: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getHeatmapReplayPreview(
|
||||||
|
websiteId: string,
|
||||||
|
urlPath: string,
|
||||||
|
viewportW: number | null,
|
||||||
|
viewportH: number | null,
|
||||||
|
): Promise<HeatmapReplayPreview | null> {
|
||||||
|
if (!websiteId || !urlPath || !viewportW || !viewportH) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows: {
|
||||||
|
id: string;
|
||||||
|
replayId: string;
|
||||||
|
chunkIndex: number;
|
||||||
|
eventIndex: number;
|
||||||
|
replayTimeMs: bigint | number | null;
|
||||||
|
viewportW: number;
|
||||||
|
viewportH: number;
|
||||||
|
}[] = await prisma.rawQuery(
|
||||||
|
`
|
||||||
|
select
|
||||||
|
preview_id as id,
|
||||||
|
visit_id as "replayId",
|
||||||
|
replay_chunk_index as "chunkIndex",
|
||||||
|
replay_event_index as "eventIndex",
|
||||||
|
replay_time_ms as "replayTimeMs",
|
||||||
|
viewport_w as "viewportW",
|
||||||
|
viewport_h as "viewportH"
|
||||||
|
from heatmap_replay_preview
|
||||||
|
where website_id = {{websiteId::uuid}}
|
||||||
|
and url_path = {{urlPath}}
|
||||||
|
and viewport_w = {{viewportW}}
|
||||||
|
and viewport_h = {{viewportH}}
|
||||||
|
limit 1
|
||||||
|
`,
|
||||||
|
{ websiteId, urlPath, viewportW, viewportH },
|
||||||
|
'getHeatmapReplayPreview',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const row = rows[0];
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: row.id,
|
||||||
|
replayId: row.replayId,
|
||||||
|
chunkIndex: Number(row.chunkIndex),
|
||||||
|
eventIndex: Number(row.eventIndex),
|
||||||
|
replayTimeMs:
|
||||||
|
row.replayTimeMs === null || row.replayTimeMs === undefined
|
||||||
|
? null
|
||||||
|
: Number(row.replayTimeMs),
|
||||||
|
viewportW: Number(row.viewportW),
|
||||||
|
viewportH: Number(row.viewportH),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,12 @@ import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|||||||
import kafka from '@/lib/kafka';
|
import kafka from '@/lib/kafka';
|
||||||
import prisma from '@/lib/prisma';
|
import prisma from '@/lib/prisma';
|
||||||
|
|
||||||
|
const RRWEB_TYPE_FULL_SNAPSHOT = 2;
|
||||||
|
const RRWEB_TYPE_INCREMENTAL = 3;
|
||||||
|
const RRWEB_TYPE_META = 4;
|
||||||
|
const RRWEB_TYPE_CUSTOM = 5;
|
||||||
|
const RRWEB_SOURCE_VIEWPORT_RESIZE = 4;
|
||||||
|
|
||||||
export interface SaveRecordingArgs {
|
export interface SaveRecordingArgs {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
@@ -17,10 +23,21 @@ export interface SaveRecordingArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function saveRecording(args: SaveRecordingArgs) {
|
export async function saveRecording(args: SaveRecordingArgs) {
|
||||||
return runQuery({
|
const result = await runQuery({
|
||||||
[PRISMA]: () => relationalQuery(args),
|
[PRISMA]: () => relationalQuery(args),
|
||||||
[CLICKHOUSE]: () => clickhouseQuery(args),
|
[CLICKHOUSE]: () => clickhouseQuery(args),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// rrweb-backed heatmap previews are intentionally relational-only.
|
||||||
|
if (!clickhouse.enabled) {
|
||||||
|
try {
|
||||||
|
await upsertHeatmapReplayPreviews(args);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to save heatmap replay preview', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function relationalQuery({
|
async function relationalQuery({
|
||||||
@@ -81,3 +98,222 @@ async function clickhouseQuery({
|
|||||||
|
|
||||||
return insert('session_replay', [message]);
|
return insert('session_replay', [message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface HeatmapReplayPreviewRow {
|
||||||
|
websiteId: string;
|
||||||
|
sessionId: string;
|
||||||
|
visitId: string;
|
||||||
|
urlPath: string;
|
||||||
|
viewportW: number;
|
||||||
|
viewportH: number;
|
||||||
|
replayChunkIndex: number;
|
||||||
|
replayEventIndex: number;
|
||||||
|
replayTimeMs: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safePathname(href: unknown): string | null {
|
||||||
|
if (typeof href !== 'string') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return new URL(href).pathname || '/';
|
||||||
|
} catch {
|
||||||
|
return href.startsWith('/') ? href.split(/[?#]/)[0] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toBigIntOrNull(value: number | null) {
|
||||||
|
return value === null ? null : BigInt(Math.trunc(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractHeatmapReplayPreviewRows({
|
||||||
|
websiteId,
|
||||||
|
sessionId,
|
||||||
|
visitId,
|
||||||
|
chunkIndex,
|
||||||
|
events,
|
||||||
|
}: Pick<SaveRecordingArgs, 'websiteId' | 'sessionId' | 'visitId' | 'chunkIndex' | 'events'>) {
|
||||||
|
const latestByKey = new Map<string, HeatmapReplayPreviewRow>();
|
||||||
|
let urlPath: string | null = null;
|
||||||
|
let viewportW: number | null = null;
|
||||||
|
let viewportH: number | null = null;
|
||||||
|
|
||||||
|
for (const [eventIndex, event] of events.entries()) {
|
||||||
|
if (!event || typeof event !== 'object') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const replayTimeMs =
|
||||||
|
typeof event.timestamp === 'number' && Number.isFinite(event.timestamp)
|
||||||
|
? Math.trunc(event.timestamp)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (event.type === RRWEB_TYPE_META && event.data) {
|
||||||
|
const nextPath = safePathname(event.data.href);
|
||||||
|
|
||||||
|
if (nextPath) {
|
||||||
|
urlPath = nextPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof event.data.width === 'number') {
|
||||||
|
viewportW = Math.trunc(event.data.width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof event.data.height === 'number') {
|
||||||
|
viewportH = Math.trunc(event.data.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type === RRWEB_TYPE_CUSTOM && event.data?.tag === 'url-change') {
|
||||||
|
const nextPath = safePathname(event.data.payload?.url);
|
||||||
|
|
||||||
|
if (nextPath) {
|
||||||
|
urlPath = nextPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type === RRWEB_TYPE_INCREMENTAL && event.data?.source === RRWEB_SOURCE_VIEWPORT_RESIZE) {
|
||||||
|
if (typeof event.data.width === 'number') {
|
||||||
|
viewportW = Math.trunc(event.data.width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof event.data.height === 'number') {
|
||||||
|
viewportH = Math.trunc(event.data.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!urlPath ||
|
||||||
|
!viewportW ||
|
||||||
|
!viewportH ||
|
||||||
|
(event.type !== RRWEB_TYPE_FULL_SNAPSHOT &&
|
||||||
|
event.type !== RRWEB_TYPE_INCREMENTAL &&
|
||||||
|
event.type !== RRWEB_TYPE_CUSTOM)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = `${urlPath}:${viewportW}x${viewportH}`;
|
||||||
|
|
||||||
|
latestByKey.set(key, {
|
||||||
|
websiteId,
|
||||||
|
sessionId,
|
||||||
|
visitId,
|
||||||
|
urlPath,
|
||||||
|
viewportW,
|
||||||
|
viewportH,
|
||||||
|
replayChunkIndex: chunkIndex,
|
||||||
|
replayEventIndex: eventIndex,
|
||||||
|
replayTimeMs,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(latestByKey.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSchema() {
|
||||||
|
const databaseUrl = process.env.DATABASE_URL;
|
||||||
|
|
||||||
|
if (!databaseUrl) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const connectionUrl = new URL(databaseUrl);
|
||||||
|
|
||||||
|
return connectionUrl.searchParams.get('schema');
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function rawExecute(sql: string, data: Record<string, any> = {}) {
|
||||||
|
const params: any[] = [];
|
||||||
|
const schema = getSchema();
|
||||||
|
|
||||||
|
if (schema) {
|
||||||
|
await prisma.client.$executeRawUnsafe(`SET search_path TO "${schema}";`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = sql.replaceAll(/\{\{\s*(\w+)(::\w+)?\s*}}/g, (...args) => {
|
||||||
|
const [, name, type] = args;
|
||||||
|
|
||||||
|
params.push(data[name]);
|
||||||
|
|
||||||
|
return `$${params.length}${type ?? ''}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return prisma.client.$executeRawUnsafe(query, ...params);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function upsertHeatmapReplayPreviews({
|
||||||
|
websiteId,
|
||||||
|
sessionId,
|
||||||
|
visitId,
|
||||||
|
chunkIndex,
|
||||||
|
events,
|
||||||
|
}: Pick<SaveRecordingArgs, 'websiteId' | 'sessionId' | 'visitId' | 'chunkIndex' | 'events'>) {
|
||||||
|
const previewRows = extractHeatmapReplayPreviewRows({
|
||||||
|
websiteId,
|
||||||
|
sessionId,
|
||||||
|
visitId,
|
||||||
|
chunkIndex,
|
||||||
|
events,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const row of previewRows) {
|
||||||
|
await rawExecute(
|
||||||
|
`
|
||||||
|
insert into heatmap_replay_preview (
|
||||||
|
preview_id,
|
||||||
|
website_id,
|
||||||
|
session_id,
|
||||||
|
visit_id,
|
||||||
|
url_path,
|
||||||
|
viewport_w,
|
||||||
|
viewport_h,
|
||||||
|
replay_chunk_index,
|
||||||
|
replay_event_index,
|
||||||
|
replay_time_ms
|
||||||
|
)
|
||||||
|
values (
|
||||||
|
{{id::uuid}},
|
||||||
|
{{websiteId::uuid}},
|
||||||
|
{{sessionId::uuid}},
|
||||||
|
{{visitId::uuid}},
|
||||||
|
{{urlPath}},
|
||||||
|
{{viewportW}},
|
||||||
|
{{viewportH}},
|
||||||
|
{{replayChunkIndex}},
|
||||||
|
{{replayEventIndex}},
|
||||||
|
{{replayTimeMs::bigint}}
|
||||||
|
)
|
||||||
|
on conflict (website_id, url_path, viewport_w, viewport_h)
|
||||||
|
do update set
|
||||||
|
session_id = excluded.session_id,
|
||||||
|
visit_id = excluded.visit_id,
|
||||||
|
replay_chunk_index = excluded.replay_chunk_index,
|
||||||
|
replay_event_index = excluded.replay_event_index,
|
||||||
|
replay_time_ms = excluded.replay_time_ms,
|
||||||
|
updated_at = now()
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
id: uuid(),
|
||||||
|
websiteId: row.websiteId,
|
||||||
|
sessionId: row.sessionId,
|
||||||
|
visitId: row.visitId,
|
||||||
|
urlPath: row.urlPath,
|
||||||
|
viewportW: row.viewportW,
|
||||||
|
viewportH: row.viewportH,
|
||||||
|
replayChunkIndex: row.replayChunkIndex,
|
||||||
|
replayEventIndex: row.replayEventIndex,
|
||||||
|
replayTimeMs: toBigIntOrNull(row.replayTimeMs),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user