@temps-sdk/analytics-browser 0.0.2 → 0.0.6

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/temps.js CHANGED
@@ -2,6 +2,8 @@
2
2
  // ../analytics-core/dist/constants.js
3
3
  var DEFAULT_BASE_PATH = "/api/_temps";
4
4
  var SESSION_RECORDER_ENDPOINT = "session-replay";
5
+ var INGEST_KEY_HEADER = "X-Temps-Analytics-Key";
6
+ var INGEST_KEY_QUERY_PARAM = "temps_key";
5
7
  var DEFAULT_EXCLUDED_PATHS = [
6
8
  "/login",
7
9
  "/log-in",
@@ -21,6 +23,49 @@
21
23
  "/2fa*",
22
24
  "/verify*"
23
25
  ];
26
+ // ../analytics-core/dist/identity.js
27
+ var VISITOR_ID_KEY = "temps_visitor_id";
28
+ var SESSION_ID_KEY = "temps_session_id";
29
+ var SESSION_LAST_SEEN_KEY = "temps_session_last_seen";
30
+ var SESSION_MAX_AGE_MS = 30 * 60 * 1000;
31
+ function randomId(prefix) {
32
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
33
+ return crypto.randomUUID();
34
+ }
35
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
36
+ }
37
+ function getOrCreateVisitorId() {
38
+ try {
39
+ if (typeof localStorage === "undefined")
40
+ return;
41
+ let visitorId = localStorage.getItem(VISITOR_ID_KEY);
42
+ if (!visitorId) {
43
+ visitorId = randomId("visitor");
44
+ localStorage.setItem(VISITOR_ID_KEY, visitorId);
45
+ }
46
+ return visitorId;
47
+ } catch {
48
+ return;
49
+ }
50
+ }
51
+ function getOrCreateSessionId() {
52
+ try {
53
+ if (typeof localStorage === "undefined")
54
+ return;
55
+ const now = Date.now();
56
+ const lastSeen = Number(localStorage.getItem(SESSION_LAST_SEEN_KEY));
57
+ let sessionId = localStorage.getItem(SESSION_ID_KEY);
58
+ if (!sessionId || !Number.isFinite(lastSeen) || now - lastSeen > SESSION_MAX_AGE_MS) {
59
+ sessionId = randomId("session");
60
+ localStorage.setItem(SESSION_ID_KEY, sessionId);
61
+ }
62
+ localStorage.setItem(SESSION_LAST_SEEN_KEY, String(now));
63
+ return sessionId;
64
+ } catch {
65
+ return;
66
+ }
67
+ }
68
+
24
69
  // ../analytics-core/dist/utils.js
25
70
  function getRequestId() {
26
71
  if (typeof document === "undefined")
@@ -62,28 +107,42 @@
62
107
  const enriched = {
63
108
  ...data,
64
109
  request_id: getRequestId(),
65
- session_id: typeof localStorage !== "undefined" ? localStorage.getItem("session_id") || undefined : undefined
110
+ visitorId: getOrCreateVisitorId(),
111
+ sessionId: getOrCreateSessionId()
66
112
  };
67
113
  return enriched;
68
114
  }
69
- async function sendAnalytics(endpoint, data, method = "POST", basePath) {
115
+ function ingestKeyHeaders(ingestKey) {
116
+ return ingestKey ? { [INGEST_KEY_HEADER]: ingestKey } : {};
117
+ }
118
+ function withIngestKey(url, ingestKey) {
119
+ if (!ingestKey)
120
+ return url;
121
+ const separator = url.includes("?") ? "&" : "?";
122
+ return `${url}${separator}${INGEST_KEY_QUERY_PARAM}=${encodeURIComponent(ingestKey)}`;
123
+ }
124
+ async function sendAnalytics(endpoint, data, method = "POST", basePath, ingestKey) {
70
125
  try {
71
126
  await fetch(`${basePath}/${endpoint}`, {
72
127
  method,
73
- headers: { "Content-Type": "application/json" },
128
+ headers: { "Content-Type": "application/json", ...ingestKeyHeaders(ingestKey) },
74
129
  body: JSON.stringify(enrich(data))
75
130
  });
76
131
  } catch (error) {
77
132
  console.error("Failed to send analytics:", error);
78
133
  }
79
134
  }
80
- function sendAnalyticsReliable(endpoint, data, basePath) {
135
+ function sendAnalyticsReliable(endpoint, data, basePath, ingestKey) {
81
136
  try {
82
- const url = `${basePath}/${endpoint}`;
137
+ const url = withIngestKey(`${basePath}/${endpoint}`, ingestKey);
83
138
  const payload = JSON.stringify(enrich(data));
84
139
  if (typeof navigator !== "undefined" && navigator.sendBeacon && typeof navigator.sendBeacon === "function") {
85
- const blob = new Blob([payload], { type: "application/json" });
86
- return navigator.sendBeacon(url, blob);
140
+ try {
141
+ const blob = new Blob([payload], { type: "application/json" });
142
+ if (navigator.sendBeacon(url, blob))
143
+ return true;
144
+ } catch {
145
+ }
87
146
  }
88
147
  fetch(url, {
89
148
  method: "POST",
@@ -151,6 +210,7 @@
151
210
  request_path: window.location.pathname,
152
211
  request_query: window.location.search,
153
212
  domain: this.domain,
213
+ language: navigator.language,
154
214
  event_data: {
155
215
  engagement_time_seconds: data.engagement_time_seconds,
156
216
  total_time_seconds: data.total_time_seconds,
@@ -159,13 +219,14 @@
159
219
  url: window.location.href,
160
220
  referrer: document.referrer
161
221
  }
162
- }, this.basePath);
222
+ }, this.basePath, this.ingestKey);
163
223
  };
164
224
  this.handleNavigation = () => {
165
225
  this.handlePageLeave();
166
226
  this.reset();
167
227
  };
168
228
  this.basePath = options.basePath || DEFAULT_BASE_PATH;
229
+ this.ingestKey = options.ingestKey;
169
230
  this.domain = options.domain || window.location.hostname;
170
231
  this.heartbeatInterval = options.heartbeatInterval || 30000;
171
232
  this.inactivityTimeout = options.inactivityTimeout || 30000;
@@ -252,6 +313,7 @@
252
313
  request_path: window.location.pathname,
253
314
  request_query: window.location.search,
254
315
  domain: this.domain,
316
+ language: navigator.language,
255
317
  event_data: {
256
318
  engagement_time: Math.round(this.engagementTime),
257
319
  total_time: Math.round(Date.now() - this.startTime),
@@ -260,7 +322,7 @@
260
322
  time_since_last_activity: data.time_since_last_activity,
261
323
  heartbeat_count: this.heartbeatCount
262
324
  }
263
- }, "POST", this.basePath);
325
+ }, "POST", this.basePath, this.ingestKey);
264
326
  if (this.isActive && this.isVisible) {
265
327
  this.lastEngagementStart = Date.now();
266
328
  }
@@ -345,7 +407,8 @@
345
407
  });
346
408
  return r2.observe(Object.assign({ type: e2, buffered: true }, t2 || {})), r2;
347
409
  }
348
- } catch (e3) {}
410
+ } catch (e3) {
411
+ }
349
412
  };
