@temps-sdk/react-analytics 0.0.1-beta.26 → 0.0.1-beta.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,8 +15,29 @@ interface SessionRecorderProps {
|
|
|
15
15
|
slimDOMOptions?: Record<string, boolean>;
|
|
16
16
|
batchSize?: number;
|
|
17
17
|
flushInterval?: number;
|
|
18
|
+
ignoreSelector?: string;
|
|
19
|
+
blockSelector?: string;
|
|
20
|
+
sampling?: {
|
|
21
|
+
scroll?: number;
|
|
22
|
+
media?: number;
|
|
23
|
+
mouseInteraction?: boolean | {
|
|
24
|
+
click?: boolean;
|
|
25
|
+
dblclick?: boolean;
|
|
26
|
+
contextmenu?: boolean;
|
|
27
|
+
focus?: boolean;
|
|
28
|
+
blur?: boolean;
|
|
29
|
+
touchstart?: boolean;
|
|
30
|
+
touchend?: boolean;
|
|
31
|
+
touchcancel?: boolean;
|
|
32
|
+
play?: boolean;
|
|
33
|
+
pause?: boolean;
|
|
34
|
+
};
|
|
35
|
+
mousemove?: boolean | number;
|
|
36
|
+
input?: "all" | "last";
|
|
37
|
+
canvas?: number | "all";
|
|
38
|
+
};
|
|
18
39
|
}
|
|
19
40
|
export declare function SessionRecorder({ basePath, // Required, no default
|
|
20
|
-
domain, enabled, excludedPaths, sessionSampleRate, maskAllInputs, maskTextSelector, blockClass, ignoreClass, maskTextClass, recordCanvas, collectFonts, slimDOMOptions, batchSize, flushInterval, }: SessionRecorderProps): null;
|
|
41
|
+
domain, enabled, excludedPaths, sessionSampleRate, maskAllInputs, maskTextSelector, blockClass, ignoreClass, maskTextClass, ignoreSelector, blockSelector, recordCanvas, collectFonts, slimDOMOptions, batchSize, flushInterval, sampling, }: SessionRecorderProps): null;
|
|
21
42
|
export {};
|
|
22
43
|
//# sourceMappingURL=SessionRecorder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionRecorder.d.ts","sourceRoot":"","sources":["../src/SessionRecorder.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"SessionRecorder.d.ts","sourceRoot":"","sources":["../src/SessionRecorder.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,C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ionRecorder.js
CHANGED
|
@@ -42,7 +42,7 @@ function getSessionMetadata(domain) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
export function SessionRecorder({ basePath, // Required, no default
|
|
45
|
-
domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInputs = true, maskTextSelector = "[data-mask]", blockClass = "rr-block", ignoreClass = "rr-ignore", maskTextClass = "rr-mask", recordCanvas = false, collectFonts = false, slimDOMOptions = {
|
|
45
|
+
domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInputs = true, maskTextSelector = "[data-mask]", blockClass = "rr-block", ignoreClass = "rr-ignore", maskTextClass = "rr-mask", ignoreSelector = "[data-ignore]", blockSelector = "[data-private]", recordCanvas = false, collectFonts = false, slimDOMOptions = {
|
|
46
46
|
script: false,
|
|
47
47
|
comment: false,
|
|
48
48
|
headFavicon: false,
|
|
@@ -52,7 +52,7 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
52
52
|
headMetaHttpEquiv: false,
|
|
53
53
|
headMetaVerification: false,
|
|
54
54
|
headMetaDescKeywords: false
|
|
55
|
-
}, batchSize = 200, flushInterval = 30000, }) {
|
|
55
|
+
}, batchSize = 200, flushInterval = 30000, sampling = {}, }) {
|
|
56
56
|
const stopFnRef = useRef(null);
|
|
57
57
|
const eventsRef = useRef([]);
|
|
58
58
|
const sessionIdRef = useRef("");
|
|
@@ -62,6 +62,19 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
62
62
|
const initFailedRef = useRef(false); // Track if init has permanently failed
|
|
63
63
|
const maxInitRetries = 3;
|
|
64
64
|
const [isInitializing, setIsInitializing] = useState(false);
|
|
65
|
+
// Deep merge sampling defaults with proper handling of mouseInteraction
|
|
66
|
+
const defaultSampling = {
|
|
67
|
+
scroll: 150,
|
|
68
|
+
media: 800,
|
|
69
|
+
mouseInteraction: true,
|
|
70
|
+
mousemove: true,
|
|
71
|
+
input: "last",
|
|
72
|
+
};
|
|
73
|
+
// Merge sampling configs, handling mouseInteraction specially
|
|
74
|
+
const samplingConfig = {
|
|
75
|
+
...defaultSampling,
|
|
76
|
+
...sampling,
|
|
77
|
+
};
|
|
65
78
|
const shouldRecord = useCallback(() => {
|
|
66
79
|
if (!enabled)
|
|
67
80
|
return false;
|
|
@@ -275,7 +288,10 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
275
288
|
console.error("[SessionRecorder] Failed to initialize session, not starting recording");
|
|
276
289
|
return;
|
|
277
290
|
}
|
|
278
|
-
|
|
291
|
+
// Don't clear events buffer on restart - preserve any pending events
|
|
292
|
+
if (!eventsRef.current) {
|
|
293
|
+
eventsRef.current = [];
|
|
294
|
+
}
|
|
279
295
|
const stopFn = record({
|
|
280
296
|
emit(event) {
|
|
281
297
|
eventsRef.current.push(event);
|
|
@@ -285,13 +301,9 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
285
301
|
// scheduleFlush() is now called automatically after each send
|
|
286
302
|
}
|
|
287
303
|
},
|
|
288
|
-
sampling:
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
input: "last"
|
|
292
|
-
},
|
|
293
|
-
blockSelector: "[data-private]",
|
|
294
|
-
ignoreSelector: "[data-ignore]",
|
|
304
|
+
sampling: samplingConfig,
|
|
305
|
+
blockSelector,
|
|
306
|
+
ignoreSelector,
|
|
295
307
|
recordCanvas,
|
|
296
308
|
collectFonts,
|
|
297
309
|
maskAllInputs,
|
|
@@ -300,13 +312,18 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
300
312
|
ignoreClass,
|
|
301
313
|
maskTextClass,
|
|
302
314
|
slimDOMOptions,
|
|
315
|
+
// Add checkoutEveryNms to force periodic full snapshots
|
|
316
|
+
// This helps with route changes by ensuring we get fresh snapshots
|
|
317
|
+
checkoutEveryNms: 60000, // Take a full snapshot every minute
|
|
318
|
+
// Add recordCrossOriginIframes for better iframe support
|
|
319
|
+
recordCrossOriginIframes: false,
|
|
303
320
|
});
|
|
304
321
|
if (stopFn) {
|
|
305
322
|
stopFnRef.current = stopFn;
|
|
306
323
|
}
|
|
307
324
|
// Start the flush interval
|
|
308
325
|
scheduleFlush();
|
|
309
|
-
}, [shouldRecord, initializeSession, sendEvents, scheduleFlush, batchSize, recordCanvas, collectFonts, maskAllInputs, maskTextSelector, blockClass, ignoreClass, maskTextClass, slimDOMOptions]);
|
|
326
|
+
}, [shouldRecord, initializeSession, sendEvents, scheduleFlush, batchSize, recordCanvas, collectFonts, maskAllInputs, maskTextSelector, blockClass, ignoreClass, maskTextClass, slimDOMOptions, samplingConfig]);
|
|
310
327
|
const stopRecording = useCallback(() => {
|
|
311
328
|
if (stopFnRef.current) {
|
|
312
329
|
stopFnRef.current();
|
|
@@ -382,30 +399,54 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
|
|
|
382
399
|
const regex = new RegExp(`^${path.replace(/\*/g, '.*')}$`);
|
|
383
400
|
return regex.test(currentPath);
|
|
384
401
|
});
|
|
385
|
-
if
|
|
402
|
+
// Only stop/start recording if we're actually changing exclusion status
|
|
403
|
+
// This prevents unnecessary restarts during normal navigation
|
|
404
|
+
const isCurrentlyRecording = stopFnRef.current !== null;
|
|
405
|
+
if (isExcluded && isCurrentlyRecording) {
|
|
406
|
+
// Path is excluded and we're recording - stop
|
|
386
407
|
stopRecording();
|
|
387
408
|
}
|
|
388
|
-
else if (!isExcluded && !
|
|
409
|
+
else if (!isExcluded && !isCurrentlyRecording && !initFailedRef.current) {
|
|
410
|
+
// Path is not excluded and we're not recording - start
|
|
389
411
|
startRecording();
|
|
390
412
|
}
|
|
413
|
+
// If the path exclusion status hasn't changed, keep recording continuously
|
|
391
414
|
};
|
|
392
415
|
// Listen for route changes
|
|
393
416
|
const originalPushState = window.history.pushState;
|
|
394
417
|
const originalReplaceState = window.history.replaceState;
|
|
395
418
|
window.history.pushState = function (...args) {
|
|
419
|
+
// Flush current events before route change to ensure they're captured
|
|
420
|
+
if (stopFnRef.current && eventsRef.current.length > 0) {
|
|
421
|
+
sendEvents(false);
|
|
422
|
+
}
|
|
396
423
|
originalPushState.apply(window.history, args);
|
|
397
|
-
|
|
424
|
+
// Use setTimeout to allow DOM updates to complete before checking
|
|
425
|
+
setTimeout(checkPathAndToggleRecording, 0);
|
|
398
426
|
};
|
|
399
427
|
window.history.replaceState = function (...args) {
|
|
428
|
+
// Flush current events before route change to ensure they're captured
|
|
429
|
+
if (stopFnRef.current && eventsRef.current.length > 0) {
|
|
430
|
+
sendEvents(false);
|
|
431
|
+
}
|
|
400
432
|
originalReplaceState.apply(window.history, args);
|
|
401
|
-
|
|
433
|
+
// Use setTimeout to allow DOM updates to complete before checking
|
|
434
|
+
setTimeout(checkPathAndToggleRecording, 0);
|
|
435
|
+
};
|
|
436
|
+
const handlePopState = () => {
|
|
437
|
+
// Flush current events before route change to ensure they're captured
|
|
438
|
+
if (stopFnRef.current && eventsRef.current.length > 0) {
|
|
439
|
+
sendEvents(false);
|
|
440
|
+
}
|
|
441
|
+
// Use setTimeout to allow DOM updates to complete before checking
|
|
442
|
+
setTimeout(checkPathAndToggleRecording, 0);
|
|
402
443
|
};
|
|
403
|
-
window.addEventListener("popstate",
|
|
444
|
+
window.addEventListener("popstate", handlePopState);
|
|
404
445
|
return () => {
|
|
405
446
|
window.history.pushState = originalPushState;
|
|
406
447
|
window.history.replaceState = originalReplaceState;
|
|
407
|
-
window.removeEventListener("popstate",
|
|
448
|
+
window.removeEventListener("popstate", handlePopState);
|
|
408
449
|
};
|
|
409
|
-
}, [enabled, excludedPaths, startRecording, stopRecording]);
|
|
450
|
+
}, [enabled, excludedPaths, startRecording, stopRecording, sendEvents]);
|
|
410
451
|
return null;
|
|
411
452
|
}
|