@extn/segi-js 0.2.11 → 0.2.12
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.
- package/dist/cdn.global.js +27 -27
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/dist/replay/index.d.mts +5 -5
- package/dist/replay/index.d.ts +5 -5
- package/dist/replay/index.js +25 -183
- package/dist/replay/index.mjs +3 -161
- package/dist/{types-DfmnOA9D.d.mts → types-CsgcNSc1.d.mts} +5 -5
- package/dist/{types-DfmnOA9D.d.ts → types-CsgcNSc1.d.ts} +5 -5
- package/package.json +1 -1
package/dist/replay/index.mjs
CHANGED
|
@@ -1,142 +1,3 @@
|
|
|
1
|
-
// src/replay/heatmap.ts
|
|
2
|
-
var FLUSH_CLICK_INTERVAL_MS = 5e3;
|
|
3
|
-
var FLUSH_CLICK_BUFFER = 50;
|
|
4
|
-
var SCROLL_THROTTLE_MS = 1e3;
|
|
5
|
-
function deviceClass(w) {
|
|
6
|
-
if (w < 640) return "mobile";
|
|
7
|
-
if (w < 1024) return "tablet";
|
|
8
|
-
return "desktop";
|
|
9
|
-
}
|
|
10
|
-
function isMaskedElement(el, maskClass) {
|
|
11
|
-
let cur = el;
|
|
12
|
-
while (cur) {
|
|
13
|
-
if (cur.classList?.contains(maskClass)) return true;
|
|
14
|
-
cur = cur.parentElement;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
function buildSelector(el) {
|
|
19
|
-
try {
|
|
20
|
-
if (el.id) return `#${el.id}`;
|
|
21
|
-
const tag = el.tagName?.toLowerCase();
|
|
22
|
-
if (!tag) return void 0;
|
|
23
|
-
const cls = (el.className && typeof el.className === "string" ? el.className.split(/\s+/).filter(Boolean).slice(0, 2) : []).map((c) => `.${c}`);
|
|
24
|
-
return `${tag}${cls.join("")}`.slice(0, 512);
|
|
25
|
-
} catch {
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function startHeatmap(args) {
|
|
30
|
-
const maskClass = args.options.mask?.class ?? "segi-mask";
|
|
31
|
-
let paused = false;
|
|
32
|
-
const buffer = [];
|
|
33
|
-
let lastScrollPct = -1;
|
|
34
|
-
let lastScrollPostAt = 0;
|
|
35
|
-
const flushClicks = (opts = {}) => {
|
|
36
|
-
if (buffer.length === 0) return;
|
|
37
|
-
const batch = buffer.splice(0, buffer.length);
|
|
38
|
-
args.sendClicks(batch, Boolean(opts.useBeacon));
|
|
39
|
-
};
|
|
40
|
-
const interval = setInterval(() => {
|
|
41
|
-
if (!paused) flushClicks();
|
|
42
|
-
}, FLUSH_CLICK_INTERVAL_MS);
|
|
43
|
-
const onClick = (e) => {
|
|
44
|
-
if (paused) return;
|
|
45
|
-
try {
|
|
46
|
-
const target = e.target;
|
|
47
|
-
if (!target) return;
|
|
48
|
-
if (isMaskedElement(target, maskClass)) return;
|
|
49
|
-
const docW = Math.max(
|
|
50
|
-
document.documentElement.scrollWidth,
|
|
51
|
-
document.body?.scrollWidth ?? 0,
|
|
52
|
-
1
|
|
53
|
-
);
|
|
54
|
-
const docH = Math.max(
|
|
55
|
-
document.documentElement.scrollHeight,
|
|
56
|
-
document.body?.scrollHeight ?? 0,
|
|
57
|
-
1
|
|
58
|
-
);
|
|
59
|
-
const pageX = e.pageX;
|
|
60
|
-
const pageY = e.pageY;
|
|
61
|
-
const w = window.innerWidth;
|
|
62
|
-
const row = {
|
|
63
|
-
sessionUid: args.sessionUid,
|
|
64
|
-
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
65
|
-
urlPath: location.pathname.slice(0, 255),
|
|
66
|
-
device: deviceClass(w),
|
|
67
|
-
viewportW: w,
|
|
68
|
-
viewportH: window.innerHeight,
|
|
69
|
-
x: Math.round(e.clientX),
|
|
70
|
-
y: Math.round(e.clientY),
|
|
71
|
-
pageX: Math.round(pageX),
|
|
72
|
-
pageY: Math.round(pageY),
|
|
73
|
-
relX: Math.max(0, Math.min(1, pageX / docW)),
|
|
74
|
-
relY: Math.max(0, Math.min(1, pageY / docH)),
|
|
75
|
-
selector: buildSelector(target),
|
|
76
|
-
tag: target.tagName?.toLowerCase().slice(0, 32),
|
|
77
|
-
text: (target.textContent ?? void 0)?.trim().slice(0, 128) || void 0
|
|
78
|
-
};
|
|
79
|
-
buffer.push(row);
|
|
80
|
-
if (buffer.length >= FLUSH_CLICK_BUFFER) flushClicks();
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const onScroll = () => {
|
|
85
|
-
if (paused) return;
|
|
86
|
-
const now = Date.now();
|
|
87
|
-
if (now - lastScrollPostAt < SCROLL_THROTTLE_MS) return;
|
|
88
|
-
try {
|
|
89
|
-
const docH = Math.max(
|
|
90
|
-
document.documentElement.scrollHeight,
|
|
91
|
-
document.body?.scrollHeight ?? 0,
|
|
92
|
-
1
|
|
93
|
-
);
|
|
94
|
-
const viewH = window.innerHeight;
|
|
95
|
-
const maxY = Math.round(window.scrollY + viewH);
|
|
96
|
-
const pct = Math.max(0, Math.min(100, Math.round(maxY / docH * 100)));
|
|
97
|
-
if (pct <= lastScrollPct) return;
|
|
98
|
-
lastScrollPct = pct;
|
|
99
|
-
lastScrollPostAt = now;
|
|
100
|
-
const w = window.innerWidth;
|
|
101
|
-
args.sendScroll(
|
|
102
|
-
{
|
|
103
|
-
sessionUid: args.sessionUid,
|
|
104
|
-
urlPath: location.pathname.slice(0, 255),
|
|
105
|
-
device: deviceClass(w),
|
|
106
|
-
viewportH: viewH,
|
|
107
|
-
docH,
|
|
108
|
-
maxScrollY: maxY,
|
|
109
|
-
maxScrollPct: pct
|
|
110
|
-
},
|
|
111
|
-
false
|
|
112
|
-
);
|
|
113
|
-
} catch {
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const onPageHide = () => {
|
|
117
|
-
flushClicks({ useBeacon: true });
|
|
118
|
-
};
|
|
119
|
-
window.addEventListener("click", onClick, true);
|
|
120
|
-
window.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
121
|
-
window.addEventListener("pagehide", onPageHide);
|
|
122
|
-
return {
|
|
123
|
-
pause() {
|
|
124
|
-
paused = true;
|
|
125
|
-
},
|
|
126
|
-
resume() {
|
|
127
|
-
paused = false;
|
|
128
|
-
},
|
|
129
|
-
stop() {
|
|
130
|
-
clearInterval(interval);
|
|
131
|
-
window.removeEventListener("click", onClick, true);
|
|
132
|
-
window.removeEventListener("scroll", onScroll, true);
|
|
133
|
-
window.removeEventListener("pagehide", onPageHide);
|
|
134
|
-
flushClicks({ useBeacon: true });
|
|
135
|
-
},
|
|
136
|
-
flushClicks
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
1
|
// src/replay/session.ts
|
|
141
2
|
var UID_KEY = "_bd_session_uid";
|
|
142
3
|
var UID_TS_KEY = "_bd_session_at";
|
|
@@ -249,7 +110,7 @@ function withReplay(options = {}) {
|
|
|
249
110
|
return { __segi_replay: true, options };
|
|
250
111
|
}
|
|
251
112
|
var active = null;
|
|
252
|
-
function
|
|
113
|
+
function deviceClass() {
|
|
253
114
|
if (typeof window === "undefined") return "desktop";
|
|
254
115
|
const w = window.innerWidth;
|
|
255
116
|
if (w < 640) return "mobile";
|
|
@@ -286,7 +147,7 @@ async function activateReplay(args) {
|
|
|
286
147
|
sessionUid,
|
|
287
148
|
anonId,
|
|
288
149
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
289
|
-
device:
|
|
150
|
+
device: deviceClass(),
|
|
290
151
|
viewportW: window.innerWidth,
|
|
291
152
|
viewportH: window.innerHeight,
|
|
292
153
|
ua: navigator.userAgent?.slice(0, 512),
|
|
@@ -314,7 +175,6 @@ async function activateReplay(args) {
|
|
|
314
175
|
sessionUid,
|
|
315
176
|
config: transportCfg,
|
|
316
177
|
options,
|
|
317
|
-
heatmap: null,
|
|
318
178
|
rrweb: null,
|
|
319
179
|
replayBlocked: false,
|
|
320
180
|
paused: true,
|
|
@@ -326,22 +186,10 @@ async function activateReplay(args) {
|
|
|
326
186
|
};
|
|
327
187
|
return;
|
|
328
188
|
}
|
|
329
|
-
const heatmap = startHeatmap({
|
|
330
|
-
sessionUid,
|
|
331
|
-
options,
|
|
332
|
-
sendClicks: (rows, useBeacon) => {
|
|
333
|
-
if (useBeacon) beaconTrace(transportCfg, "/heatmap/clicks", { clicks: rows });
|
|
334
|
-
else void postTrace(transportCfg, "/heatmap/clicks", { clicks: rows });
|
|
335
|
-
},
|
|
336
|
-
sendScroll: (row) => {
|
|
337
|
-
void postTrace(transportCfg, "/heatmap/scroll", row);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
189
|
active = {
|
|
341
190
|
sessionUid,
|
|
342
191
|
config: transportCfg,
|
|
343
192
|
options,
|
|
344
|
-
heatmap,
|
|
345
193
|
rrweb: null,
|
|
346
194
|
replayBlocked: false,
|
|
347
195
|
paused: false,
|
|
@@ -457,8 +305,6 @@ async function activateReplay(args) {
|
|
|
457
305
|
active.rrweb?.flush(true);
|
|
458
306
|
active.rrweb?.stop();
|
|
459
307
|
active.rrweb = null;
|
|
460
|
-
active.heatmap?.stop();
|
|
461
|
-
active.heatmap = null;
|
|
462
308
|
beaconTrace(active.config, "/session/end", {
|
|
463
309
|
sessionUid: active.sessionUid,
|
|
464
310
|
endedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -472,12 +318,10 @@ async function activateReplay(args) {
|
|
|
472
318
|
}
|
|
473
319
|
var replayApi = {
|
|
474
320
|
pause() {
|
|
475
|
-
active?.heatmap?.pause();
|
|
476
321
|
active?.rrweb?.pause();
|
|
477
322
|
if (active) active.paused = true;
|
|
478
323
|
},
|
|
479
324
|
resume() {
|
|
480
|
-
active?.heatmap?.resume();
|
|
481
325
|
active?.rrweb?.resume();
|
|
482
326
|
if (active) active.paused = false;
|
|
483
327
|
bumpSessionActivity();
|
|
@@ -490,7 +334,7 @@ var replayApi = {
|
|
|
490
334
|
anonId: getOrCreateAnonId(),
|
|
491
335
|
userId: active.userId,
|
|
492
336
|
startedAt: active.startedAt,
|
|
493
|
-
device:
|
|
337
|
+
device: deviceClass(),
|
|
494
338
|
viewportW: window.innerWidth,
|
|
495
339
|
viewportH: window.innerHeight
|
|
496
340
|
});
|
|
@@ -520,14 +364,12 @@ var replayApi = {
|
|
|
520
364
|
const nowBlocked = isPathBlocked(active.options, location.pathname);
|
|
521
365
|
if (nowBlocked) {
|
|
522
366
|
if (!active.paused) {
|
|
523
|
-
active.heatmap?.pause();
|
|
524
367
|
active.rrweb?.pause();
|
|
525
368
|
active.paused = true;
|
|
526
369
|
}
|
|
527
370
|
return;
|
|
528
371
|
}
|
|
529
372
|
if (active.paused) {
|
|
530
|
-
active.heatmap?.resume();
|
|
531
373
|
active.rrweb?.resume();
|
|
532
374
|
active.paused = false;
|
|
533
375
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Replay
|
|
2
|
+
* Replay collector — public option types and internal DTOs.
|
|
3
3
|
* Mirrors apps/api/src/trace/trace.types.ts at the field level.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Covers session start/end, page_view / custom trace events, and rrweb DOM
|
|
6
|
+
* replay. (Heatmap collection — click/scroll/move — was removed alongside the
|
|
7
|
+
* server-side /api/trace/heatmap/* endpoints.)
|
|
8
8
|
*/
|
|
9
9
|
interface ReplayOptions {
|
|
10
10
|
/** Toggle the whole module. Setting `false` causes withReplay() to return null. */
|
|
@@ -13,7 +13,7 @@ interface ReplayOptions {
|
|
|
13
13
|
sample?: number;
|
|
14
14
|
/** Path-prefix deny-list (in addition to the server-side per-project list). */
|
|
15
15
|
blockRoutes?: string[];
|
|
16
|
-
/** rrweb
|
|
16
|
+
/** rrweb mask. Class is recursively checked up the ancestor chain. */
|
|
17
17
|
mask?: {
|
|
18
18
|
inputs?: "all" | "sensitive" | "none";
|
|
19
19
|
class?: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Replay
|
|
2
|
+
* Replay collector — public option types and internal DTOs.
|
|
3
3
|
* Mirrors apps/api/src/trace/trace.types.ts at the field level.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Covers session start/end, page_view / custom trace events, and rrweb DOM
|
|
6
|
+
* replay. (Heatmap collection — click/scroll/move — was removed alongside the
|
|
7
|
+
* server-side /api/trace/heatmap/* endpoints.)
|
|
8
8
|
*/
|
|
9
9
|
interface ReplayOptions {
|
|
10
10
|
/** Toggle the whole module. Setting `false` causes withReplay() to return null. */
|
|
@@ -13,7 +13,7 @@ interface ReplayOptions {
|
|
|
13
13
|
sample?: number;
|
|
14
14
|
/** Path-prefix deny-list (in addition to the server-side per-project list). */
|
|
15
15
|
blockRoutes?: string[];
|
|
16
|
-
/** rrweb
|
|
16
|
+
/** rrweb mask. Class is recursively checked up the ancestor chain. */
|
|
17
17
|
mask?: {
|
|
18
18
|
inputs?: "all" | "sensitive" | "none";
|
|
19
19
|
class?: string;
|