350
413
  var d = function(e2, n2, t2, r2) {
351
414
  var i2, o2;
@@ -597,55 +660,104 @@
597
660
  // ../analytics-core/dist/SpeedTracker.js
598
661
  class SpeedTracker {
599
662
  constructor(options) {
600
- this.initialMetrics = {};
663
+ this.pathname = "";
664
+ this.query = "";
665
+ this.loadMetrics = {};
666
+ this.loadSent = false;
667
+ this.sentLoadMetrics = new Set;
668
+ this.stopped = false;
669
+ this.handleVisibilityChange = () => {
670
+ if (document.visibilityState === "hidden")
671
+ this.flushLoad();
672
+ };
673
+ this.handlePageHide = () => {
674
+ this.flushLoad();
675
+ };
601
676
  this.basePath = options.basePath;
677
+ this.ingestKey = options.ingestKey;
602
678
  if (typeof window === "undefined")
603
679
  return;
680
+ this.pathname = window.location.pathname;
681
+ this.query = window.location.search;
604
682
  this.start();
605
683
  }
606
684
  start() {
607
- Q((m2) => {
608
- this.initialMetrics.TTFB = { value: m2.value, rating: m2.rating };
609
- this.sendInitial();
610
- });
611
- G((m2) => {
612
- this.initialMetrics.LCP = { value: m2.value, rating: m2.rating };
613
- this.sendInitial();
614
- });
615
- ee((m2) => {
616
- this.initialMetrics.FID = { value: m2.value, rating: m2.rating };
617
- this.sendInitial();
618
- });
619
- S((m2) => {
620
- this.initialMetrics.FCP = { value: m2.value, rating: m2.rating };
621
- this.sendInitial();
622
- });
685
+ Q((m2) => this.recordLoad("ttfb", m2.value));
686
+ S((m2) => this.recordLoad("fcp", m2.value));
687
+ G((m2) => this.recordLoad("lcp", m2.value));
688
+ ee((m2) => this.recordFid(m2.value));
623
689
  w((m2) => this.sendLate("cls", m2.value));
624
690
  j((m2) => this.sendLate("inp", m2.value));
691
+ document.addEventListener("visibilitychange", this.handleVisibilityChange, true);
692
+ window.addEventListener("pagehide", this.handlePageHide, true);
625
693
  }
626
- sendInitial() {
627
- if (Object.keys(this.initialMetrics).length !== 4)
694
+ recordLoad(name, value) {
695
+ if (this.stopped || this.sentLoadMetrics.has(name))
628
696
  return;
629
- const payload = {
630
- ttfb: this.initialMetrics.TTFB?.value ?? null,
631
- lcp: this.initialMetrics.LCP?.value ?? null,
632
- fid: this.initialMetrics.FID?.value ?? null,
633
- fcp: this.initialMetrics.FCP?.value ?? null,
634
- path: window.location.pathname,
635
- query: window.location.search
636
- };
637
- sendAnalytics("speed", payload, "POST", this.basePath);
697
+ if (this.loadSent) {
698
+ this.sentLoadMetrics.add(name);
699
+ this.send({ [name]: value });
700
+ return;
701
+ }
702
+ this.loadMetrics[name] = value;
703
+ const { ttfb, fcp, lcp } = this.loadMetrics;
704
+ if (ttfb !== undefined && fcp !== undefined && lcp !== undefined) {
705
+ this.flushLoad();
706
+ }
707
+ }
708
+ recordFid(value) {
709
+ if (this.stopped || this.sentLoadMetrics.has("fid"))
710
+ return;
711
+ if (this.loadSent) {
712
+ this.sentLoadMetrics.add("fid");
713
+ this.send({ fid: value });
714
+ return;
715
+ }
716
+ this.loadMetrics.fid = value;
717
+ }
718
+ flushLoad() {
719
+ if (this.stopped || this.loadSent)
720
+ return;
721
+ const { ttfb, fcp, lcp, fid } = this.loadMetrics;
722
+ if (ttfb === undefined && fcp === undefined && lcp === undefined && fid === undefined) {
723
+ return;
724
+ }
725
+ this.loadSent = true;
726
+ for (const [name, value] of Object.entries(this.loadMetrics)) {
727
+ if (value !== undefined)
728
+ this.sentLoadMetrics.add(name);
729
+ }
730
+ this.send({
731
+ ttfb: ttfb ?? null,
732
+ lcp: lcp ?? null,
733
+ fid: fid ?? null,
734
+ fcp: fcp ?? null
735
+ });
638
736
  }
639
737
  sendLate(name, value) {
738
+ if (this.stopped)
739
+ return;
740
+ this.send({ [name]: value });
741
+ }
742
+ send(metrics) {
640
743
  const payload = {
641
- [name]: value,
642
- path: window.location.pathname,
643
- query: window.location.search
744
+ ...metrics,
745
+ pathname: this.pathname,
746
+ query: this.query
644
747
  };
645
- sendAnalytics("speed", payload, "POST", this.basePath);
748
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
749
+ sendAnalyticsReliable("speed", payload, this.basePath, this.ingestKey);
750
+ return;
751
+ }
752
+ sendAnalytics("speed", payload, "POST", this.basePath, this.ingestKey);
646
753
  }
647
754
  destroy() {
648
- this.initialMetrics = {};
755
+ this.stopped = true;
756
+ this.loadMetrics = {};
757
+ if (typeof window === "undefined")
758
+ return;
759
+ document.removeEventListener("visibilitychange", this.handleVisibilityChange, true);
760
+ window.removeEventListener("pagehide", this.handlePageHide, true);
649
761
  }
650
762
  }
651
763
 
@@ -1205,7 +1317,8 @@
1205
1317
  if (blockSelector) {
1206
1318
  return element.matches(blockSelector);
1207
1319
  }
1208
- } catch (e22) {}
1320
+ } catch (e22) {
1321
+ }
1209
1322
  return false;
1210
1323
  }
1211
1324
  function classMatchesRegex(node2, regex, checkAncestors) {
@@ -1260,7 +1373,8 @@
1260
1373
  return true;
1261
1374
  }
1262
1375
  }
1263
- } catch (e22) {}
1376
+ } catch (e22) {
1377
+ }
1264
1378
  return false;
1265
1379
  }
1266
1380
  function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
@@ -1589,7 +1703,8 @@
1589
1703
  try {
1590
1704
  if (customElements.get(tagName))
1591
1705
  isCustomElement = true;
1592
- } catch (e22) {}
1706
+ } catch (e22) {
1707
+ }
1593
1708
  return {
1594
1709
  type: NodeType$3.Element,
1595
1710
  tagName,
@@ -4636,7 +4751,8 @@
4636
4751
  }
4637
4752
  this.endFile();
4638
4753
  }
4639
- precheckMissedSemicolon() {}
4754
+ precheckMissedSemicolon() {
4755
+ }
4640
4756
  raw(node2, prop, tokens, customProperty) {
4641
4757
  let token, type;
4642
4758
  let length = tokens.length;
@@ -8269,7 +8385,8 @@ https://www.w3ctech.com/topic/2226`);
8269
8385
  }
8270
8386
  this.endFile();
8271
8387
  }
8272
- precheckMissedSemicolon() {}
8388
+ precheckMissedSemicolon() {
8389
+ }
8273
8390
  raw(node2, prop, tokens, customProperty) {
8274
8391
  let token, type;
8275
8392
  let length = tokens.length;
@@ -9448,7 +9565,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
9448
9565
  function patch(source, name, replacement) {
9449
9566
  try {
9450
9567
  if (!(name in source)) {
9451
- return () => {};
9568
+ return () => {
9569
+ };
9452
9570
  }
9453
9571
  const original = source[name];
9454
9572
  const wrapped = replacement(original);
@@ -9466,7 +9584,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
9466
9584
  source[name] = original;
9467
9585
  };
9468
9586
  } catch {
9469
- return () => {};
9587
+ return () => {
9588
+ };
9470
9589
  }
9471
9590
  }
9472
9591
  var nowTimestamp = Date.now;
@@ -9512,7 +9631,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
9512
9631
  if (classMatchesRegex(el, blockClass, checkAncestors))
9513
9632
  return true;
9514
9633
  }
9515
- } catch (e22) {}
9634
+ } catch (e22) {
9635
+ }
9516
9636
  if (blockSelector) {
9517
9637
  if (el.matches(blockSelector))
9518
9638
  return true;
@@ -10330,7 +10450,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10330
10450
  } else if ("path" in event && event.path.length) {
10331
10451
  return event.path[0];
10332
10452
  }
10333
- } catch {}
10453
+ } catch {
10454
+ }
10334
10455
  return event && event.target;
10335
10456
  }
10336
10457
  function initMutationObserver(options, rootEl) {
@@ -10355,7 +10476,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10355
10476
  mirror: mirror2
10356
10477
  }) {
10357
10478
  if (sampling.mousemove === false) {
10358
- return () => {};
10479
+ return () => {
10480
+ };
10359
10481
  }
10360
10482
  const threshold = typeof sampling.mousemove === "number" ? sampling.mousemove : 50;
10361
10483
  const callbackThreshold = typeof sampling.mousemoveCallback === "number" ? sampling.mousemoveCallback : 500;
@@ -10404,7 +10526,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10404
10526
  sampling
10405
10527
  }) {
10406
10528
  if (sampling.mouseInteraction === false) {
10407
- return () => {};
10529
+ return () => {
10530
+ };
10408
10531
  }
10409
10532
  const disableMap = sampling.mouseInteraction === true || sampling.mouseInteraction === undefined ? {} : sampling.mouseInteraction;
10410
10533
  const handlers = [];
@@ -10659,7 +10782,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10659
10782
  }
10660
10783
  function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetManager }, { win }) {
10661
10784
  if (!win.CSSStyleSheet || !win.CSSStyleSheet.prototype) {
10662
- return () => {};
10785
+ return () => {
10786
+ };
10663
10787
  }
10664
10788
  const insertRule = win.CSSStyleSheet.prototype.insertRule;
10665
10789
  win.CSSStyleSheet.prototype.insertRule = new Proxy(insertRule, {
@@ -10817,7 +10941,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10817
10941
  const patchTarget = host2.nodeName === "#document" ? (_a2 = host2.defaultView) == null ? undefined : _a2.Document : (_c = (_b = host2.ownerDocument) == null ? undefined : _b.defaultView) == null ? undefined : _c.ShadowRoot;
10818
10942
  const originalPropertyDescriptor = (patchTarget == null ? undefined : patchTarget.prototype) ? Object.getOwnPropertyDescriptor(patchTarget == null ? undefined : patchTarget.prototype, "adoptedStyleSheets") : undefined;
10819
10943
  if (hostId === null || hostId === -1 || !patchTarget || !originalPropertyDescriptor)
10820
- return () => {};
10944
+ return () => {
10945
+ };
10821
10946
  Object.defineProperty(host2, "adoptedStyleSheets", {
10822
10947
  configurable: originalPropertyDescriptor.configurable,
10823
10948
  enumerable: originalPropertyDescriptor.enumerable,
@@ -10831,7 +10956,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10831
10956
  if (hostId !== null && hostId !== -1) {
10832
10957
  try {
10833
10958
  stylesheetManager.adoptStyleSheets(sheets, hostId);
10834
- } catch (e22) {}
10959
+ } catch (e22) {
10960
+ }
10835
10961
  }
10836
10962
  return result2;
10837
10963
  }
@@ -10940,7 +11066,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
10940
11066
  function initFontObserver({ fontCb, doc }) {
10941
11067
  const win = doc.defaultView;
10942
11068
  if (!win) {
10943
- return () => {};
11069
+ return () => {
11070
+ };
10944
11071
  }
10945
11072
  const handlers = [];
10946
11073
  const fontMap = /* @__PURE__ */ new WeakMap;
@@ -11009,7 +11136,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
11009
11136
  }) {
11010
11137
  const win = doc.defaultView;
11011
11138
  if (!win || !win.customElements)
11012
- return () => {};
11139
+ return () => {
11140
+ };
11013
11141
  const restoreHandler = patch(win.customElements, "define", function(original) {
11014
11142
  return function(name, constructor, options) {
11015
11143
  try {
@@ -11124,7 +11252,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
11124
11252
  function initObservers(o2, hooks = {}) {
11125
11253
  const currentWindow = o2.doc.defaultView;
11126
11254
  if (!currentWindow) {
11127
- return () => {};
11255
+ return () => {
11256
+ };
11128
11257
  }
11129
11258
  mergeHooks(o2, hooks);
11130
11259
  let mutationObserver;
@@ -11139,10 +11268,14 @@ or you can use record.mirror to access the mirror instance during recording.`;
11139
11268
  });
11140
11269
  const inputHandler = initInputObserver(o2);
11141
11270
  const mediaInteractionHandler = initMediaInteractionObserver(o2);
11142
- let styleSheetObserver = () => {};
11143
- let adoptedStyleSheetObserver = () => {};
11144
- let styleDeclarationObserver = () => {};
11145
- let fontObserver = () => {};
11271
+ let styleSheetObserver = () => {
11272
+ };
11273
+ let adoptedStyleSheetObserver = () => {
11274
+ };
11275
+ let styleDeclarationObserver = () => {
11276
+ };
11277
+ let fontObserver = () => {
11278
+ };
11146
11279
  if (o2.recordDOM) {
11147
11280
  styleSheetObserver = initStyleSheetObserver(o2, { win: currentWindow });
11148
11281
  adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o2, o2.doc);
@@ -11529,7 +11662,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
11529
11662
  this.restoreHandlers.forEach((handler) => {
11530
11663
  try {
11531
11664
  handler();
11532
- } catch (e22) {}
11665
+ } catch (e22) {
11666
+ }
11533
11667
  });
11534
11668
  this.restoreHandlers = [];
11535
11669
  this.shadowDoms = /* @__PURE__ */ new WeakSet;
@@ -12065,7 +12199,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
12065
12199
  this.styleMirror.reset();
12066
12200
  this.trackedLinkElements = /* @__PURE__ */ new WeakSet;
12067
12201
  }
12068
- trackStylesheetInLinkElement(_linkEl) {}
12202
+ trackStylesheetInLinkElement(_linkEl) {
12203
+ }
12069
12204
  }
12070
12205
 
12071
12206
  class ProcessedNodeManager {
@@ -12087,7 +12222,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
12087
12222
  }
12088
12223
  this.nodeMap.set(node2, (this.nodeMap.get(node2) || /* @__PURE__ */ new Set).add(buffer));
12089
12224
  }
12090
- destroy() {}
12225
+ destroy() {
12226
+ }
12091
12227
  }
12092
12228
  var wrappedEmit;
12093
12229
  var takeFullSnapshot$1;
@@ -12154,7 +12290,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
12154
12290
  throw new Error("emit function is required");
12155
12291
  }
12156
12292
  if (!inEmittingFrame && !passEmitsToParent) {
12157
- return () => {};
12293
+ return () => {
12294
+ };
12158
12295
  }
12159
12296
  if (mousemoveWait !== undefined && sampling.mousemove === undefined) {
12160
12297
  sampling.mousemove = mousemoveWait;
@@ -12696,23 +12833,23 @@ or you can use record.mirror to access the mirror instance during recording.`;
12696
12833
  var i2;
12697
12834
  var hMap = function(cd, mb, r2) {
12698
12835
  var s2 = cd.length;
12699
- var i3 = 0;
12836
+ var i2 = 0;
12700
12837
  var l2 = new u16(mb);
12701
- for (;i3 < s2; ++i3)
12702
- ++l2[cd[i3] - 1];
12838
+ for (;i2 < s2; ++i2)
12839
+ ++l2[cd[i2] - 1];
12703
12840
  var le = new u16(mb);
12704
- for (i3 = 0;i3 < mb; ++i3) {
12705
- le[i3] = le[i3 - 1] + l2[i3 - 1] << 1;
12841
+ for (i2 = 0;i2 < mb; ++i2) {
12842
+ le[i2] = le[i2 - 1] + l2[i2 - 1] << 1;
12706
12843
  }
12707
12844
  var co;
12708
12845
  if (r2) {
12709
12846
  co = new u16(1 << mb);
12710
12847
  var rvb = 15 - mb;
12711
- for (i3 = 0;i3 < s2; ++i3) {
12712
- if (cd[i3]) {
12713
- var sv = i3 << 4 | cd[i3];
12714
- var r_1 = mb - cd[i3];
12715
- var v2 = le[cd[i3] - 1]++ << r_1;
12848
+ for (i2 = 0;i2 < s2; ++i2) {
12849
+ if (cd[i2]) {
12850
+ var sv = i2 << 4 | cd[i2];
12851
+ var r_1 = mb - cd[i2];
12852
+ var v2 = le[cd[i2] - 1]++ << r_1;
12716
12853
  for (var m2 = v2 | (1 << r_1) - 1;v2 <= m2; ++v2) {
12717
12854
  co[rev[v2] >>> rvb] = sv;
12718
12855
  }
@@ -12720,8 +12857,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
12720
12857
  }
12721
12858
  } else {
12722
12859
  co = new u16(s2);
12723
- for (i3 = 0;i3 < s2; ++i3)
12724
- co[i3] = rev[le[cd[i3] - 1]++] >>> 15 - cd[i3];
12860
+ for (i2 = 0;i2 < s2; ++i2)
12861
+ co[i2] = rev[le[cd[i2] - 1]++] >>> 15 - cd[i2];
12725
12862
  }
12726
12863
  return co;
12727
12864
  };
@@ -12769,9 +12906,9 @@ or you can use record.mirror to access the mirror instance during recording.`;
12769
12906
  };
12770
12907
  var hTree = function(d2, mb) {
12771
12908
  var t2 = [];
12772
- for (var i3 = 0;i3 < d2.length; ++i3) {
12773
- if (d2[i3])
12774
- t2.push({ s: i3, f: d2[i3] });
12909
+ for (var i2 = 0;i2 < d2.length; ++i2) {
12910
+ if (d2[i2])
12911
+ t2.push({ s: i2, f: d2[i2] });
12775
12912
  }
12776
12913
  var s2 = t2.length;
12777
12914
  var t22 = t2.slice();
@@ -12794,20 +12931,20 @@ or you can use record.mirror to access the mirror instance during recording.`;
12794
12931
  t2[i1++] = { s: -1, f: l2.f + r2.f, l: l2, r: r2 };
12795
12932
  }
12796
12933
  var maxSym = t22[0].s;
12797
- for (var i3 = 1;i3 < s2; ++i3) {
12798
- if (t22[i3].s > maxSym)
12799
- maxSym = t22[i3].s;
12934
+ for (var i2 = 1;i2 < s2; ++i2) {
12935
+ if (t22[i2].s > maxSym)
12936
+ maxSym = t22[i2].s;
12800
12937
  }
12801
12938
  var tr = new u16(maxSym + 1);
12802
12939
  var mbt = ln(t2[i1 - 1], tr, 0);
12803
12940
  if (mbt > mb) {
12804
- var i3 = 0, dt = 0;
12941
+ var i2 = 0, dt = 0;
12805
12942
  var lft = mbt - mb, cst = 1 << lft;
12806
12943
  t22.sort(function(a2, b2) {
12807
12944
  return tr[b2.s] - tr[a2.s] || a2.f - b2.f;
12808
12945
  });
12809
- for (;i3 < s2; ++i3) {
12810
- var i2_1 = t22[i3].s;
12946
+ for (;i2 < s2; ++i2) {
12947
+ var i2_1 = t22[i2].s;
12811
12948
  if (tr[i2_1] > mb) {
12812
12949
  dt += cst - (1 << mbt - tr[i2_1]);
12813
12950
  tr[i2_1] = mb;
@@ -12816,14 +12953,14 @@ or you can use record.mirror to access the mirror instance during recording.`;
12816
12953
  }
12817
12954
  dt >>>= lft;
12818
12955
  while (dt > 0) {
12819
- var i2_2 = t22[i3].s;
12956
+ var i2_2 = t22[i2].s;
12820
12957
  if (tr[i2_2] < mb)
12821
12958
  dt -= 1 << mb - tr[i2_2]++ - 1;
12822
12959
  else
12823
- ++i3;
12960
+ ++i2;
12824
12961
  }
12825
- for (;i3 >= 0 && dt; --i3) {
12826
- var i2_3 = t22[i3].s;
12962
+ for (;i2 >= 0 && dt; --i2) {
12963
+ var i2_3 = t22[i2].s;
12827
12964
  if (tr[i2_3] == mb) {
12828
12965
  --tr[i2_3];
12829
12966
  ++dt;
@@ -12845,8 +12982,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
12845
12982
  var w2 = function(v2) {
12846
12983
  cl[cli++] = v2;
12847
12984
  };
12848
- for (var i3 = 1;i3 <= s2; ++i3) {
12849
- if (c2[i3] == cln && i3 != s2)
12985
+ for (var i2 = 1;i2 <= s2; ++i2) {
12986
+ if (c2[i2] == cln && i2 != s2)
12850
12987
  ++cls;
12851
12988
  else {
12852
12989
  if (!cln && cls > 2) {
@@ -12866,15 +13003,15 @@ or you can use record.mirror to access the mirror instance during recording.`;
12866
13003
  while (cls--)
12867
13004
  w2(cln);
12868
13005
  cls = 1;
12869
- cln = c2[i3];
13006
+ cln = c2[i2];
12870
13007
  }
12871
13008
  }
12872
13009
  return [cl.subarray(0, cli), s2];
12873
13010
  };
12874
13011
  var clen = function(cf, cl) {
12875
13012
  var l2 = 0;
12876
- for (var i3 = 0;i3 < cl.length; ++i3)
12877
- l2 += cf[i3] * cl[i3];
13013
+ for (var i2 = 0;i2 < cl.length; ++i2)
13014
+ l2 += cf[i2] * cl[i2];
12878
13015
  return l2;
12879
13016
  };
12880
13017
  var wfblk = function(out, pos, dat) {
@@ -12884,8 +13021,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
12884
13021
  out[o2 + 1] = s2 >>> 8;
12885
13022
  out[o2 + 2] = out[o2] ^ 255;
12886
13023
  out[o2 + 3] = out[o2 + 1] ^ 255;
12887
- for (var i3 = 0;i3 < s2; ++i3)
12888
- out[o2 + i3 + 4] = dat[i3];
13024
+ for (var i2 = 0;i2 < s2; ++i2)
13025
+ out[o2 + i2 + 4] = dat[i2];
12889
13026
  return (o2 + 4 + s2) * 8;
12890
13027
  };
12891
13028
  var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p2) {
@@ -12896,10 +13033,10 @@ or you can use record.mirror to access the mirror instance during recording.`;
12896
13033
  var _c = lc(dlt), lclt = _c[0], nlc = _c[1];
12897
13034
  var _d = lc(ddt), lcdt = _d[0], ndc = _d[1];
12898
13035
  var lcfreq = new u16(19);
12899
- for (var i3 = 0;i3 < lclt.length; ++i3)
12900
- lcfreq[lclt[i3] & 31]++;
12901
- for (var i3 = 0;i3 < lcdt.length; ++i3)
12902
- lcfreq[lcdt[i3] & 31]++;
13036
+ for (var i2 = 0;i2 < lclt.length; ++i2)
13037
+ lcfreq[lclt[i2] & 31]++;
13038
+ for (var i2 = 0;i2 < lcdt.length; ++i2)
13039
+ lcfreq[lcdt[i2] & 31]++;
12903
13040
  var _e = hTree(lcfreq, 7), lct = _e[0], mlcb = _e[1];
12904
13041
  var nlcc = 19;
12905
13042
  for (;nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
@@ -12918,34 +13055,34 @@ or you can use record.mirror to access the mirror instance during recording.`;
12918
13055
  wbits(out, p2 + 5, ndc - 1);
12919
13056
  wbits(out, p2 + 10, nlcc - 4);
12920
13057
  p2 += 14;
12921
- for (var i3 = 0;i3 < nlcc; ++i3)
12922
- wbits(out, p2 + 3 * i3, lct[clim[i3]]);
13058
+ for (var i2 = 0;i2 < nlcc; ++i2)
13059
+ wbits(out, p2 + 3 * i2, lct[clim[i2]]);
12923
13060
  p2 += 3 * nlcc;
12924
13061
  var lcts = [lclt, lcdt];
12925
13062
  for (var it = 0;it < 2; ++it) {
12926
13063
  var clct = lcts[it];
12927
- for (var i3 = 0;i3 < clct.length; ++i3) {
12928
- var len = clct[i3] & 31;
13064
+ for (var i2 = 0;i2 < clct.length; ++i2) {
13065
+ var len = clct[i2] & 31;
12929
13066
  wbits(out, p2, llm[len]), p2 += lct[len];
12930
13067
  if (len > 15)
12931
- wbits(out, p2, clct[i3] >>> 5 & 127), p2 += clct[i3] >>> 12;
13068
+ wbits(out, p2, clct[i2] >>> 5 & 127), p2 += clct[i2] >>> 12;
12932
13069
  }
12933
13070
  }
12934
13071
  } else {
12935
13072
  lm = flm, ll = flt, dm = fdm, dl = fdt;
12936
13073
  }
12937
- for (var i3 = 0;i3 < li; ++i3) {
12938
- if (syms[i3] > 255) {
12939
- var len = syms[i3] >>> 18 & 31;
13074
+ for (var i2 = 0;i2 < li; ++i2) {
13075
+ if (syms[i2] > 255) {
13076
+ var len = syms[i2] >>> 18 & 31;
12940
13077
  wbits16(out, p2, lm[len + 257]), p2 += ll[len + 257];
12941
13078
  if (len > 7)
12942
- wbits(out, p2, syms[i3] >>> 23 & 31), p2 += fleb[len];
12943
- var dst = syms[i3] & 31;
13079
+ wbits(out, p2, syms[i2] >>> 23 & 31), p2 += fleb[len];
13080
+ var dst = syms[i2] & 31;
12944
13081
  wbits16(out, p2, dm[dst]), p2 += dl[dst];
12945
13082
  if (dst > 3)
12946
- wbits16(out, p2, syms[i3] >>> 5 & 8191), p2 += fdeb[dst];
13083
+ wbits16(out, p2, syms[i2] >>> 5 & 8191), p2 += fdeb[dst];
12947
13084
  } else {
12948
- wbits16(out, p2, lm[syms[i3]]), p2 += ll[syms[i3]];
13085
+ wbits16(out, p2, lm[syms[i2]]), p2 += ll[syms[i2]];
12949
13086
  }
12950
13087
  }
12951
13088
  wbits16(out, p2, lm[256]);
@@ -12958,13 +13095,13 @@ or you can use record.mirror to access the mirror instance during recording.`;
12958
13095
  var w2 = o2.subarray(pre, o2.length - post);
12959
13096
  var pos = 0;
12960
13097
  if (!lvl || s2 < 8) {
12961
- for (var i3 = 0;i3 <= s2; i3 += 65535) {
12962
- var e3 = i3 + 65535;
13098
+ for (var i2 = 0;i2 <= s2; i2 += 65535) {
13099
+ var e3 = i2 + 65535;
12963
13100
  if (e3 < s2) {
12964
- pos = wfblk(w2, pos, dat.subarray(i3, e3));
13101
+ pos = wfblk(w2, pos, dat.subarray(i2, e3));
12965
13102
  } else {
12966
- w2[i3] = lst;
12967
- pos = wfblk(w2, pos, dat.subarray(i3, s2));
13103
+ w2[i2] = lst;
13104
+ pos = wfblk(w2, pos, dat.subarray(i2, s2));
12968
13105
  }
12969
13106
  }
12970
13107
  } else {
@@ -12978,32 +13115,32 @@ or you can use record.mirror to access the mirror instance during recording.`;
12978
13115
  };
12979
13116
  var syms = new u32(25000);
12980
13117
  var lf = new u16(288), df = new u16(32);
12981
- var lc_1 = 0, eb = 0, i3 = 0, li = 0, wi = 0, bs = 0;
12982
- for (;i3 < s2; ++i3) {
12983
- var hv = hsh(i3);
12984
- var imod = i3 & 32767;
13118
+ var lc_1 = 0, eb = 0, i2 = 0, li = 0, wi = 0, bs = 0;
13119
+ for (;i2 < s2; ++i2) {
13120
+ var hv = hsh(i2);
13121
+ var imod = i2 & 32767;
12985
13122
  var pimod = head[hv];
12986
13123
  prev[imod] = pimod;
12987
13124
  head[hv] = imod;
12988
- if (wi <= i3) {
12989
- var rem = s2 - i3;
13125
+ if (wi <= i2) {
13126
+ var rem = s2 - i2;
12990
13127
  if ((lc_1 > 7000 || li > 24576) && rem > 423) {
12991
- pos = wblk(dat, w2, 0, syms, lf, df, eb, li, bs, i3 - bs, pos);
12992
- li = lc_1 = eb = 0, bs = i3;
13128
+ pos = wblk(dat, w2, 0, syms, lf, df, eb, li, bs, i2 - bs, pos);
13129
+ li = lc_1 = eb = 0, bs = i2;
12993
13130
  for (var j2 = 0;j2 < 286; ++j2)
12994
13131
  lf[j2] = 0;
12995
13132
  for (var j2 = 0;j2 < 30; ++j2)
12996
13133
  df[j2] = 0;
12997
13134
  }
12998
13135
  var l2 = 2, d2 = 0, ch_1 = c2, dif = imod - pimod & 32767;
12999
- if (rem > 2 && hv == hsh(i3 - dif)) {
13136
+ if (rem > 2 && hv == hsh(i2 - dif)) {
13000
13137
  var maxn = Math.min(n3, rem) - 1;
13001
- var maxd = Math.min(32767, i3);
13138
+ var maxd = Math.min(32767, i2);
13002
13139
  var ml = Math.min(258, rem);
13003
13140
  while (dif <= maxd && --ch_1 && imod != pimod) {
13004
- if (dat[i3 + l2] == dat[i3 + l2 - dif]) {
13141
+ if (dat[i2 + l2] == dat[i2 + l2 - dif]) {
13005
13142
  var nl = 0;
13006
- for (;nl < ml && dat[i3 + nl] == dat[i3 + nl - dif]; ++nl)
13143
+ for (;nl < ml && dat[i2 + nl] == dat[i2 + nl - dif]; ++nl)
13007
13144
  ;
13008
13145
  if (nl > l2) {
13009
13146
  l2 = nl, d2 = dif;
@@ -13012,7 +13149,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13012
13149
  var mmd = Math.min(dif, nl - 2);
13013
13150
  var md = 0;
13014
13151
  for (var j2 = 0;j2 < mmd; ++j2) {
13015
- var ti = i3 - dif + j2 + 32768 & 32767;
13152
+ var ti = i2 - dif + j2 + 32768 & 32767;
13016
13153
  var pti = prev[ti];
13017
13154
  var cd = ti - pti + 32768 & 32767;
13018
13155
  if (cd > md)
@@ -13030,15 +13167,15 @@ or you can use record.mirror to access the mirror instance during recording.`;
13030
13167
  eb += fleb[lin] + fdeb[din];
13031
13168
  ++lf[257 + lin];
13032
13169
  ++df[din];
13033
- wi = i3 + l2;
13170
+ wi = i2 + l2;
13034
13171
  ++lc_1;
13035
13172
  } else {
13036
- syms[li++] = dat[i3];
13037
- ++lf[dat[i3]];
13173
+ syms[li++] = dat[i2];
13174
+ ++lf[dat[i2]];
13038
13175
  }
13039
13176
  }
13040
13177
  }
13041
- pos = wblk(dat, w2, lst, syms, lf, df, eb, li, bs, i3 - bs, pos);
13178
+ pos = wblk(dat, w2, lst, syms, lf, df, eb, li, bs, i2 - bs, pos);
13042
13179
  }
13043
13180
  return slc(o2, 0, pre + shft(pos) + post);
13044
13181
  };
@@ -13048,10 +13185,10 @@ or you can use record.mirror to access the mirror instance during recording.`;
13048
13185
  p: function(d2) {
13049
13186
  var n3 = a2, m2 = b2;
13050
13187
  var l2 = d2.length;
13051
- for (var i3 = 0;i3 != l2; ) {
13052
- var e3 = Math.min(i3 + 5552, l2);
13053
- for (;i3 < e3; ++i3)
13054
- n3 += d2[i3], m2 += n3;
13188
+ for (var i2 = 0;i2 != l2; ) {
13189
+ var e3 = Math.min(i2 + 5552, l2);
13190
+ for (;i2 < e3; ++i2)
13191
+ n3 += d2[i2], m2 += n3;
13055
13192
  n3 %= 65521, m2 %= 65521;
13056
13193
  }
13057
13194
  a2 = n3, b2 = m2;
@@ -13090,19 +13227,19 @@ or you can use record.mirror to access the mirror instance during recording.`;
13090
13227
  var w2 = function(v2) {
13091
13228
  ar[ai++] = v2;
13092
13229
  };
13093
- for (var i3 = 0;i3 < l2; ++i3) {
13230
+ for (var i2 = 0;i2 < l2; ++i2) {
13094
13231
  if (ai + 5 > ar.length) {
13095
- var n3 = new u8(ai + 8 + (l2 - i3 << 1));
13232
+ var n3 = new u8(ai + 8 + (l2 - i2 << 1));
13096
13233
  n3.set(ar);
13097
13234
  ar = n3;
13098
13235
  }
13099
- var c2 = str.charCodeAt(i3);
13236
+ var c2 = str.charCodeAt(i2);
13100
13237
  if (c2 < 128 || latin1)
13101
13238
  w2(c2);
13102
13239
  else if (c2 < 2048)
13103
13240
  w2(192 | c2 >>> 6), w2(128 | c2 & 63);
13104
13241
  else if (c2 > 55295 && c2 < 57344)
13105
- c2 = 65536 + (c2 & 1023 << 10) | str.charCodeAt(++i3) & 1023, w2(240 | c2 >>> 18), w2(128 | c2 >>> 12 & 63), w2(128 | c2 >>> 6 & 63), w2(128 | c2 & 63);
13242
+ c2 = 65536 + (c2 & 1023 << 10) | str.charCodeAt(++i2) & 1023, w2(240 | c2 >>> 18), w2(128 | c2 >>> 12 & 63), w2(128 | c2 >>> 6 & 63), w2(128 | c2 & 63);
13106
13243
  else
13107
13244
  w2(224 | c2 >>> 12), w2(128 | c2 >>> 6 & 63), w2(128 | c2 & 63);
13108
13245
  }
@@ -13112,16 +13249,16 @@ or you can use record.mirror to access the mirror instance during recording.`;
13112
13249
  var r2 = "";
13113
13250
  if (!latin1 && typeof TextDecoder != "undefined")
13114
13251
  return new TextDecoder().decode(dat);
13115
- for (var i3 = 0;i3 < dat.length; ) {
13116
- var c2 = dat[i3++];
13252
+ for (var i2 = 0;i2 < dat.length; ) {
13253
+ var c2 = dat[i2++];
13117
13254
  if (c2 < 128 || latin1)
13118
13255
  r2 += String.fromCharCode(c2);
13119
13256
  else if (c2 < 224)
13120
- r2 += String.fromCharCode((c2 & 31) << 6 | dat[i3++] & 63);
13257
+ r2 += String.fromCharCode((c2 & 31) << 6 | dat[i2++] & 63);
13121
13258
  else if (c2 < 240)
13122
- r2 += String.fromCharCode((c2 & 15) << 12 | (dat[i3++] & 63) << 6 | dat[i3++] & 63);
13259
+ r2 += String.fromCharCode((c2 & 15) << 12 | (dat[i2++] & 63) << 6 | dat[i2++] & 63);
13123
13260
  else
13124
- c2 = ((c2 & 15) << 18 | (dat[i3++] & 63) << 12 | (dat[i3++] & 63) << 6 | dat[i3++] & 63) - 65536, r2 += String.fromCharCode(55296 | c2 >> 10, 56320 | c2 & 1023);
13261
+ c2 = ((c2 & 15) << 18 | (dat[i2++] & 63) << 12 | (dat[i2++] & 63) << 6 | dat[i2++] & 63) - 65536, r2 += String.fromCharCode(55296 | c2 >> 10, 56320 | c2 & 1023);
13125
13262
  }
13126
13263
  return r2;
13127
13264
  }
@@ -13137,22 +13274,26 @@ or you can use record.mirror to access the mirror instance during recording.`;
13137
13274
  };
13138
13275
 
13139
13276
  // ../analytics-core/dist/SessionRecorder.js
13140
- function generateSessionId() {
13277
+ var ACTIVITY_EVENTS = [
13278
+ "pointerdown",
13279
+ "keydown",
13280
+ "scroll",
13281
+ "touchstart",
13282
+ "wheel",
13283
+ "mousemove"
13284
+ ];
13285
+ var IDLE_CHECK_CEILING_MS = 15000;
13286
+ function randomId2(prefix) {
13141
13287
  if (typeof crypto !== "undefined" && crypto.randomUUID) {
13142
13288
  return crypto.randomUUID();
13143
13289
  }
13144
- return `session_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
13290
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
13145
13291
  }
13146
- function generateVisitorId() {
13147
- if (typeof localStorage !== "undefined") {
13148
- let visitorId = localStorage.getItem("temps_visitor_id");
13149
- if (!visitorId) {
13150
- visitorId = `visitor_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
13151
- localStorage.setItem("temps_visitor_id", visitorId);
13152
- }
13153
- return visitorId;
13154
- }
13155
- return `visitor_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
13292
+ function generateSessionId() {
13293
+ return randomId2("session");
13294
+ }
13295
+ function generateBatchId() {
13296
+ return randomId2("batch");
13156
13297
  }
13157
13298
  function matchesAnyPath(currentPath, paths) {
13158
13299
  return paths.some((path) => {
@@ -13160,13 +13301,24 @@ or you can use record.mirror to access the mirror instance during recording.`;
13160
13301
  return regex.test(currentPath);
13161
13302
  });
13162
13303
  }
13304
+ function rememberRecordingSessionId(sessionId) {
13305
+ try {
13306
+ if (typeof localStorage === "undefined")
13307
+ return;
13308
+ if (sessionId === null)
13309
+ localStorage.removeItem("currentRecordingSessionId");
13310
+ else
13311
+ localStorage.setItem("currentRecordingSessionId", sessionId);
13312
+ } catch {
13313
+ }
13314
+ }
13163
13315
  function getSessionMetadata() {
13164
13316
  if (typeof window === "undefined")
13165
13317
  return {};
13166
13318
  const screen = window.screen || {};
13167
13319
  const nav = window.navigator || {};
13168
13320
  return {
13169
- visitorId: generateVisitorId(),
13321
+ visitorId: getOrCreateVisitorId() ?? randomId2("visitor"),
13170
13322
  userAgent: nav.userAgent,
13171
13323
  language: nav.language,
13172
13324
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
@@ -13182,12 +13334,15 @@ or you can use record.mirror to access the mirror instance during recording.`;
13182
13334
 
13183
13335
  class SessionRecorder {
13184
13336
  constructor(options = {}) {
13337
+ this.reportedFailures = new Set;
13185
13338
  this.stopFn = null;
13186
13339
  this.takeSnapshot = null;
13187
- this.events = [];
13340
+ this.pending = [];
13341
+ this.inflight = null;
13188
13342
  this.sessionId = "";
13189
13343
  this.sessionInitialized = false;
13190
13344
  this.flushTimer = null;
13345
+ this.idleTimer = null;
13191
13346
  this.initRetryCount = 0;
13192
13347
  this.initFailed = false;
13193
13348
  this.maxInitRetries = 3;
@@ -13195,15 +13350,36 @@ or you can use record.mirror to access the mirror instance during recording.`;
13195
13350
  this.maxSendRetries = 5;
13196
13351
  this.lastSendAttempt = 0;
13197
13352
  this.isSending = false;
13353
+ this.starting = false;
13354
+ this.stopGeneration = 0;
13355
+ this.paused = false;
13356
+ this.lastActivityAt = Date.now();
13357
+ this.droppedEvents = 0;
13358
+ this.sampleDecision = null;
13198
13359
  this.originalPushState = null;
13199
13360
  this.originalReplaceState = null;
13361
+ this.globalListenersAttached = false;
13362
+ this.handleActivity = () => {
13363
+ this.lastActivityAt = Date.now();
13364
+ if (this.paused)
13365
+ this.resumeRecording();
13366
+ };
13367
+ this.handleVisibilityChange = () => {
13368
+ if (!this.pauseOnHidden)
13369
+ return;
13370
+ if (document.visibilityState === "hidden") {
13371
+ this.pauseRecording();
13372
+ } else {
13373
+ this.handleActivity();
13374
+ }
13375
+ };
13200
13376
  this.handleUnload = () => {
13201
- if (this.sessionInitialized && this.events.length > 0) {
13377
+ if (this.sessionInitialized && this.hasBufferedEvents()) {
13202
13378
  this.sendEvents(true);
13203
13379
  }
13204
13380
  };
13205
13381
  this.handlePopState = () => {
13206
- if (this.stopFn && this.events.length > 0)
13382
+ if (this.stopFn && this.hasBufferedEvents())
13207
13383
  this.sendEvents(false);
13208
13384
  setTimeout(() => {
13209
13385
  this.checkPath();
@@ -13212,6 +13388,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13212
13388
  }, 100);
13213
13389
  };
13214
13390
  this.basePath = options.basePath || DEFAULT_BASE_PATH;
13391
+ this.ingestKey = options.ingestKey;
13215
13392
  this.excludedPaths = options.useDefaultExcludedPaths === false ? options.excludedPaths || [] : [...DEFAULT_EXCLUDED_PATHS, ...options.excludedPaths || []];
13216
13393
  this.sessionSampleRate = options.sessionSampleRate ?? 1;
13217
13394
  this.maskAllInputs = options.maskAllInputs ?? true;
@@ -13225,6 +13402,11 @@ or you can use record.mirror to access the mirror instance during recording.`;
13225
13402
  this.collectFonts = options.collectFonts ?? true;
13226
13403
  this.batchSize = options.batchSize ?? 100;
13227
13404
  this.flushInterval = options.flushInterval ?? 1e4;
13405
+ this.idleTimeout = options.idleTimeout ?? 60000;
13406
+ this.pauseOnHidden = options.pauseOnHidden ?? true;
13407
+ this.checkoutEveryNms = options.checkoutEveryNms ?? 30000;
13408
+ this.checkoutEveryNth = options.checkoutEveryNth ?? 200;
13409
+ this.maxBufferedEvents = options.maxBufferedEvents ?? 5000;
13228
13410
  this.slimDOMOptions = options.slimDOMOptions || {
13229
13411
  script: false,
13230
13412
  comment: true,
@@ -13256,22 +13438,44 @@ or you can use record.mirror to access the mirror instance during recording.`;
13256
13438
  input: "last",
13257
13439
  ...options.sampling || {}
13258
13440
  };
13441
+ this.debug = options.debug ?? false;
13259
13442
  this.enabled = options.enabled ?? false;
13260
13443
  if (this.enabled && typeof window !== "undefined") {
13261
13444
  this.start();
13262
13445
  }
13263
13446
  }
13447
+ passesSampling() {
13448
+ if (this.sampleDecision === null) {
13449
+ this.sampleDecision = this.sessionSampleRate >= 1 || Math.random() <= this.sessionSampleRate;
13450
+ }
13451
+ return this.sampleDecision;
13452
+ }
13264
13453
  shouldRecord() {
13265
13454
  if (!this.enabled || typeof window === "undefined")
13266
13455
  return false;
13267
- const currentPath = window.location.pathname;
13268
- const isExcluded = matchesAnyPath(currentPath, this.excludedPaths);
13269
- if (isExcluded)
13456
+ if (matchesAnyPath(window.location.pathname, this.excludedPaths)) {
13457
+ this.debugLog(`not recording ${window.location.pathname}: excluded path`);
13270
13458
  return false;
13271
- if (this.sessionSampleRate < 1 && Math.random() > this.sessionSampleRate)
13459
+ }
13460
+ if (!this.passesSampling()) {
13461
+ this.debugLog(`not recording: sampled out (sessionSampleRate ${this.sessionSampleRate})`);
13272
13462
  return false;
13463
+ }
13273
13464
  return true;
13274
13465
  }
13466
+ reportFailure(kind, detail) {
13467
+ if (!this.debug) {
13468
+ if (this.reportedFailures.has(kind))
13469
+ return;
13470
+ this.reportedFailures.add(kind);
13471
+ }
13472
+ console.warn(`[SessionRecorder] session replay ${kind} failed:`, detail, ...this.debug ? [] : ["(reported once; set sessionRecordingConfig.debug to log every failure)"]);
13473
+ }
13474
+ debugLog(message, ...details) {
13475
+ if (!this.debug)
13476
+ return;
13477
+ console.debug(`[SessionRecorder] ${message}`, ...details);
13478
+ }
13275
13479
  async initializeSession() {
13276
13480
  if (this.sessionInitialized)
13277
13481
  return true;
@@ -13286,34 +13490,49 @@ or you can use record.mirror to access the mirror instance during recording.`;
13286
13490
  this.sessionId = sessionId;
13287
13491
  try {
13288
13492
  const metadata = { sessionId, ...getSessionMetadata() };
13289
- const response = await fetch(`${this.basePath}/${SESSION_RECORDER_ENDPOINT}/init`, {
13493
+ const initUrl = `${this.basePath}/${SESSION_RECORDER_ENDPOINT}/init`;
13494
+ const response = await fetch(initUrl, {
13290
13495
  method: "POST",
13291
- headers: { "Content-Type": "application/json" },
13496
+ headers: {
13497
+ "Content-Type": "application/json",
13498
+ ...ingestKeyHeaders(this.ingestKey)
13499
+ },
13292
13500
  body: JSON.stringify(metadata)
13293
13501
  });
13294
- if (response.status === 201) {
13502
+ if (response.ok) {
13295
13503
  this.sessionInitialized = true;
13296
13504
  this.initRetryCount = 0;
13297
13505
  this.initFailed = false;
13298
- if (typeof localStorage !== "undefined") {
13299
- localStorage.setItem("currentRecordingSessionId", sessionId);
13300
- }
13506
+ rememberRecordingSessionId(sessionId);
13507
+ this.debugLog("session started", sessionId);
13301
13508
  return true;
13302
13509
  }
13510
+ this.reportFailure("init", `HTTP ${response.status} from ${initUrl}`);
13303
13511
  this.sessionId = "";
13304
13512
  if (this.initRetryCount >= this.maxInitRetries)
13305
13513
  this.initFailed = true;
13306
13514
  return false;
13307
13515
  } catch (error) {
13308
- console.error("[SessionRecorder] init failed:", error);
13516
+ this.reportFailure("init", error);
13309
13517
  this.sessionId = "";
13310
13518
  if (this.initRetryCount >= this.maxInitRetries)
13311
13519
  this.initFailed = true;
13312
13520
  return false;
13313
13521
  }
13314
13522
  }
13523
+ claimBatch() {
13524
+ if (this.inflight)
13525
+ return this.inflight;
13526
+ if (this.pending.length === 0)
13527
+ return null;
13528
+ this.inflight = {
13529
+ batchId: generateBatchId(),
13530
+ events: this.pending.splice(0, this.pending.length)
13531
+ };
13532
+ return this.inflight;
13533
+ }
13315
13534
  async sendEvents(isReliable = false) {
13316
- if (!this.sessionInitialized || this.events.length === 0)
13535
+ if (!this.sessionInitialized)
13317
13536
  return;
13318
13537
  if (this.isSending && !isReliable)
13319
13538
  return;
@@ -13323,19 +13542,26 @@ or you can use record.mirror to access the mirror instance during recording.`;
13323
13542
  if (now - this.lastSendAttempt < backoff)
13324
13543
  return;
13325
13544
  }
13545
+ const batch = this.claimBatch();
13546
+ if (!batch)
13547
+ return;
13326
13548
  this.isSending = true;
13327
13549
  this.lastSendAttempt = now;
13328
- const eventsToSend = [...this.events];
13329
13550
  try {
13330
- const packed = pack(eventsToSend);
13551
+ const packed = pack(batch.events);
13331
13552
  const encodedEvents = btoa(packed);
13332
- const payload = { sessionId: this.sessionId, events: encodedEvents };
13553
+ const payload = {
13554
+ sessionId: this.sessionId,
13555
+ batchId: batch.batchId,
13556
+ events: encodedEvents
13557
+ };
13333
13558
  const url = `${this.basePath}/${SESSION_RECORDER_ENDPOINT}/events`;
13559
+ const unloadUrl = withIngestKey(url, this.ingestKey);
13334
13560
  if (isReliable) {
13335
13561
  if (navigator.sendBeacon) {
13336
13562
  const blob2 = new Blob([JSON.stringify(payload)], { type: "application/json" });
13337
- if (!navigator.sendBeacon(url, blob2)) {
13338
- await fetch(url, {
13563
+ if (!navigator.sendBeacon(unloadUrl, blob2)) {
13564
+ await fetch(unloadUrl, {
13339
13565
  method: "POST",
13340
13566
  headers: { "Content-Type": "application/json" },
13341
13567
  body: JSON.stringify(payload),
@@ -13343,122 +13569,192 @@ or you can use record.mirror to access the mirror instance during recording.`;
13343
13569
  });
13344
13570
  }
13345
13571
  } else {
13346
- await fetch(url, {
13572
+ await fetch(unloadUrl, {
13347
13573
  method: "POST",
13348
13574
  headers: { "Content-Type": "application/json" },
13349
13575
  body: JSON.stringify(payload),
13350
13576
  keepalive: true
13351
13577
  });
13352
13578
  }
13353
- this.events = [];
13579
+ this.inflight = null;
13354
13580
  this.sendRetryCount = 0;
13355
13581
  } else {
13356
13582
  const response = await fetch(url, {
13357
13583
  method: "POST",
13358
- headers: { "Content-Type": "application/json" },
13584
+ headers: {
13585
+ "Content-Type": "application/json",
13586
+ ...ingestKeyHeaders(this.ingestKey)
13587
+ },
13359
13588
  body: JSON.stringify(payload)
13360
13589
  });
13361
13590
  if (response.status === 404) {
13362
- this.sessionInitialized = false;
13363
- this.sessionId = "";
13364
- if (typeof localStorage !== "undefined") {
13365
- localStorage.removeItem("currentRecordingSessionId");
13366
- }
13591
+ this.debugLog("the server no longer knows this session; recording stopped");
13592
+ this.clearSession();
13367
13593
  this.stopRecording();
13368
- this.events = [];
13594
+ this.inflight = null;
13595
+ this.pending = [];
13369
13596
  this.sendRetryCount = 0;
13370
13597
  } else if (!response.ok) {
13598
+ this.reportFailure("upload", `HTTP ${response.status} from ${url}`);
13371
13599
  this.sendRetryCount++;
13372
13600
  if (this.sendRetryCount >= this.maxSendRetries) {
13373
- this.events = [];
13601
+ this.inflight = null;
13374
13602
  this.sendRetryCount = 0;
13375
13603
  }
13376
13604
  } else {
13377
- this.events = [];
13605
+ this.inflight = null;
13378
13606
  this.sendRetryCount = 0;
13379
13607
  }
13380
13608
  }
13381
13609
  } catch (error) {
13382
- console.error("[SessionRecorder] send failed:", error);
13610
+ this.reportFailure("upload", error);
13383
13611
  this.sendRetryCount++;
13384
13612
  if (this.sendRetryCount >= this.maxSendRetries) {
13385
- this.events = [];
13613
+ this.inflight = null;
13386
13614
  this.sendRetryCount = 0;
13387
13615
  }
13388
13616
  } finally {
13389
13617
  this.isSending = false;
13390
13618
  }
13391
13619
  }
13392
- scheduleFlush() {
13620
+ hasBufferedEvents() {
13621
+ return this.pending.length > 0 || this.inflight !== null;
13622
+ }
13623
+ startFlushTimer() {
13393
13624
  if (this.flushTimer)
13394
- clearTimeout(this.flushTimer);
13395
- this.flushTimer = setTimeout(() => {
13396
- if (this.events.length > 0)
13625
+ return;
13626
+ this.flushTimer = setInterval(() => {
13627
+ if (this.hasBufferedEvents())
13397
13628
  this.sendEvents(false);
13398
- this.scheduleFlush();
13399
13629
  }, this.flushInterval);
13400
13630
  }
13631
+ stopFlushTimer() {
13632
+ if (!this.flushTimer)
13633
+ return;
13634
+ clearInterval(this.flushTimer);
13635
+ this.flushTimer = null;
13636
+ }
13637
+ startIdleTimer() {
13638
+ if (this.idleTimer || this.idleTimeout <= 0)
13639
+ return;
13640
+ const tick = Math.min(this.idleTimeout, IDLE_CHECK_CEILING_MS);
13641
+ this.idleTimer = setInterval(() => {
13642
+ if (this.paused || !this.stopFn)
13643
+ return;
13644
+ if (Date.now() - this.lastActivityAt >= this.idleTimeout)
13645
+ this.pauseRecording();
13646
+ }, tick);
13647
+ }
13648
+ stopIdleTimer() {
13649
+ if (!this.idleTimer)
13650
+ return;
13651
+ clearInterval(this.idleTimer);
13652
+ this.idleTimer = null;
13653
+ }
13401
13654
  async startRecording() {
13402
- if (this.stopFn || this.initFailed)
13655
+ if (this.stopFn || this.initFailed || this.starting)
13403
13656
  return;
13404
13657
  if (!this.shouldRecord())
13405
13658
  return;
13406
- const ok = await this.initializeSession();
13407
- if (!ok)
13408
- return;
13409
- const stopFn = record({
13410
- emit: (event) => {
13411
- this.events.push(event);
13412
- if (this.events.length >= this.batchSize) {
13413
- this.sendEvents(false);
13414
- this.scheduleFlush();
13415
- }
13416
- },
13417
- sampling: this.samplingConfig,
13418
- blockSelector: this.blockSelector,
13419
- ignoreSelector: this.ignoreSelector,
13420
- recordCanvas: this.recordCanvas,
13421
- collectFonts: this.collectFonts,
13422
- maskAllInputs: this.maskAllInputs,
13423
- maskInputOptions: this.maskInputOptions,
13424
- maskTextSelector: this.maskTextSelector,
13425
- blockClass: this.blockClass,
13426
- ignoreClass: this.ignoreClass,
13427
- maskTextClass: this.maskTextClass,
13428
- slimDOMOptions: this.slimDOMOptions,
13429
- checkoutEveryNms: 30000,
13430
- checkoutEveryNth: 200
13431
- });
13432
- if (stopFn) {
13433
- this.stopFn = stopFn;
13434
- const exposed = stopFn;
13435
- this.takeSnapshot = exposed.takeFullSnapshot || null;
13659
+ this.starting = true;
13660
+ const generation = this.stopGeneration;
13661
+ try {
13662
+ const ok = await this.initializeSession();
13663
+ if (!ok)
13664
+ return;
13665
+ if (this.stopGeneration !== generation || this.stopFn || !this.enabled) {
13666
+ this.clearSession();
13667
+ return;
13668
+ }
13669
+ const stopFn = record({
13670
+ emit: (event) => {
13671
+ this.pending.push(event);
13672
+ if (this.pending.length > this.maxBufferedEvents) {
13673
+ const overflow = this.pending.length - this.maxBufferedEvents;
13674
+ this.pending.splice(0, overflow);
13675
+ this.droppedEvents += overflow;
13676
+ }
13677
+ if (this.pending.length >= this.batchSize)
13678
+ this.sendEvents(false);
13679
+ },
13680
+ sampling: this.samplingConfig,
13681
+ blockSelector: this.blockSelector,
13682
+ ignoreSelector: this.ignoreSelector,
13683
+ recordCanvas: this.recordCanvas,
13684
+ collectFonts: this.collectFonts,
13685
+ maskAllInputs: this.maskAllInputs,
13686
+ maskInputOptions: this.maskInputOptions,
13687
+ maskTextSelector: this.maskTextSelector,
13688
+ blockClass: this.blockClass,
13689
+ ignoreClass: this.ignoreClass,
13690
+ maskTextClass: this.maskTextClass,
13691
+ slimDOMOptions: this.slimDOMOptions,
13692
+ checkoutEveryNms: this.checkoutEveryNms,
13693
+ checkoutEveryNth: this.checkoutEveryNth
13694
+ });
13695
+ if (stopFn) {
13696
+ this.stopFn = stopFn;
13697
+ const exposed = stopFn;
13698
+ this.takeSnapshot = exposed.takeFullSnapshot || null;
13699
+ }
13700
+ this.paused = false;
13701
+ this.lastActivityAt = Date.now();
13702
+ this.startFlushTimer();
13703
+ this.startIdleTimer();
13704
+ } finally {
13705
+ this.starting = false;
13436
13706
  }
13437
- this.scheduleFlush();
13438
13707
  }
13439
- stopRecording() {
13708
+ clearSession() {
13709
+ this.sessionInitialized = false;
13710
+ this.sessionId = "";
13711
+ rememberRecordingSessionId(null);
13712
+ }
13713
+ detachRecorder() {
13440
13714
  if (!this.stopFn)
13441
13715
  return;
13442
13716
  this.stopFn();
13443
13717
  this.stopFn = null;
13444
- if (this.flushTimer) {
13445
- clearTimeout(this.flushTimer);
13446
- this.flushTimer = null;
13447
- }
13718
+ this.takeSnapshot = null;
13719
+ }
13720
+ pauseRecording() {
13721
+ if (this.paused || !this.stopFn)
13722
+ return;
13723
+ this.debugLog("paused (idle or hidden tab)");
13724
+ this.detachRecorder();
13725
+ this.paused = true;
13726
+ this.stopFlushTimer();
13727
+ if (this.hasBufferedEvents())
13728
+ this.sendEvents(false);
13729
+ }
13730
+ resumeRecording() {
13731
+ if (!this.paused || !this.enabled || this.initFailed)
13732
+ return;
13733
+ this.debugLog("resumed");
13734
+ this.paused = false;
13735
+ this.startRecording();
13736
+ }
13737
+ stopRecording() {
13738
+ if (!this.stopFn && !this.paused && !this.starting && !this.sessionInitialized)
13739
+ return;
13740
+ this.stopGeneration++;
13741
+ this.detachRecorder();
13742
+ this.stopFlushTimer();
13743
+ this.stopIdleTimer();
13744
+ this.paused = false;
13448
13745
  this.sendEvents(true);
13449
- this.sessionInitialized = false;
13450
- this.sessionId = "";
13451
- if (typeof localStorage !== "undefined") {
13452
- localStorage.removeItem("currentRecordingSessionId");
13453
- }
13746
+ this.clearSession();
13454
13747
  this.initRetryCount = 0;
13455
13748
  this.initFailed = false;
13456
13749
  }
13457
- wrapHistory() {
13750
+ attachGlobalListeners() {
13751
+ if (this.globalListenersAttached)
13752
+ return;
13753
+ this.globalListenersAttached = true;
13458
13754
  this.originalPushState = window.history.pushState;
13459
13755
  this.originalReplaceState = window.history.replaceState;
13460
13756
  const flushAndCheck = () => {
13461
- if (this.stopFn && this.events.length > 0)
13757
+ if (this.stopFn && this.hasBufferedEvents())
13462
13758
  this.sendEvents(false);
13463
13759
  setTimeout(() => {
13464
13760
  this.checkPath();
@@ -13477,6 +13773,30 @@ or you can use record.mirror to access the mirror instance during recording.`;
13477
13773
  window.addEventListener("popstate", this.handlePopState);
13478
13774
  window.addEventListener("beforeunload", this.handleUnload);
13479
13775
  window.addEventListener("pagehide", this.handleUnload);
13776
+ document.addEventListener("visibilitychange", this.handleVisibilityChange);
13777
+ for (const name of ACTIVITY_EVENTS) {
13778
+ window.addEventListener(name, this.handleActivity, { passive: true, capture: true });
13779
+ }
13780
+ }
13781
+ detachGlobalListeners() {
13782
+ if (!this.globalListenersAttached)
13783
+ return;
13784
+ this.globalListenersAttached = false;
13785
+ if (this.originalPushState) {
13786
+ window.history.pushState = this.originalPushState;
13787
+ this.originalPushState = null;
13788
+ }
13789
+ if (this.originalReplaceState) {
13790
+ window.history.replaceState = this.originalReplaceState;
13791
+ this.originalReplaceState = null;
13792
+ }
13793
+ window.removeEventListener("popstate", this.handlePopState);
13794
+ window.removeEventListener("beforeunload", this.handleUnload);
13795
+ window.removeEventListener("pagehide", this.handleUnload);
13796
+ document.removeEventListener("visibilitychange", this.handleVisibilityChange);
13797
+ for (const name of ACTIVITY_EVENTS) {
13798
+ window.removeEventListener(name, this.handleActivity, { capture: true });
13799
+ }
13480
13800
  }
13481
13801
  checkPath() {
13482
13802
  if (!this.enabled || this.initFailed) {
@@ -13484,12 +13804,13 @@ or you can use record.mirror to access the mirror instance during recording.`;
13484
13804
  this.stopRecording();
13485
13805
  return;
13486
13806
  }
13487
- const currentPath = window.location.pathname;
13488
- const isExcluded = matchesAnyPath(currentPath, this.excludedPaths);
13807
+ const isExcluded = matchesAnyPath(window.location.pathname, this.excludedPaths);
13489
13808
  const isRecording = this.stopFn !== null;
13809
+ if (isExcluded)
13810
+ this.debugLog(`not recording ${window.location.pathname}: excluded path`);
13490
13811
  if (isExcluded && isRecording) {
13491
13812
  this.stopRecording();
13492
- } else if (!isExcluded && !isRecording && !this.initFailed) {
13813
+ } else if (!isExcluded && !isRecording && !this.paused) {
13493
13814
  this.startRecording();
13494
13815
  }
13495
13816
  }
@@ -13499,8 +13820,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13499
13820
  this.enabled = true;
13500
13821
  if (typeof window === "undefined")
13501
13822
  return;
13502
- if (!this.originalPushState)
13503
- this.wrapHistory();
13823
+ this.attachGlobalListeners();
13504
13824
  this.startRecording();
13505
13825
  }
13506
13826
  stop() {
@@ -13509,26 +13829,23 @@ or you can use record.mirror to access the mirror instance during recording.`;
13509
13829
  }
13510
13830
  destroy() {
13511
13831
  this.stop();
13512
- if (this.originalPushState) {
13513
- window.history.pushState = this.originalPushState;
13514
- this.originalPushState = null;
13515
- }
13516
- if (this.originalReplaceState) {
13517
- window.history.replaceState = this.originalReplaceState;
13518
- this.originalReplaceState = null;
13519
- }
13520
- window.removeEventListener("popstate", this.handlePopState);
13521
- window.removeEventListener("beforeunload", this.handleUnload);
13522
- window.removeEventListener("pagehide", this.handleUnload);
13832
+ this.stopIdleTimer();
13833
+ this.detachGlobalListeners();
13523
13834
  }
13524
13835
  getSessionId() {
13525
13836
  return this.sessionId || null;
13526
13837
  }
13838
+ getDroppedEventCount() {
13839
+ return this.droppedEvents;
13840
+ }
13841
+ isPaused() {
13842
+ return this.paused;
13843
+ }
13527
13844
  }
13528
13845
 
13529
13846
  // ../analytics-core/dist/Analytics.js
13530
13847
  function createAnalytics(options = {}) {
13531
- const { basePath = DEFAULT_BASE_PATH, disabled = false, ignoreLocalhost = true, domain, autoTrackPageviews = true, autoTrackPageLeave = true, pageLeaveEventName = "page_leave", autoTrackSpeedAnalytics = true, autoTrackEngagement = true, heartbeatInterval = 30000, inactivityTimeout = 30000, engagementThreshold = 1e4, enableSessionRecording = false, sessionRecordingConfig = {} } = options;
13848
+ const { basePath = DEFAULT_BASE_PATH, disabled = false, ignoreLocalhost = true, domain, ingestKey, autoTrackPageviews = true, autoTrackPageLeave = true, pageLeaveEventName = "page_leave", autoTrackSpeedAnalytics = true, autoTrackEngagement = true, heartbeatInterval = 30000, inactivityTimeout = 30000, engagementThreshold = 1e4, enableSessionRecording = false, sessionRecordingConfig = {} } = options;
13532
13849
  const cleanups = [];
13533
13850
  const enabled = computeEnabled(disabled, ignoreLocalhost);
13534
13851
  const resolveDomain = () => domain || (typeof window !== "undefined" ? window.location.hostname : "");
@@ -13540,8 +13857,9 @@ or you can use record.mirror to access the mirror instance during recording.`;
13540
13857
  request_query: window.location.search,
13541
13858
  request_path: window.location.pathname,
13542
13859
  domain: resolveDomain(),
13860
+ language: navigator.language,
13543
13861
  event_data: data
13544
- }, "POST", basePath);
13862
+ }, "POST", basePath, ingestKey);
13545
13863
  };
13546
13864
  const trackPageview = () => {
13547
13865
  if (!enabled)
@@ -13551,14 +13869,16 @@ or you can use record.mirror to access the mirror instance during recording.`;
13551
13869
  request_query: window.location.search,
13552
13870
  request_path: window.location.pathname,
13553
13871
  domain: resolveDomain(),
13872
+ language: navigator.language,
13554
13873
  event_data: {
13555
13874
  referrer: document.referrer,
13556
13875
  userAgent: navigator.userAgent,
13557
13876
  timestamp: new Date().toISOString()
13558
13877
  }
13559
- }, "POST", basePath);
13878
+ }, "POST", basePath, ingestKey);
13879
+ };
13880
+ const identify = async () => {
13560
13881
  };
13561
- const identify = async () => {};
13562
13882
  if (enabled) {
13563
13883
  if (autoTrackPageviews) {
13564
13884
  cleanups.push(setupPageviewTracking(trackPageview));
@@ -13566,6 +13886,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13566
13886
  if (autoTrackEngagement) {
13567
13887
  const tracker = new EngagementTracker({
13568
13888
  basePath,
13889
+ ingestKey,
13569
13890
  domain: resolveDomain(),
13570
13891
  heartbeatInterval,
13571
13892
  inactivityTimeout,
@@ -13573,15 +13894,21 @@ or you can use record.mirror to access the mirror instance during recording.`;
13573
13894
  });
13574
13895
  cleanups.push(() => tracker.destroy());
13575
13896
  } else if (autoTrackPageLeave) {
13576
- cleanups.push(setupLegacyPageLeave(pageLeaveEventName, resolveDomain, basePath));
13897
+ cleanups.push(setupLegacyPageLeave(pageLeaveEventName, resolveDomain, basePath, ingestKey));
13577
13898
  }
13578
13899
  if (autoTrackSpeedAnalytics) {
13579
- const speed = new SpeedTracker({ basePath });
13900
+ const speed = new SpeedTracker({ basePath, ingestKey });
13580
13901
  cleanups.push(() => speed.destroy());
13581
13902
  }
13582
13903
  cleanups.push(setupClickDelegation(trackEvent));
13583
13904
  }
13584
- const recorder = enabled && enableSessionRecording ? new SessionRecorder({ basePath, domain: resolveDomain(), enabled: true, ...sessionRecordingConfig }) : null;
13905
+ const recorder = enabled && enableSessionRecording ? new SessionRecorder({
13906
+ basePath,
13907
+ ingestKey,
13908
+ domain: resolveDomain(),
13909
+ enabled: true,
13910
+ ...sessionRecordingConfig
13911
+ }) : null;
13585
13912
  if (recorder)
13586
13913
  cleanups.push(() => recorder.destroy());
13587
13914
  let runtimeRecorder = recorder;
@@ -13589,6 +13916,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13589
13916
  get enabled() {
13590
13917
  return enabled;
13591
13918
  },
13919
+ ingestKey,
13592
13920
  trackEvent,
13593
13921
  trackPageview,
13594
13922
  identify,
@@ -13601,6 +13929,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13601
13929
  }
13602
13930
  runtimeRecorder = new SessionRecorder({
13603
13931
  basePath,
13932
+ ingestKey,
13604
13933
  domain: resolveDomain(),
13605
13934
  enabled: true,
13606
13935
  ...sessionRecordingConfig
@@ -13635,7 +13964,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
13635
13964
  const legacy = window.localStorage?.temps_ignore;
13636
13965
  if (legacy === "true")
13637
13966
  return false;
13638
- } catch {}
13967
+ } catch {
13968
+ }
13639
13969
  return true;
13640
13970
  }
13641
13971
  function setupPageviewTracking(trackPageview) {
@@ -13695,7 +14025,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13695
14025
  document.addEventListener("click", onClick);
13696
14026
  return () => document.removeEventListener("click", onClick);
13697
14027
  }
13698
- function setupLegacyPageLeave(pageLeaveEventName, resolveDomain, basePath) {
14028
+ function setupLegacyPageLeave(pageLeaveEventName, resolveDomain, basePath, ingestKey) {
13699
14029
  let hasTracked = false;
13700
14030
  const startTime = Date.now();
13701
14031
  const trackPageLeave = () => {
@@ -13708,13 +14038,14 @@ or you can use record.mirror to access the mirror instance during recording.`;
13708
14038
  request_query: window.location.search,
13709
14039
  request_path: window.location.pathname,
13710
14040
  domain: resolveDomain(),
14041
+ language: navigator.language,
13711
14042
  event_data: {
13712
14043
  time_on_page_ms: timeOnPage,
13713
14044
  timestamp: new Date().toISOString(),
13714
14045
  url: window.location.href,
13715
14046
  referrer: document.referrer
13716
14047
  }
13717
- }, basePath);
14048
+ }, basePath, ingestKey);
13718
14049
  };
13719
14050
  window.addEventListener("pagehide", trackPageLeave);
13720
14051
  window.addEventListener("beforeunload", trackPageLeave);
@@ -13740,7 +14071,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
13740
14071
  function readDataset() {
13741
14072
  if (typeof document === "undefined")
13742
14073
  return {};
13743
- const script = document.currentScript ?? document.querySelector("script[data-temps]") ?? Array.from(document.scripts).reverse().find((s2) => !!s2.dataset?.domain || !!s2.dataset?.basePath) ?? null;
14074
+ const script = document.currentScript ?? document.querySelector("script[data-temps]") ?? Array.from(document.scripts).reverse().find((s2) => !!s2.dataset?.domain || !!s2.dataset?.basePath || !!s2.dataset?.ingestKey) ?? null;
13744
14075
  if (!script)
13745
14076
  return {};
13746
14077
  const ds = script.dataset;
@@ -13748,6 +14079,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
13748
14079
  const recording2 = {};
13749
14080
  if (ds.basePath)
13750
14081
  opts.basePath = ds.basePath;
14082
+ if (ds.ingestKey)
14083
+ opts.ingestKey = ds.ingestKey;
13751
14084
  if (ds.domain)
13752
14085
  opts.domain = ds.domain;
13753
14086
  if (ds.disabled)