@temps-sdk/analytics-browser 0.0.8 → 0.0.9-beta.1
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/auto.js +16 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/temps.js +1194 -8
- package/dist/temps.min.js +61 -37
- package/package.json +9 -4
package/dist/temps.js
CHANGED
|
@@ -27,6 +27,76 @@
|
|
|
27
27
|
var VISITOR_ID_KEY = "temps_visitor_id";
|
|
28
28
|
var SESSION_ID_KEY = "temps_session_id";
|
|
29
29
|
var SESSION_LAST_SEEN_KEY = "temps_session_last_seen";
|
|
30
|
+
var cookieless = false;
|
|
31
|
+
function enableCookielessIdentity() {
|
|
32
|
+
const switched = !cookieless;
|
|
33
|
+
cookieless = true;
|
|
34
|
+
clearStoredIdentity();
|
|
35
|
+
try {
|
|
36
|
+
if (typeof localStorage !== "undefined")
|
|
37
|
+
localStorage.removeItem("temps_identified");
|
|
38
|
+
} catch {}
|
|
39
|
+
if (!switched)
|
|
40
|
+
return;
|
|
41
|
+
for (const listener of Array.from(cookielessListeners)) {
|
|
42
|
+
try {
|
|
43
|
+
listener();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("[temps] cookieless switch listener failed:", error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function clearStoredIdentity() {
|
|
50
|
+
try {
|
|
51
|
+
if (typeof localStorage !== "undefined") {
|
|
52
|
+
localStorage.removeItem(VISITOR_ID_KEY);
|
|
53
|
+
localStorage.removeItem(SESSION_ID_KEY);
|
|
54
|
+
localStorage.removeItem(SESSION_LAST_SEEN_KEY);
|
|
55
|
+
}
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
function getStoredVisitorId() {
|
|
59
|
+
if (cookieless)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
if (typeof localStorage === "undefined")
|
|
63
|
+
return;
|
|
64
|
+
return localStorage.getItem(VISITOR_ID_KEY) ?? undefined;
|
|
65
|
+
} catch {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
var cookielessListeners = new Set;
|
|
70
|
+
function onCookielessIdentity(listener) {
|
|
71
|
+
cookielessListeners.add(listener);
|
|
72
|
+
return () => {
|
|
73
|
+
cookielessListeners.delete(listener);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var identityResetListeners = new Set;
|
|
77
|
+
var identityResetPending = false;
|
|
78
|
+
function isIdentityResetPending() {
|
|
79
|
+
return identityResetPending;
|
|
80
|
+
}
|
|
81
|
+
function onIdentityReset(listener) {
|
|
82
|
+
identityResetListeners.add(listener);
|
|
83
|
+
return () => {
|
|
84
|
+
identityResetListeners.delete(listener);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function notifyIdentityReset(phase) {
|
|
88
|
+
identityResetPending = phase === "started";
|
|
89
|
+
for (const listener of Array.from(identityResetListeners)) {
|
|
90
|
+
try {
|
|
91
|
+
listener(phase);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("[temps] identity reset listener failed:", error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isCookielessIdentity() {
|
|
98
|
+
return cookieless;
|
|
99
|
+
}
|
|
30
100
|
var SESSION_MAX_AGE_MS = 30 * 60 * 1000;
|
|
31
101
|
function randomId(prefix) {
|
|
32
102
|
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
@@ -35,6 +105,8 @@
|
|
|
35
105
|
return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
36
106
|
}
|
|
37
107
|
function getOrCreateVisitorId() {
|
|
108
|
+
if (cookieless)
|
|
109
|
+
return;
|
|
38
110
|
try {
|
|
39
111
|
if (typeof localStorage === "undefined")
|
|
40
112
|
return;
|
|
@@ -49,6 +121,8 @@
|
|
|
49
121
|
}
|
|
50
122
|
}
|
|
51
123
|
function getOrCreateSessionId() {
|
|
124
|
+
if (cookieless)
|
|
125
|
+
return;
|
|
52
126
|
try {
|
|
53
127
|
if (typeof localStorage === "undefined")
|
|
54
128
|
return;
|
|
@@ -662,6 +736,7 @@
|
|
|
662
736
|
constructor(options) {
|
|
663
737
|
this.pathname = "";
|
|
664
738
|
this.query = "";
|
|
739
|
+
this.referrer = "";
|
|
665
740
|
this.loadMetrics = {};
|
|
666
741
|
this.loadSent = false;
|
|
667
742
|
this.sentLoadMetrics = new Set;
|
|
@@ -679,6 +754,7 @@
|
|
|
679
754
|
return;
|
|
680
755
|
this.pathname = window.location.pathname;
|
|
681
756
|
this.query = window.location.search;
|
|
757
|
+
this.referrer = typeof document !== "undefined" ? document.referrer : "";
|
|
682
758
|
this.start();
|
|
683
759
|
}
|
|
684
760
|
start() {
|
|
@@ -743,7 +819,8 @@
|
|
|
743
819
|
const payload = {
|
|
744
820
|
...metrics,
|
|
745
821
|
pathname: this.pathname,
|
|
746
|
-
query: this.query
|
|
822
|
+
query: this.query,
|
|
823
|
+
referrer: this.referrer
|
|
747
824
|
};
|
|
748
825
|
if (typeof document !== "undefined" && document.visibilityState === "hidden") {
|
|
749
826
|
sendAnalyticsReliable("speed", payload, this.basePath, this.ingestKey);
|
|
@@ -13332,6 +13409,7 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13332
13409
|
this.paused = false;
|
|
13333
13410
|
this.lastActivityAt = Date.now();
|
|
13334
13411
|
this.droppedEvents = 0;
|
|
13412
|
+
this.resumeAfterResetPending = false;
|
|
13335
13413
|
this.sampleDecision = null;
|
|
13336
13414
|
this.originalPushState = null;
|
|
13337
13415
|
this.originalReplaceState = null;
|
|
@@ -13685,6 +13763,9 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13685
13763
|
clearSession() {
|
|
13686
13764
|
this.sessionInitialized = false;
|
|
13687
13765
|
this.sessionId = "";
|
|
13766
|
+
this.pending = [];
|
|
13767
|
+
this.inflight = null;
|
|
13768
|
+
this.sendRetryCount = 0;
|
|
13688
13769
|
rememberRecordingSessionId(null);
|
|
13689
13770
|
}
|
|
13690
13771
|
detachRecorder() {
|
|
@@ -13794,6 +13875,11 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13794
13875
|
start() {
|
|
13795
13876
|
if (this.enabled && this.stopFn)
|
|
13796
13877
|
return;
|
|
13878
|
+
if (isIdentityResetPending()) {
|
|
13879
|
+
this.enabled = false;
|
|
13880
|
+
this.resumeAfterResetPending = true;
|
|
13881
|
+
return;
|
|
13882
|
+
}
|
|
13797
13883
|
this.enabled = true;
|
|
13798
13884
|
if (typeof window === "undefined")
|
|
13799
13885
|
return;
|
|
@@ -13801,6 +13887,10 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13801
13887
|
this.startRecording();
|
|
13802
13888
|
}
|
|
13803
13889
|
stop() {
|
|
13890
|
+
this.resumeAfterResetPending = false;
|
|
13891
|
+
this.halt();
|
|
13892
|
+
}
|
|
13893
|
+
halt() {
|
|
13804
13894
|
this.enabled = false;
|
|
13805
13895
|
this.stopRecording();
|
|
13806
13896
|
}
|
|
@@ -13809,6 +13899,22 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13809
13899
|
this.stopIdleTimer();
|
|
13810
13900
|
this.detachGlobalListeners();
|
|
13811
13901
|
}
|
|
13902
|
+
discard() {
|
|
13903
|
+
this.pending = [];
|
|
13904
|
+
this.inflight = null;
|
|
13905
|
+
this.destroy();
|
|
13906
|
+
}
|
|
13907
|
+
endForReset() {
|
|
13908
|
+
if (this.enabled)
|
|
13909
|
+
this.resumeAfterResetPending = true;
|
|
13910
|
+
this.halt();
|
|
13911
|
+
}
|
|
13912
|
+
resumeAfterReset() {
|
|
13913
|
+
if (!this.resumeAfterResetPending)
|
|
13914
|
+
return;
|
|
13915
|
+
this.resumeAfterResetPending = false;
|
|
13916
|
+
this.start();
|
|
13917
|
+
}
|
|
13812
13918
|
getSessionId() {
|
|
13813
13919
|
return this.sessionId || null;
|
|
13814
13920
|
}
|
|
@@ -13820,13 +13926,970 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13820
13926
|
}
|
|
13821
13927
|
}
|
|
13822
13928
|
|
|
13929
|
+
// ../analytics-core/dist/AutoTracking.js
|
|
13930
|
+
var OUTBOUND_CLICK_EVENT = "outbound_click";
|
|
13931
|
+
var FILE_DOWNLOAD_EVENT = "file_download";
|
|
13932
|
+
var NOT_FOUND_EVENT = "not_found";
|
|
13933
|
+
var NOT_FOUND_MARKER_ATTRIBUTE = "data-temps-404";
|
|
13934
|
+
var DEFAULT_FILE_DOWNLOAD_EXTENSIONS = [
|
|
13935
|
+
"pdf",
|
|
13936
|
+
"doc",
|
|
13937
|
+
"docx",
|
|
13938
|
+
"odt",
|
|
13939
|
+
"rtf",
|
|
13940
|
+
"txt",
|
|
13941
|
+
"md",
|
|
13942
|
+
"epub",
|
|
13943
|
+
"xls",
|
|
13944
|
+
"xlsx",
|
|
13945
|
+
"ods",
|
|
13946
|
+
"csv",
|
|
13947
|
+
"ppt",
|
|
13948
|
+
"pptx",
|
|
13949
|
+
"pps",
|
|
13950
|
+
"odp",
|
|
13951
|
+
"key",
|
|
13952
|
+
"zip",
|
|
13953
|
+
"7z",
|
|
13954
|
+
"rar",
|
|
13955
|
+
"tar",
|
|
13956
|
+
"gz",
|
|
13957
|
+
"tgz",
|
|
13958
|
+
"bz2",
|
|
13959
|
+
"xz",
|
|
13960
|
+
"mp3",
|
|
13961
|
+
"wav",
|
|
13962
|
+
"wma",
|
|
13963
|
+
"flac",
|
|
13964
|
+
"midi",
|
|
13965
|
+
"mp4",
|
|
13966
|
+
"mov",
|
|
13967
|
+
"avi",
|
|
13968
|
+
"wmv",
|
|
13969
|
+
"mpeg",
|
|
13970
|
+
"webm",
|
|
13971
|
+
"mkv",
|
|
13972
|
+
"dmg",
|
|
13973
|
+
"iso",
|
|
13974
|
+
"exe",
|
|
13975
|
+
"msi",
|
|
13976
|
+
"pkg",
|
|
13977
|
+
"deb",
|
|
13978
|
+
"rpm",
|
|
13979
|
+
"apk",
|
|
13980
|
+
"appimage"
|
|
13981
|
+
];
|
|
13982
|
+
var NOT_FOUND_RECHECK_DELAY_MS = 1000;
|
|
13983
|
+
function recordedUrl(url) {
|
|
13984
|
+
return `${url.origin}${url.pathname}`;
|
|
13985
|
+
}
|
|
13986
|
+
function pathExtension(pathname) {
|
|
13987
|
+
const segment = pathname.slice(pathname.lastIndexOf("/") + 1);
|
|
13988
|
+
const dot = segment.lastIndexOf(".");
|
|
13989
|
+
if (dot <= 0 || dot === segment.length - 1)
|
|
13990
|
+
return null;
|
|
13991
|
+
return segment.slice(dot + 1).toLowerCase();
|
|
13992
|
+
}
|
|
13993
|
+
function classifyLink(link, currentHost, options) {
|
|
13994
|
+
let url;
|
|
13995
|
+
try {
|
|
13996
|
+
url = new URL(link.href);
|
|
13997
|
+
} catch {
|
|
13998
|
+
return null;
|
|
13999
|
+
}
|
|
14000
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
14001
|
+
return null;
|
|
14002
|
+
if (options.trackFileDownloads) {
|
|
14003
|
+
const extension = pathExtension(url.pathname);
|
|
14004
|
+
const listed = extension !== null && options.fileDownloadExtensions.some((candidate) => candidate.toLowerCase() === extension);
|
|
14005
|
+
if (listed || link.hasAttribute("download")) {
|
|
14006
|
+
return {
|
|
14007
|
+
eventName: FILE_DOWNLOAD_EVENT,
|
|
14008
|
+
data: { url: recordedUrl(url), extension: extension ?? "", host: url.host }
|
|
14009
|
+
};
|
|
14010
|
+
}
|
|
14011
|
+
}
|
|
14012
|
+
if (options.trackOutboundLinks && url.host !== currentHost) {
|
|
14013
|
+
return {
|
|
14014
|
+
eventName: OUTBOUND_CLICK_EVENT,
|
|
14015
|
+
data: { url: recordedUrl(url), host: url.host }
|
|
14016
|
+
};
|
|
14017
|
+
}
|
|
14018
|
+
return null;
|
|
14019
|
+
}
|
|
14020
|
+
function setupLinkTracking(options, send) {
|
|
14021
|
+
const classify = {
|
|
14022
|
+
trackOutboundLinks: options.autoTrackOutboundLinks ?? true,
|
|
14023
|
+
trackFileDownloads: options.autoTrackFileDownloads ?? true,
|
|
14024
|
+
fileDownloadExtensions: options.fileDownloadExtensions ?? DEFAULT_FILE_DOWNLOAD_EXTENSIONS
|
|
14025
|
+
};
|
|
14026
|
+
if (!classify.trackOutboundLinks && !classify.trackFileDownloads) {
|
|
14027
|
+
return () => {};
|
|
14028
|
+
}
|
|
14029
|
+
const onClick = (event) => {
|
|
14030
|
+
if (event.type === "auxclick" ? event.button !== 1 : event.button !== 0)
|
|
14031
|
+
return;
|
|
14032
|
+
const target = event.target;
|
|
14033
|
+
const link = target?.closest?.("a[href]");
|
|
14034
|
+
if (!link || !("href" in link))
|
|
14035
|
+
return;
|
|
14036
|
+
const result = classifyLink(link, window.location.host, classify);
|
|
14037
|
+
if (result)
|
|
14038
|
+
send(result.eventName, result.data);
|
|
14039
|
+
};
|
|
14040
|
+
document.addEventListener("click", onClick);
|
|
14041
|
+
document.addEventListener("auxclick", onClick);
|
|
14042
|
+
return () => {
|
|
14043
|
+
document.removeEventListener("click", onClick);
|
|
14044
|
+
document.removeEventListener("auxclick", onClick);
|
|
14045
|
+
};
|
|
14046
|
+
}
|
|
14047
|
+
function notFoundEventData(extra = {}) {
|
|
14048
|
+
if (typeof window === "undefined" || typeof document === "undefined")
|
|
14049
|
+
return { ...extra };
|
|
14050
|
+
return {
|
|
14051
|
+
path: window.location.pathname,
|
|
14052
|
+
referrer: document.referrer,
|
|
14053
|
+
...extra
|
|
14054
|
+
};
|
|
14055
|
+
}
|
|
14056
|
+
class NotFoundMarkerWatcher {
|
|
14057
|
+
constructor(report) {
|
|
14058
|
+
this.report = report;
|
|
14059
|
+
this.timer = null;
|
|
14060
|
+
this.reported = false;
|
|
14061
|
+
this.previousMarkers = new Set;
|
|
14062
|
+
this.observedMarkers = new Set;
|
|
14063
|
+
this.path = "";
|
|
14064
|
+
}
|
|
14065
|
+
afterPageview() {
|
|
14066
|
+
this.cancel();
|
|
14067
|
+
this.reported = false;
|
|
14068
|
+
this.path = window.location.pathname;
|
|
14069
|
+
this.previousMarkers = this.observedMarkers;
|
|
14070
|
+
this.observedMarkers = new Set;
|
|
14071
|
+
if (this.check())
|
|
14072
|
+
return;
|
|
14073
|
+
this.timer = setTimeout(() => {
|
|
14074
|
+
this.timer = null;
|
|
14075
|
+
this.check();
|
|
14076
|
+
}, NOT_FOUND_RECHECK_DELAY_MS);
|
|
14077
|
+
}
|
|
14078
|
+
cancel() {
|
|
14079
|
+
if (this.timer !== null) {
|
|
14080
|
+
clearTimeout(this.timer);
|
|
14081
|
+
this.timer = null;
|
|
14082
|
+
}
|
|
14083
|
+
}
|
|
14084
|
+
check() {
|
|
14085
|
+
if (this.reported)
|
|
14086
|
+
return false;
|
|
14087
|
+
if (window.location.pathname !== this.path)
|
|
14088
|
+
return false;
|
|
14089
|
+
const markers = markerElements();
|
|
14090
|
+
for (const element of markers)
|
|
14091
|
+
this.observedMarkers.add(element);
|
|
14092
|
+
const fresh = markers.some((element) => !this.previousMarkers.has(element));
|
|
14093
|
+
if (!fresh)
|
|
14094
|
+
return false;
|
|
14095
|
+
this.reported = true;
|
|
14096
|
+
this.report();
|
|
14097
|
+
return true;
|
|
14098
|
+
}
|
|
14099
|
+
}
|
|
14100
|
+
function markerElements() {
|
|
14101
|
+
return Array.from(document.querySelectorAll(`[${NOT_FOUND_MARKER_ATTRIBUTE}]`));
|
|
14102
|
+
}
|
|
14103
|
+
|
|
14104
|
+
// ../analytics-core/dist/Identify.js
|
|
14105
|
+
var IDENTIFIED_KEY = "temps_identified";
|
|
14106
|
+
var IDENTIFY_ENDPOINT = "identify";
|
|
14107
|
+
var RESET_ENDPOINT = "reset";
|
|
14108
|
+
var APPLIED_OUTCOMES = new Set(["updated", "unchanged"]);
|
|
14109
|
+
var identityGeneration = 0;
|
|
14110
|
+
|
|
14111
|
+
class ResetFailedError extends Error {
|
|
14112
|
+
constructor(message, cause) {
|
|
14113
|
+
super(message);
|
|
14114
|
+
this.cause = cause;
|
|
14115
|
+
this.name = "ResetFailedError";
|
|
14116
|
+
}
|
|
14117
|
+
}
|
|
14118
|
+
function memoFor(userId, traits) {
|
|
14119
|
+
return JSON.stringify([userId, traits ?? null]);
|
|
14120
|
+
}
|
|
14121
|
+
function readMemo() {
|
|
14122
|
+
try {
|
|
14123
|
+
return typeof localStorage === "undefined" ? null : localStorage.getItem(IDENTIFIED_KEY);
|
|
14124
|
+
} catch {
|
|
14125
|
+
return null;
|
|
14126
|
+
}
|
|
14127
|
+
}
|
|
14128
|
+
function writeMemo(value) {
|
|
14129
|
+
try {
|
|
14130
|
+
if (typeof localStorage === "undefined")
|
|
14131
|
+
return;
|
|
14132
|
+
if (value === null)
|
|
14133
|
+
localStorage.removeItem(IDENTIFIED_KEY);
|
|
14134
|
+
else
|
|
14135
|
+
localStorage.setItem(IDENTIFIED_KEY, value);
|
|
14136
|
+
} catch {}
|
|
14137
|
+
}
|
|
14138
|
+
async function identifyVisitor(options) {
|
|
14139
|
+
const { basePath, ingestKey, userId, traits, ready } = options;
|
|
14140
|
+
if (isCookielessIdentity()) {
|
|
14141
|
+
return {
|
|
14142
|
+
applied: false,
|
|
14143
|
+
outcome: "cookieless_project",
|
|
14144
|
+
message: "Identify stores nothing in cookieless mode."
|
|
14145
|
+
};
|
|
14146
|
+
}
|
|
14147
|
+
if (typeof userId !== "string" || userId.trim() === "") {
|
|
14148
|
+
return { applied: false, outcome: "invalid_user_id", message: "identify() needs a non-empty user id." };
|
|
14149
|
+
}
|
|
14150
|
+
const memo = memoFor(userId, traits);
|
|
14151
|
+
if (readMemo() === memo) {
|
|
14152
|
+
return { applied: true, outcome: "already_sent", message: "This visitor already has this identity." };
|
|
14153
|
+
}
|
|
14154
|
+
const generation = identityGeneration;
|
|
14155
|
+
try {
|
|
14156
|
+
await ready;
|
|
14157
|
+
} catch {}
|
|
14158
|
+
if (generation !== identityGeneration) {
|
|
14159
|
+
return {
|
|
14160
|
+
applied: false,
|
|
14161
|
+
outcome: "reset",
|
|
14162
|
+
message: "reset() ran while identify was waiting; nothing was sent."
|
|
14163
|
+
};
|
|
14164
|
+
}
|
|
14165
|
+
if (isCookielessIdentity()) {
|
|
14166
|
+
return {
|
|
14167
|
+
applied: false,
|
|
14168
|
+
outcome: "cookieless_project",
|
|
14169
|
+
message: "Identify stores nothing in cookieless mode."
|
|
14170
|
+
};
|
|
14171
|
+
}
|
|
14172
|
+
try {
|
|
14173
|
+
const response = await fetch(`${basePath}/${IDENTIFY_ENDPOINT}`, {
|
|
14174
|
+
method: "POST",
|
|
14175
|
+
headers: { "Content-Type": "application/json", ...ingestKeyHeaders(ingestKey) },
|
|
14176
|
+
body: JSON.stringify({ user_id: userId, traits, visitor_id: getOrCreateVisitorId() })
|
|
14177
|
+
});
|
|
14178
|
+
const body = await response.json().catch(() => null);
|
|
14179
|
+
const result = {
|
|
14180
|
+
applied: Boolean(body?.applied),
|
|
14181
|
+
outcome: typeof body?.outcome === "string" ? body.outcome : `http_${response.status}`,
|
|
14182
|
+
message: typeof body?.message === "string" ? body.message : response.statusText
|
|
14183
|
+
};
|
|
14184
|
+
const stillCurrent = generation === identityGeneration && !isCookielessIdentity();
|
|
14185
|
+
if (response.ok && APPLIED_OUTCOMES.has(result.outcome) && stillCurrent)
|
|
14186
|
+
writeMemo(memo);
|
|
14187
|
+
return result;
|
|
14188
|
+
} catch (error) {
|
|
14189
|
+
console.error("Failed to send identify:", error);
|
|
14190
|
+
return { applied: false, outcome: "network_error", message: String(error) };
|
|
14191
|
+
}
|
|
14192
|
+
}
|
|
14193
|
+
async function resetVisitor(options) {
|
|
14194
|
+
identityGeneration += 1;
|
|
14195
|
+
writeMemo(null);
|
|
14196
|
+
clearStoredIdentity();
|
|
14197
|
+
notifyIdentityReset("started");
|
|
14198
|
+
if (isCookielessIdentity()) {
|
|
14199
|
+
notifyIdentityReset("confirmed");
|
|
14200
|
+
return;
|
|
14201
|
+
}
|
|
14202
|
+
let response;
|
|
14203
|
+
try {
|
|
14204
|
+
response = await fetch(`${options.basePath}/${RESET_ENDPOINT}`, {
|
|
14205
|
+
method: "POST",
|
|
14206
|
+
headers: ingestKeyHeaders(options.ingestKey)
|
|
14207
|
+
});
|
|
14208
|
+
} catch (error) {
|
|
14209
|
+
throw new ResetFailedError(`Could not reach ${options.basePath}/${RESET_ENDPOINT} to reset the visitor`, error);
|
|
14210
|
+
}
|
|
14211
|
+
if (!response.ok) {
|
|
14212
|
+
throw new ResetFailedError(`${options.basePath}/${RESET_ENDPOINT} answered ${response.status}; the visitor was not reset on the server`);
|
|
14213
|
+
}
|
|
14214
|
+
notifyIdentityReset("confirmed");
|
|
14215
|
+
}
|
|
14216
|
+
|
|
14217
|
+
// ../analytics-core/dist/request.js
|
|
14218
|
+
var REQUEST_TIMEOUT_MS = 1e4;
|
|
14219
|
+
async function postJson(fetchImpl, url, body, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
14220
|
+
const controller = typeof AbortController === "function" ? new AbortController : undefined;
|
|
14221
|
+
let timer;
|
|
14222
|
+
const deadline = new Promise((_, reject) => {
|
|
14223
|
+
timer = setTimeout(() => {
|
|
14224
|
+
controller?.abort();
|
|
14225
|
+
reject(new Error(`${url} did not answer within ${Math.round(timeoutMs / 1000)}s`));
|
|
14226
|
+
}, timeoutMs);
|
|
14227
|
+
});
|
|
14228
|
+
const exchange = (async () => {
|
|
14229
|
+
const response = await fetchImpl(url, {
|
|
14230
|
+
method: "POST",
|
|
14231
|
+
headers: { "Content-Type": "application/json" },
|
|
14232
|
+
credentials: "same-origin",
|
|
14233
|
+
body,
|
|
14234
|
+
signal: controller?.signal
|
|
14235
|
+
});
|
|
14236
|
+
if (!response.ok)
|
|
14237
|
+
throw new Error(`${url} returned ${response.status}`);
|
|
14238
|
+
return await response.json();
|
|
14239
|
+
})();
|
|
14240
|
+
try {
|
|
14241
|
+
return await Promise.race([exchange, deadline]);
|
|
14242
|
+
} finally {
|
|
14243
|
+
clearTimeout(timer);
|
|
14244
|
+
exchange.catch(() => {
|
|
14245
|
+
return;
|
|
14246
|
+
});
|
|
14247
|
+
}
|
|
14248
|
+
}
|
|
14249
|
+
|
|
14250
|
+
// ../analytics-core/dist/FeatureFlags.js
|
|
14251
|
+
class FeatureFlags {
|
|
14252
|
+
constructor(options = {}) {
|
|
14253
|
+
this.results = new Map;
|
|
14254
|
+
this.inflight = null;
|
|
14255
|
+
this.exposed = new Set;
|
|
14256
|
+
this.listeners = new Set;
|
|
14257
|
+
this.currentStatus = "idle";
|
|
14258
|
+
this.revision = 0;
|
|
14259
|
+
this.generation = 0;
|
|
14260
|
+
this.basePath = options.basePath ?? "/api/_temps";
|
|
14261
|
+
this.context = { key: options.key, attributes: options.attributes };
|
|
14262
|
+
this.bootstrap = new Map(Object.entries(options.bootstrap ?? {}));
|
|
14263
|
+
this.onExposure = options.onExposure;
|
|
14264
|
+
this.onError = options.onError ?? ((error) => {
|
|
14265
|
+
console.warn("[temps-flags] serving fallbacks:", error.message);
|
|
14266
|
+
});
|
|
14267
|
+
this.fetchImpl = options.fetch;
|
|
14268
|
+
this.timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
14269
|
+
this.disabled = options.disabled ?? false;
|
|
14270
|
+
}
|
|
14271
|
+
get status() {
|
|
14272
|
+
return this.currentStatus;
|
|
14273
|
+
}
|
|
14274
|
+
get version() {
|
|
14275
|
+
return this.revision;
|
|
14276
|
+
}
|
|
14277
|
+
get(key, fallback) {
|
|
14278
|
+
this.ensureLoaded();
|
|
14279
|
+
const evaluation = this.results.get(key);
|
|
14280
|
+
if (evaluation && compatible(evaluation.value, fallback))
|
|
14281
|
+
this.recordExposure(evaluation);
|
|
14282
|
+
return this.peek(key, fallback);
|
|
14283
|
+
}
|
|
14284
|
+
peek(key, fallback) {
|
|
14285
|
+
const evaluation = this.results.get(key);
|
|
14286
|
+
if (!evaluation) {
|
|
14287
|
+
return this.bootstrap.has(key) ? sameType(this.bootstrap.get(key), fallback) : fallback;
|
|
14288
|
+
}
|
|
14289
|
+
return sameType(evaluation.value, fallback);
|
|
14290
|
+
}
|
|
14291
|
+
peekVariant(key) {
|
|
14292
|
+
return this.results.get(key)?.variant ?? null;
|
|
14293
|
+
}
|
|
14294
|
+
getVariant(key) {
|
|
14295
|
+
this.ensureLoaded();
|
|
14296
|
+
const evaluation = this.results.get(key);
|
|
14297
|
+
if (!evaluation)
|
|
14298
|
+
return null;
|
|
14299
|
+
this.recordExposure(evaluation);
|
|
14300
|
+
return evaluation.variant;
|
|
14301
|
+
}
|
|
14302
|
+
setContext(context) {
|
|
14303
|
+
this.replaceContext({ key: context.key, attributes: context.attributes });
|
|
14304
|
+
if (this.currentStatus !== "idle")
|
|
14305
|
+
this.load();
|
|
14306
|
+
}
|
|
14307
|
+
setDisabled(disabled) {
|
|
14308
|
+
if (disabled === this.disabled)
|
|
14309
|
+
return;
|
|
14310
|
+
this.disabled = disabled;
|
|
14311
|
+
if (disabled) {
|
|
14312
|
+
this.results = new Map;
|
|
14313
|
+
this.generation += 1;
|
|
14314
|
+
this.inflight = null;
|
|
14315
|
+
if (this.currentStatus === "loading")
|
|
14316
|
+
this.currentStatus = "idle";
|
|
14317
|
+
} else if (this.currentStatus !== "idle") {
|
|
14318
|
+
this.load();
|
|
14319
|
+
return;
|
|
14320
|
+
}
|
|
14321
|
+
this.notify();
|
|
14322
|
+
}
|
|
14323
|
+
getEvaluation(key) {
|
|
14324
|
+
this.ensureLoaded();
|
|
14325
|
+
return this.results.get(key);
|
|
14326
|
+
}
|
|
14327
|
+
all() {
|
|
14328
|
+
this.ensureLoaded();
|
|
14329
|
+
return [...this.results.values()];
|
|
14330
|
+
}
|
|
14331
|
+
ready() {
|
|
14332
|
+
this.ensureLoaded();
|
|
14333
|
+
return this.inflight ?? Promise.resolve();
|
|
14334
|
+
}
|
|
14335
|
+
reload(context = {}) {
|
|
14336
|
+
this.replaceContext({
|
|
14337
|
+
key: context.key ?? this.context.key,
|
|
14338
|
+
attributes: { ...this.context.attributes, ...context.attributes }
|
|
14339
|
+
});
|
|
14340
|
+
return this.load();
|
|
14341
|
+
}
|
|
14342
|
+
subscribe(listener) {
|
|
14343
|
+
this.listeners.add(listener);
|
|
14344
|
+
return () => {
|
|
14345
|
+
this.listeners.delete(listener);
|
|
14346
|
+
};
|
|
14347
|
+
}
|
|
14348
|
+
replaceContext(next) {
|
|
14349
|
+
const changed = contextKey(next) !== contextKey(this.context);
|
|
14350
|
+
this.context = next;
|
|
14351
|
+
if (!changed)
|
|
14352
|
+
return;
|
|
14353
|
+
this.results = new Map;
|
|
14354
|
+
this.bootstrap.clear();
|
|
14355
|
+
this.exposed.clear();
|
|
14356
|
+
this.notify();
|
|
14357
|
+
}
|
|
14358
|
+
ensureLoaded() {
|
|
14359
|
+
if (this.currentStatus === "idle")
|
|
14360
|
+
this.load();
|
|
14361
|
+
}
|
|
14362
|
+
load() {
|
|
14363
|
+
if (this.disabled)
|
|
14364
|
+
return Promise.resolve();
|
|
14365
|
+
const fetchImpl = this.fetchImpl ?? (typeof fetch === "function" ? fetch : undefined);
|
|
14366
|
+
if (!fetchImpl) {
|
|
14367
|
+
this.currentStatus = "error";
|
|
14368
|
+
return Promise.resolve();
|
|
14369
|
+
}
|
|
14370
|
+
const generation = ++this.generation;
|
|
14371
|
+
this.currentStatus = "loading";
|
|
14372
|
+
Promise.resolve().then(() => {
|
|
14373
|
+
if (generation === this.generation && this.currentStatus === "loading")
|
|
14374
|
+
this.notify();
|
|
14375
|
+
});
|
|
14376
|
+
const body = JSON.stringify({ key: this.context.key, attributes: this.context.attributes ?? {} });
|
|
14377
|
+
const request = (async () => {
|
|
14378
|
+
try {
|
|
14379
|
+
const parsed = await postJson(fetchImpl, `${this.basePath}/flags`, body, this.timeoutMs);
|
|
14380
|
+
if (generation !== this.generation)
|
|
14381
|
+
return;
|
|
14382
|
+
this.results = new Map((parsed.flags ?? []).map((flag) => [flag.key, flag]));
|
|
14383
|
+
this.bootstrap.clear();
|
|
14384
|
+
this.currentStatus = "ready";
|
|
14385
|
+
} catch (error) {
|
|
14386
|
+
if (generation !== this.generation)
|
|
14387
|
+
return;
|
|
14388
|
+
this.currentStatus = "error";
|
|
14389
|
+
this.onError(error instanceof Error ? error : new Error(String(error)));
|
|
14390
|
+
}
|
|
14391
|
+
this.notify();
|
|
14392
|
+
})();
|
|
14393
|
+
this.inflight = request;
|
|
14394
|
+
return request;
|
|
14395
|
+
}
|
|
14396
|
+
notify() {
|
|
14397
|
+
this.revision += 1;
|
|
14398
|
+
for (const listener of [...this.listeners]) {
|
|
14399
|
+
try {
|
|
14400
|
+
listener();
|
|
14401
|
+
} catch {}
|
|
14402
|
+
}
|
|
14403
|
+
}
|
|
14404
|
+
recordExposure(evaluation) {
|
|
14405
|
+
if (!evaluation.record_exposure || !this.onExposure)
|
|
14406
|
+
return;
|
|
14407
|
+
const variant = evaluation.variant ?? "";
|
|
14408
|
+
const marker = `${evaluation.key}\x00${variant}`;
|
|
14409
|
+
if (this.exposed.has(marker))
|
|
14410
|
+
return;
|
|
14411
|
+
this.exposed.add(marker);
|
|
14412
|
+
try {
|
|
14413
|
+
this.onExposure({ flag_key: evaluation.key, variant, reason: evaluation.reason.kind });
|
|
14414
|
+
} catch {}
|
|
14415
|
+
}
|
|
14416
|
+
}
|
|
14417
|
+
function sameType(value, fallback) {
|
|
14418
|
+
return compatible(value, fallback) ? value : fallback;
|
|
14419
|
+
}
|
|
14420
|
+
function compatible(value, fallback) {
|
|
14421
|
+
if (fallback === null || fallback === undefined)
|
|
14422
|
+
return true;
|
|
14423
|
+
if (value === null || value === undefined)
|
|
14424
|
+
return false;
|
|
14425
|
+
if (typeof value !== typeof fallback)
|
|
14426
|
+
return false;
|
|
14427
|
+
return Array.isArray(fallback) === Array.isArray(value);
|
|
14428
|
+
}
|
|
14429
|
+
function exposureEventData(exposure) {
|
|
14430
|
+
return { flag_key: exposure.flag_key, variant: exposure.variant, reason: exposure.reason };
|
|
14431
|
+
}
|
|
14432
|
+
function contextKey(context) {
|
|
14433
|
+
const attributes = Object.entries(context.attributes ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
14434
|
+
return JSON.stringify([context.key ?? null, attributes]);
|
|
14435
|
+
}
|
|
14436
|
+
|
|
14437
|
+
// ../analytics-core/dist/Surveys.js
|
|
14438
|
+
var MAX_OPEN_TEXT_LENGTH = 2000;
|
|
14439
|
+
var SEEN_STORAGE_KEY = "temps_surveys_seen";
|
|
14440
|
+
var MAX_SEEN = 200;
|
|
14441
|
+
var MAX_SURVEY_EVENT_BYTES = 48 * 1024;
|
|
14442
|
+
var FIRST_RETRY_DELAY_MS = 15000;
|
|
14443
|
+
var MAX_RETRY_DELAY_MS = 5 * 60000;
|
|
14444
|
+
|
|
14445
|
+
class Surveys {
|
|
14446
|
+
constructor(options) {
|
|
14447
|
+
this.generation = 0;
|
|
14448
|
+
this.failures = 0;
|
|
14449
|
+
this.retryAt = 0;
|
|
14450
|
+
this.surveys = [];
|
|
14451
|
+
this.inflight = null;
|
|
14452
|
+
this.currentStatus = "idle";
|
|
14453
|
+
this.listeners = new Set;
|
|
14454
|
+
this.revision = 0;
|
|
14455
|
+
this.shownHere = new Set;
|
|
14456
|
+
this.basePath = options.basePath ?? "/api/_temps";
|
|
14457
|
+
this.onEvent = options.onEvent;
|
|
14458
|
+
this.onError = options.onError ?? ((error) => {
|
|
14459
|
+
console.warn("[temps-surveys] no surveys shown:", error.message);
|
|
14460
|
+
});
|
|
14461
|
+
this.fetchImpl = options.fetch;
|
|
14462
|
+
this.storage = options.storage === undefined ? defaultStorage() : options.storage;
|
|
14463
|
+
this.disabled = options.disabled ?? false;
|
|
14464
|
+
this.now = options.now ?? Date.now;
|
|
14465
|
+
this.timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
14466
|
+
this.context = { key: options.key, attributes: options.attributes };
|
|
14467
|
+
}
|
|
14468
|
+
get status() {
|
|
14469
|
+
return this.currentStatus;
|
|
14470
|
+
}
|
|
14471
|
+
get version() {
|
|
14472
|
+
return this.revision;
|
|
14473
|
+
}
|
|
14474
|
+
all() {
|
|
14475
|
+
return [...this.surveys];
|
|
14476
|
+
}
|
|
14477
|
+
load() {
|
|
14478
|
+
if (this.inflight)
|
|
14479
|
+
return this.inflight;
|
|
14480
|
+
if (this.disabled)
|
|
14481
|
+
return Promise.resolve();
|
|
14482
|
+
if (this.currentStatus === "error" && this.now() < this.retryAt)
|
|
14483
|
+
return Promise.resolve();
|
|
14484
|
+
const fetchImpl = this.fetchImpl ?? (typeof fetch === "function" ? fetch : undefined);
|
|
14485
|
+
if (!fetchImpl) {
|
|
14486
|
+
this.currentStatus = "error";
|
|
14487
|
+
this.retryAt = Number.POSITIVE_INFINITY;
|
|
14488
|
+
return Promise.resolve();
|
|
14489
|
+
}
|
|
14490
|
+
const generation = this.generation;
|
|
14491
|
+
const context = this.context;
|
|
14492
|
+
this.currentStatus = "loading";
|
|
14493
|
+
const request = (async () => {
|
|
14494
|
+
let surveys = null;
|
|
14495
|
+
let failure = null;
|
|
14496
|
+
try {
|
|
14497
|
+
const parsed = await postJson(fetchImpl, `${this.basePath}/surveys`, JSON.stringify({ key: context.key, attributes: context.attributes ?? {} }), this.timeoutMs);
|
|
14498
|
+
surveys = Array.isArray(parsed.surveys) ? parsed.surveys : [];
|
|
14499
|
+
} catch (error) {
|
|
14500
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
14501
|
+
}
|
|
14502
|
+
if (generation !== this.generation)
|
|
14503
|
+
return;
|
|
14504
|
+
if (surveys) {
|
|
14505
|
+
this.surveys = surveys;
|
|
14506
|
+
this.currentStatus = "ready";
|
|
14507
|
+
this.failures = 0;
|
|
14508
|
+
} else {
|
|
14509
|
+
this.currentStatus = "error";
|
|
14510
|
+
this.failures += 1;
|
|
14511
|
+
const delay = Math.min(FIRST_RETRY_DELAY_MS * 2 ** (this.failures - 1), MAX_RETRY_DELAY_MS);
|
|
14512
|
+
this.retryAt = this.now() + delay;
|
|
14513
|
+
this.inflight = null;
|
|
14514
|
+
if (failure)
|
|
14515
|
+
this.onError(failure);
|
|
14516
|
+
}
|
|
14517
|
+
this.notify();
|
|
14518
|
+
})();
|
|
14519
|
+
this.inflight = request;
|
|
14520
|
+
return request;
|
|
14521
|
+
}
|
|
14522
|
+
setContext(key, attributes) {
|
|
14523
|
+
this.generation += 1;
|
|
14524
|
+
this.context = { key, attributes };
|
|
14525
|
+
this.surveys = [];
|
|
14526
|
+
this.inflight = null;
|
|
14527
|
+
this.failures = 0;
|
|
14528
|
+
this.retryAt = 0;
|
|
14529
|
+
this.currentStatus = "idle";
|
|
14530
|
+
this.notify();
|
|
14531
|
+
}
|
|
14532
|
+
eligible(pathname, event) {
|
|
14533
|
+
const seen = this.seen();
|
|
14534
|
+
return this.surveys.filter((survey) => {
|
|
14535
|
+
const trigger = survey.display.trigger_event;
|
|
14536
|
+
if (event === undefined ? Boolean(trigger) : trigger !== event)
|
|
14537
|
+
return false;
|
|
14538
|
+
if (survey.display.path_pattern && !pathMatches(survey.display.path_pattern, pathname)) {
|
|
14539
|
+
return false;
|
|
14540
|
+
}
|
|
14541
|
+
if (this.shownHere.has(survey.id))
|
|
14542
|
+
return false;
|
|
14543
|
+
return !(survey.display.once_per_visitor && seen.has(survey.id));
|
|
14544
|
+
});
|
|
14545
|
+
}
|
|
14546
|
+
markShown(survey) {
|
|
14547
|
+
this.shownHere.add(survey.id);
|
|
14548
|
+
if (survey.display.once_per_visitor)
|
|
14549
|
+
this.remember(survey.id);
|
|
14550
|
+
this.emit("survey_shown", survey);
|
|
14551
|
+
}
|
|
14552
|
+
dismiss(survey) {
|
|
14553
|
+
this.emit("survey_dismissed", survey);
|
|
14554
|
+
}
|
|
14555
|
+
submit(survey, answers) {
|
|
14556
|
+
const checked = validateAnswers(survey, answers);
|
|
14557
|
+
if (!checked.ok)
|
|
14558
|
+
return checked;
|
|
14559
|
+
const data = { survey_id: survey.id, survey_name: survey.name, responses: checked.responses };
|
|
14560
|
+
if (encodedLength(JSON.stringify(data)) > MAX_SURVEY_EVENT_BYTES) {
|
|
14561
|
+
return { ok: false, errors: tooLongErrors(survey, checked.responses) };
|
|
14562
|
+
}
|
|
14563
|
+
this.emit("survey_sent", survey, { responses: checked.responses });
|
|
14564
|
+
return { ok: true };
|
|
14565
|
+
}
|
|
14566
|
+
subscribe(listener) {
|
|
14567
|
+
this.listeners.add(listener);
|
|
14568
|
+
return () => {
|
|
14569
|
+
this.listeners.delete(listener);
|
|
14570
|
+
};
|
|
14571
|
+
}
|
|
14572
|
+
emit(name, survey, extra = {}) {
|
|
14573
|
+
try {
|
|
14574
|
+
this.onEvent(name, { survey_id: survey.id, survey_name: survey.name, ...extra });
|
|
14575
|
+
} catch {}
|
|
14576
|
+
}
|
|
14577
|
+
seen() {
|
|
14578
|
+
if (isCookielessIdentity())
|
|
14579
|
+
return new Set;
|
|
14580
|
+
try {
|
|
14581
|
+
const raw = this.storage?.getItem(SEEN_STORAGE_KEY);
|
|
14582
|
+
const parsed = raw ? JSON.parse(raw) : [];
|
|
14583
|
+
return new Set(Array.isArray(parsed) ? parsed.filter((id) => typeof id === "number") : []);
|
|
14584
|
+
} catch {
|
|
14585
|
+
return new Set;
|
|
14586
|
+
}
|
|
14587
|
+
}
|
|
14588
|
+
remember(id) {
|
|
14589
|
+
if (isCookielessIdentity())
|
|
14590
|
+
return;
|
|
14591
|
+
try {
|
|
14592
|
+
const ids = [...this.seen()].filter((seen) => seen !== id);
|
|
14593
|
+
ids.push(id);
|
|
14594
|
+
this.storage?.setItem(SEEN_STORAGE_KEY, JSON.stringify(ids.slice(-MAX_SEEN)));
|
|
14595
|
+
} catch {}
|
|
14596
|
+
}
|
|
14597
|
+
notify() {
|
|
14598
|
+
this.revision += 1;
|
|
14599
|
+
for (const listener of [...this.listeners]) {
|
|
14600
|
+
try {
|
|
14601
|
+
listener();
|
|
14602
|
+
} catch {}
|
|
14603
|
+
}
|
|
14604
|
+
}
|
|
14605
|
+
}
|
|
14606
|
+
function idMap() {
|
|
14607
|
+
return Object.create(null);
|
|
14608
|
+
}
|
|
14609
|
+
function encodedLength(text) {
|
|
14610
|
+
return new TextEncoder().encode(text).length;
|
|
14611
|
+
}
|
|
14612
|
+
function tooLongErrors(survey, responses) {
|
|
14613
|
+
const message = "These answers are too long to send together. Shorten this one and send again.";
|
|
14614
|
+
const errors = idMap();
|
|
14615
|
+
for (const question of survey.questions) {
|
|
14616
|
+
const answer = responses[question.id];
|
|
14617
|
+
if (question.kind === "open_text" && typeof answer === "string" && answer.length > 0) {
|
|
14618
|
+
errors[question.id] = message;
|
|
14619
|
+
}
|
|
14620
|
+
}
|
|
14621
|
+
const first = survey.questions[0];
|
|
14622
|
+
if (Object.keys(errors).length === 0 && first)
|
|
14623
|
+
errors[first.id] = message;
|
|
14624
|
+
return errors;
|
|
14625
|
+
}
|
|
14626
|
+
function defaultStorage() {
|
|
14627
|
+
try {
|
|
14628
|
+
return typeof window !== "undefined" ? window.localStorage : null;
|
|
14629
|
+
} catch {
|
|
14630
|
+
return null;
|
|
14631
|
+
}
|
|
14632
|
+
}
|
|
14633
|
+
function pathMatches(pattern, pathname) {
|
|
14634
|
+
const parts = pattern.split("*");
|
|
14635
|
+
if (parts.length === 1)
|
|
14636
|
+
return pattern === pathname;
|
|
14637
|
+
const first = parts[0] ?? "";
|
|
14638
|
+
const last = parts[parts.length - 1] ?? "";
|
|
14639
|
+
if (!pathname.startsWith(first))
|
|
14640
|
+
return false;
|
|
14641
|
+
let position = first.length;
|
|
14642
|
+
for (const middle of parts.slice(1, -1)) {
|
|
14643
|
+
const found = pathname.indexOf(middle, position);
|
|
14644
|
+
if (found === -1)
|
|
14645
|
+
return false;
|
|
14646
|
+
position = found + middle.length;
|
|
14647
|
+
}
|
|
14648
|
+
return pathname.length - position >= last.length && pathname.endsWith(last);
|
|
14649
|
+
}
|
|
14650
|
+
function scaleBounds(question) {
|
|
14651
|
+
return question.kind === "nps" ? [0, 10] : [1, question.scale ?? 5];
|
|
14652
|
+
}
|
|
14653
|
+
function validateAnswers(survey, answers) {
|
|
14654
|
+
const errors = idMap();
|
|
14655
|
+
const responses = idMap();
|
|
14656
|
+
for (const question of survey.questions) {
|
|
14657
|
+
const answer = Object.prototype.hasOwnProperty.call(answers, question.id) ? answers[question.id] : undefined;
|
|
14658
|
+
const empty = answer === undefined || answer === null || typeof answer === "string" && answer.trim() === "" || Array.isArray(answer) && answer.length === 0;
|
|
14659
|
+
if (empty) {
|
|
14660
|
+
if (!question.optional)
|
|
14661
|
+
errors[question.id] = "This question needs an answer.";
|
|
14662
|
+
continue;
|
|
14663
|
+
}
|
|
14664
|
+
switch (question.kind) {
|
|
14665
|
+
case "open_text":
|
|
14666
|
+
if (typeof answer !== "string")
|
|
14667
|
+
errors[question.id] = "Expected text.";
|
|
14668
|
+
else
|
|
14669
|
+
responses[question.id] = answer.slice(0, MAX_OPEN_TEXT_LENGTH);
|
|
14670
|
+
break;
|
|
14671
|
+
case "single_choice":
|
|
14672
|
+
if (typeof answer !== "string" || !(question.choices ?? []).includes(answer)) {
|
|
14673
|
+
errors[question.id] = "Pick one of the choices.";
|
|
14674
|
+
} else
|
|
14675
|
+
responses[question.id] = answer;
|
|
14676
|
+
break;
|
|
14677
|
+
case "multiple_choice": {
|
|
14678
|
+
const choices = question.choices ?? [];
|
|
14679
|
+
if (!Array.isArray(answer) || answer.some((item) => !choices.includes(item))) {
|
|
14680
|
+
errors[question.id] = "Pick from the choices.";
|
|
14681
|
+
} else
|
|
14682
|
+
responses[question.id] = [...new Set(answer)];
|
|
14683
|
+
break;
|
|
14684
|
+
}
|
|
14685
|
+
case "rating":
|
|
14686
|
+
case "nps": {
|
|
14687
|
+
const [min, max] = scaleBounds(question);
|
|
14688
|
+
if (typeof answer !== "number" || !Number.isInteger(answer) || answer < min || answer > max) {
|
|
14689
|
+
errors[question.id] = `Pick a number from ${min} to ${max}.`;
|
|
14690
|
+
} else
|
|
14691
|
+
responses[question.id] = answer;
|
|
14692
|
+
break;
|
|
14693
|
+
}
|
|
14694
|
+
}
|
|
14695
|
+
}
|
|
14696
|
+
return Object.keys(errors).length > 0 ? { ok: false, errors } : { ok: true, responses };
|
|
14697
|
+
}
|
|
14698
|
+
|
|
14699
|
+
// ../analytics-core/dist/SurveyWidget.js
|
|
14700
|
+
var STYLE = `
|
|
14701
|
+
:host { all: initial; }
|
|
14702
|
+
.card { position: fixed; right: 16px; bottom: 16px; z-index: 2147483000; width: min(360px, calc(100vw - 32px));
|
|
14703
|
+
max-height: calc(100vh - 32px); overflow: auto; box-sizing: border-box; padding: 16px; border-radius: 10px;
|
|
14704
|
+
background: #fff; color: #111; border: 1px solid #ddd; box-shadow: 0 8px 30px rgba(0,0,0,.15);
|
|
14705
|
+
font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
14706
|
+
@media (prefers-color-scheme: dark) { .card { background: #1c1c1e; color: #f2f2f2; border-color: #3a3a3c; } }
|
|
14707
|
+
.head { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 8px; }
|
|
14708
|
+
h2 { font-size: 15px; margin: 0; }
|
|
14709
|
+
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
|
|
14710
|
+
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
|
|
14711
|
+
.scale { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
14712
|
+
.scale label { flex: 1 0 28px; text-align: center; border: 1px solid #ccc; border-radius: 6px; padding: 4px 0; cursor: pointer; }
|
|
14713
|
+
.scale input { position: absolute; opacity: 0; pointer-events: none; }
|
|
14714
|
+
.scale label:has(input:checked) { background: #111; color: #fff; border-color: #111; }
|
|
14715
|
+
.scale label:has(input:focus-visible) { outline: 2px solid #2563eb; outline-offset: 1px; }
|
|
14716
|
+
.labels { display: flex; justify-content: space-between; font-size: 12px; opacity: .7; margin-top: 2px; }
|
|
14717
|
+
.choice { display: flex; gap: 6px; align-items: center; margin: 2px 0; }
|
|
14718
|
+
textarea { width: 100%; box-sizing: border-box; min-height: 64px; font: inherit; padding: 6px; border-radius: 6px; border: 1px solid #ccc; }
|
|
14719
|
+
.error { color: #b91c1c; font-size: 12px; margin-top: 4px; }
|
|
14720
|
+
button { font: inherit; cursor: pointer; border-radius: 6px; }
|
|
14721
|
+
.close { background: none; border: 0; font-size: 18px; line-height: 1; color: inherit; padding: 0 4px; }
|
|
14722
|
+
.send { width: 100%; padding: 8px; background: #111; color: #fff; border: 0; }
|
|
14723
|
+
.thanks { margin: 0; }
|
|
14724
|
+
`;
|
|
14725
|
+
function renderSurveyWidget(survey, handlers) {
|
|
14726
|
+
if (typeof document === "undefined")
|
|
14727
|
+
return () => {
|
|
14728
|
+
return;
|
|
14729
|
+
};
|
|
14730
|
+
const host = document.createElement("div");
|
|
14731
|
+
host.setAttribute("data-temps-survey", String(survey.id));
|
|
14732
|
+
const root = host.attachShadow({ mode: "open" });
|
|
14733
|
+
const style = document.createElement("style");
|
|
14734
|
+
style.textContent = STYLE;
|
|
14735
|
+
root.appendChild(style);
|
|
14736
|
+
const titleId = `temps-survey-${survey.id}-title`;
|
|
14737
|
+
const card = element("form", { class: "card", role: "dialog", "aria-labelledby": titleId });
|
|
14738
|
+
card.noValidate = true;
|
|
14739
|
+
const head = element("div", { class: "head" });
|
|
14740
|
+
const title = element("h2", { id: titleId });
|
|
14741
|
+
title.textContent = survey.name;
|
|
14742
|
+
const close = element("button", { type: "button", class: "close", "aria-label": "Close survey" });
|
|
14743
|
+
close.textContent = "×";
|
|
14744
|
+
head.append(title, close);
|
|
14745
|
+
card.appendChild(head);
|
|
14746
|
+
const errorSlots = new Map;
|
|
14747
|
+
for (const question of survey.questions) {
|
|
14748
|
+
const { fieldset, error } = renderQuestion(survey.id, question);
|
|
14749
|
+
errorSlots.set(question.id, error);
|
|
14750
|
+
card.appendChild(fieldset);
|
|
14751
|
+
}
|
|
14752
|
+
const send = element("button", { type: "submit", class: "send" });
|
|
14753
|
+
send.textContent = "Send";
|
|
14754
|
+
card.appendChild(send);
|
|
14755
|
+
root.appendChild(card);
|
|
14756
|
+
document.body.appendChild(host);
|
|
14757
|
+
let removed = false;
|
|
14758
|
+
let answered = false;
|
|
14759
|
+
const remove = () => {
|
|
14760
|
+
if (removed)
|
|
14761
|
+
return;
|
|
14762
|
+
removed = true;
|
|
14763
|
+
document.removeEventListener("keydown", onKey);
|
|
14764
|
+
host.remove();
|
|
14765
|
+
handlers.onClosed?.();
|
|
14766
|
+
};
|
|
14767
|
+
const dismiss = () => {
|
|
14768
|
+
if (!answered)
|
|
14769
|
+
handlers.onDismiss();
|
|
14770
|
+
remove();
|
|
14771
|
+
};
|
|
14772
|
+
const onKey = (event) => {
|
|
14773
|
+
if (event.key === "Escape")
|
|
14774
|
+
dismiss();
|
|
14775
|
+
};
|
|
14776
|
+
document.addEventListener("keydown", onKey);
|
|
14777
|
+
close.addEventListener("click", dismiss);
|
|
14778
|
+
card.addEventListener("submit", (event) => {
|
|
14779
|
+
event.preventDefault();
|
|
14780
|
+
const errors = handlers.onSubmit(collectAnswers(card, survey));
|
|
14781
|
+
for (const [id, slot] of errorSlots)
|
|
14782
|
+
slot.textContent = errors?.[id] ?? "";
|
|
14783
|
+
if (errors)
|
|
14784
|
+
return;
|
|
14785
|
+
answered = true;
|
|
14786
|
+
card.replaceChildren(head);
|
|
14787
|
+
const thanks = element("p", { class: "thanks", role: "status" });
|
|
14788
|
+
thanks.textContent = "Thanks for your answer.";
|
|
14789
|
+
card.appendChild(thanks);
|
|
14790
|
+
setTimeout(remove, 2500);
|
|
14791
|
+
});
|
|
14792
|
+
return remove;
|
|
14793
|
+
}
|
|
14794
|
+
function renderQuestion(surveyId, question) {
|
|
14795
|
+
const name = `q-${surveyId}-${question.id}`;
|
|
14796
|
+
const fieldset = element("fieldset", {});
|
|
14797
|
+
const legend = element("legend", {});
|
|
14798
|
+
legend.textContent = question.optional ? `${question.prompt} (optional)` : question.prompt;
|
|
14799
|
+
fieldset.appendChild(legend);
|
|
14800
|
+
switch (question.kind) {
|
|
14801
|
+
case "open_text": {
|
|
14802
|
+
const textarea = element("textarea", { name, maxlength: String(MAX_OPEN_TEXT_LENGTH), "aria-label": question.prompt });
|
|
14803
|
+
fieldset.appendChild(textarea);
|
|
14804
|
+
break;
|
|
14805
|
+
}
|
|
14806
|
+
case "rating":
|
|
14807
|
+
case "nps": {
|
|
14808
|
+
const [min, max] = scaleBounds(question);
|
|
14809
|
+
const scale = element("div", { class: "scale" });
|
|
14810
|
+
for (let value = min;value <= max; value += 1) {
|
|
14811
|
+
const label = element("label", {});
|
|
14812
|
+
const input = element("input", { type: "radio", name, value: String(value) });
|
|
14813
|
+
label.append(input, document.createTextNode(String(value)));
|
|
14814
|
+
scale.appendChild(label);
|
|
14815
|
+
}
|
|
14816
|
+
fieldset.appendChild(scale);
|
|
14817
|
+
if (question.lower_label || question.upper_label) {
|
|
14818
|
+
const labels = element("div", { class: "labels" });
|
|
14819
|
+
const low = element("span", {});
|
|
14820
|
+
low.textContent = question.lower_label ?? "";
|
|
14821
|
+
const high = element("span", {});
|
|
14822
|
+
high.textContent = question.upper_label ?? "";
|
|
14823
|
+
labels.append(low, high);
|
|
14824
|
+
fieldset.appendChild(labels);
|
|
14825
|
+
}
|
|
14826
|
+
break;
|
|
14827
|
+
}
|
|
14828
|
+
case "single_choice":
|
|
14829
|
+
case "multiple_choice": {
|
|
14830
|
+
const type = question.kind === "single_choice" ? "radio" : "checkbox";
|
|
14831
|
+
for (const choice of question.choices ?? []) {
|
|
14832
|
+
const label = element("label", { class: "choice" });
|
|
14833
|
+
const input = element("input", { type, name, value: choice });
|
|
14834
|
+
label.append(input, document.createTextNode(choice));
|
|
14835
|
+
fieldset.appendChild(label);
|
|
14836
|
+
}
|
|
14837
|
+
break;
|
|
14838
|
+
}
|
|
14839
|
+
}
|
|
14840
|
+
const error = element("div", { class: "error", role: "alert" });
|
|
14841
|
+
fieldset.appendChild(error);
|
|
14842
|
+
return { fieldset, error };
|
|
14843
|
+
}
|
|
14844
|
+
function collectAnswers(form, survey) {
|
|
14845
|
+
const answers = idMap();
|
|
14846
|
+
for (const question of survey.questions) {
|
|
14847
|
+
const name = `q-${survey.id}-${question.id}`;
|
|
14848
|
+
const fields = Array.from(form.querySelectorAll(`[name="${cssEscape(name)}"]`));
|
|
14849
|
+
switch (question.kind) {
|
|
14850
|
+
case "open_text":
|
|
14851
|
+
answers[question.id] = fields[0]?.value ?? "";
|
|
14852
|
+
break;
|
|
14853
|
+
case "rating":
|
|
14854
|
+
case "nps": {
|
|
14855
|
+
const picked = fields.find((field) => field.checked);
|
|
14856
|
+
if (picked)
|
|
14857
|
+
answers[question.id] = Number(picked.value);
|
|
14858
|
+
break;
|
|
14859
|
+
}
|
|
14860
|
+
case "single_choice": {
|
|
14861
|
+
const picked = fields.find((field) => field.checked);
|
|
14862
|
+
if (picked)
|
|
14863
|
+
answers[question.id] = picked.value;
|
|
14864
|
+
break;
|
|
14865
|
+
}
|
|
14866
|
+
case "multiple_choice":
|
|
14867
|
+
answers[question.id] = fields.filter((field) => field.checked).map((field) => field.value);
|
|
14868
|
+
break;
|
|
14869
|
+
}
|
|
14870
|
+
}
|
|
14871
|
+
return answers;
|
|
14872
|
+
}
|
|
14873
|
+
function cssEscape(value) {
|
|
14874
|
+
return value.replace(/["\\]/g, "\\$&");
|
|
14875
|
+
}
|
|
14876
|
+
function element(tag, attributes) {
|
|
14877
|
+
const node = document.createElement(tag);
|
|
14878
|
+
for (const [name, value] of Object.entries(attributes))
|
|
14879
|
+
node.setAttribute(name, value);
|
|
14880
|
+
return node;
|
|
14881
|
+
}
|
|
14882
|
+
|
|
13823
14883
|
// ../analytics-core/dist/Analytics.js
|
|
13824
14884
|
function createAnalytics(options = {}) {
|
|
13825
|
-
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;
|
|
14885
|
+
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 = {}, autoTrackOutboundLinks = true, autoTrackFileDownloads = true, fileDownloadExtensions, autoTrackNotFound = true, cookieless = false, flags: flagOptions = {}, surveys: surveyOptions = {} } = options;
|
|
13826
14886
|
const cleanups = [];
|
|
14887
|
+
if (cookieless)
|
|
14888
|
+
enableCookielessIdentity();
|
|
14889
|
+
const recordingAllowed = () => !isCookielessIdentity();
|
|
13827
14890
|
const enabled = computeEnabled(disabled, ignoreLocalhost);
|
|
13828
14891
|
const resolveDomain = () => domain || (typeof window !== "undefined" ? window.location.hostname : "");
|
|
13829
|
-
const
|
|
14892
|
+
const sendEvent = async (eventName, data = {}) => {
|
|
13830
14893
|
if (!enabled)
|
|
13831
14894
|
return;
|
|
13832
14895
|
await sendAnalytics("event", {
|
|
@@ -13838,10 +14901,19 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13838
14901
|
event_data: data
|
|
13839
14902
|
}, "POST", basePath, ingestKey);
|
|
13840
14903
|
};
|
|
14904
|
+
const trackNotFound = async (data = {}) => {
|
|
14905
|
+
if (!enabled)
|
|
14906
|
+
return;
|
|
14907
|
+
await trackEvent(NOT_FOUND_EVENT, notFoundEventData(data));
|
|
14908
|
+
};
|
|
14909
|
+
const notFoundWatcher = enabled && autoTrackNotFound ? new NotFoundMarkerWatcher(() => void trackNotFound()) : null;
|
|
14910
|
+
if (notFoundWatcher)
|
|
14911
|
+
cleanups.push(() => notFoundWatcher.cancel());
|
|
14912
|
+
let pendingPageview = Promise.resolve();
|
|
13841
14913
|
const trackPageview = () => {
|
|
13842
14914
|
if (!enabled)
|
|
13843
14915
|
return;
|
|
13844
|
-
sendAnalytics("event", {
|
|
14916
|
+
pendingPageview = sendAnalytics("event", {
|
|
13845
14917
|
event_name: "page_view",
|
|
13846
14918
|
request_query: window.location.search,
|
|
13847
14919
|
request_path: window.location.pathname,
|
|
@@ -13853,11 +14925,84 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13853
14925
|
timestamp: new Date().toISOString()
|
|
13854
14926
|
}
|
|
13855
14927
|
}, "POST", basePath, ingestKey);
|
|
14928
|
+
notFoundWatcher?.afterPageview();
|
|
14929
|
+
};
|
|
14930
|
+
const flags = new FeatureFlags({
|
|
14931
|
+
...flagOptions,
|
|
14932
|
+
basePath,
|
|
14933
|
+
disabled,
|
|
14934
|
+
onExposure: (exposure) => {
|
|
14935
|
+
if (enabled)
|
|
14936
|
+
sendEvent("flag_exposure", exposureEventData(exposure));
|
|
14937
|
+
}
|
|
14938
|
+
});
|
|
14939
|
+
const surveysEnabled = enabled && surveyOptions.enabled === true;
|
|
14940
|
+
const autoShowSurveys = surveysEnabled && surveyOptions.autoShow !== false;
|
|
14941
|
+
const surveys = new Surveys({
|
|
14942
|
+
basePath,
|
|
14943
|
+
key: surveyOptions.key,
|
|
14944
|
+
attributes: surveyOptions.attributes,
|
|
14945
|
+
onError: surveyOptions.onError,
|
|
14946
|
+
disabled: !surveysEnabled,
|
|
14947
|
+
onEvent: (name, data) => {
|
|
14948
|
+
sendEvent(name, data);
|
|
14949
|
+
}
|
|
14950
|
+
});
|
|
14951
|
+
let openSurvey = null;
|
|
14952
|
+
let destroyed = false;
|
|
14953
|
+
const showSurvey = async (event) => {
|
|
14954
|
+
if (!autoShowSurveys || openSurvey || destroyed)
|
|
14955
|
+
return;
|
|
14956
|
+
await surveys.load();
|
|
14957
|
+
if (openSurvey || destroyed)
|
|
14958
|
+
return;
|
|
14959
|
+
const next = surveys.eligible(window.location.pathname, event)[0];
|
|
14960
|
+
if (!next)
|
|
14961
|
+
return;
|
|
14962
|
+
surveys.markShown(next);
|
|
14963
|
+
let closed = false;
|
|
14964
|
+
const close = renderSurveyWidget(next, {
|
|
14965
|
+
onSubmit: (answers) => {
|
|
14966
|
+
const result = surveys.submit(next, answers);
|
|
14967
|
+
return result.ok ? null : result.errors;
|
|
14968
|
+
},
|
|
14969
|
+
onDismiss: () => surveys.dismiss(next),
|
|
14970
|
+
onClosed: () => {
|
|
14971
|
+
closed = true;
|
|
14972
|
+
if (openSurvey === closeThis)
|
|
14973
|
+
openSurvey = null;
|
|
14974
|
+
}
|
|
14975
|
+
});
|
|
14976
|
+
const closeThis = () => close();
|
|
14977
|
+
if (!closed)
|
|
14978
|
+
openSurvey = closeThis;
|
|
14979
|
+
};
|
|
14980
|
+
cleanups.push(() => {
|
|
14981
|
+
destroyed = true;
|
|
14982
|
+
openSurvey?.();
|
|
14983
|
+
});
|
|
14984
|
+
const trackEvent = async (eventName, data = {}) => {
|
|
14985
|
+
if (!eventName.startsWith("survey_"))
|
|
14986
|
+
showSurvey(eventName);
|
|
14987
|
+
await sendEvent(eventName, data);
|
|
14988
|
+
};
|
|
14989
|
+
const identify = async (userId, traits) => {
|
|
14990
|
+
if (!enabled) {
|
|
14991
|
+
return { applied: false, outcome: "disabled", message: "Analytics is disabled on this page." };
|
|
14992
|
+
}
|
|
14993
|
+
return identifyVisitor({ basePath, ingestKey, userId, traits, ready: pendingPageview });
|
|
14994
|
+
};
|
|
14995
|
+
const reset = async () => {
|
|
14996
|
+
if (!enabled)
|
|
14997
|
+
return;
|
|
14998
|
+
await resetVisitor({ basePath, ingestKey });
|
|
13856
14999
|
};
|
|
13857
|
-
const identify = async () => {};
|
|
13858
15000
|
if (enabled) {
|
|
13859
15001
|
if (autoTrackPageviews) {
|
|
13860
|
-
cleanups.push(setupPageviewTracking(
|
|
15002
|
+
cleanups.push(setupPageviewTracking(() => {
|
|
15003
|
+
trackPageview();
|
|
15004
|
+
showSurvey();
|
|
15005
|
+
}));
|
|
13861
15006
|
}
|
|
13862
15007
|
if (autoTrackEngagement) {
|
|
13863
15008
|
const tracker = new EngagementTracker({
|
|
@@ -13877,8 +15022,23 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13877
15022
|
cleanups.push(() => speed.destroy());
|
|
13878
15023
|
}
|
|
13879
15024
|
cleanups.push(setupClickDelegation(trackEvent));
|
|
15025
|
+
cleanups.push(setupLinkTracking({ autoTrackOutboundLinks, autoTrackFileDownloads, fileDownloadExtensions }, (eventName, data) => {
|
|
15026
|
+
sendAnalyticsReliable("event", {
|
|
15027
|
+
event_name: eventName,
|
|
15028
|
+
request_query: window.location.search,
|
|
15029
|
+
request_path: window.location.pathname,
|
|
15030
|
+
domain: resolveDomain(),
|
|
15031
|
+
language: navigator.language,
|
|
15032
|
+
event_data: data
|
|
15033
|
+
}, basePath, ingestKey);
|
|
15034
|
+
}));
|
|
15035
|
+
if (!autoTrackPageviews)
|
|
15036
|
+
showSurvey();
|
|
15037
|
+
}
|
|
15038
|
+
if (!recordingAllowed() && enableSessionRecording) {
|
|
15039
|
+
console.warn("[temps] Session recording is off in cookieless mode: a replay needs a visitor id stored on the device.");
|
|
13880
15040
|
}
|
|
13881
|
-
const recorder = enabled && enableSessionRecording ? new SessionRecorder({
|
|
15041
|
+
const recorder = enabled && enableSessionRecording && recordingAllowed() ? new SessionRecorder({
|
|
13882
15042
|
basePath,
|
|
13883
15043
|
ingestKey,
|
|
13884
15044
|
domain: resolveDomain(),
|
|
@@ -13888,16 +15048,31 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
13888
15048
|
if (recorder)
|
|
13889
15049
|
cleanups.push(() => recorder.destroy());
|
|
13890
15050
|
let runtimeRecorder = recorder;
|
|
15051
|
+
cleanups.push(onCookielessIdentity(() => {
|
|
15052
|
+
runtimeRecorder?.discard();
|
|
15053
|
+
runtimeRecorder = null;
|
|
15054
|
+
}));
|
|
15055
|
+
cleanups.push(onIdentityReset((phase) => {
|
|
15056
|
+
if (phase === "started")
|
|
15057
|
+
runtimeRecorder?.endForReset();
|
|
15058
|
+
else
|
|
15059
|
+
runtimeRecorder?.resumeAfterReset();
|
|
15060
|
+
}));
|
|
13891
15061
|
return {
|
|
13892
15062
|
get enabled() {
|
|
13893
15063
|
return enabled;
|
|
13894
15064
|
},
|
|
13895
15065
|
ingestKey,
|
|
15066
|
+
flags,
|
|
15067
|
+
surveys,
|
|
13896
15068
|
trackEvent,
|
|
13897
15069
|
trackPageview,
|
|
15070
|
+
trackNotFound,
|
|
13898
15071
|
identify,
|
|
15072
|
+
reset,
|
|
15073
|
+
getVisitorId: getStoredVisitorId,
|
|
13899
15074
|
enableSessionRecording() {
|
|
13900
|
-
if (!enabled)
|
|
15075
|
+
if (!enabled || !recordingAllowed())
|
|
13901
15076
|
return;
|
|
13902
15077
|
if (runtimeRecorder) {
|
|
13903
15078
|
runtimeRecorder.start();
|
|
@@ -14058,6 +15233,8 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
14058
15233
|
opts.ingestKey = ds.ingestKey;
|
|
14059
15234
|
if (ds.domain)
|
|
14060
15235
|
opts.domain = ds.domain;
|
|
15236
|
+
if (ds.cookieless)
|
|
15237
|
+
opts.cookieless = ds.cookieless === "true";
|
|
14061
15238
|
if (ds.disabled)
|
|
14062
15239
|
opts.disabled = ds.disabled === "true";
|
|
14063
15240
|
if (ds.ignoreLocalhost)
|
|
@@ -14078,6 +15255,15 @@ or you can use record.mirror to access the mirror instance during recording.`;
|
|
|
14078
15255
|
opts.inactivityTimeout = Number(ds.inactivityTimeout);
|
|
14079
15256
|
if (ds.engagementThreshold)
|
|
14080
15257
|
opts.engagementThreshold = Number(ds.engagementThreshold);
|
|
15258
|
+
if (ds.autoTrackOutboundLinks)
|
|
15259
|
+
opts.autoTrackOutboundLinks = ds.autoTrackOutboundLinks === "true";
|
|
15260
|
+
if (ds.autoTrackFileDownloads)
|
|
15261
|
+
opts.autoTrackFileDownloads = ds.autoTrackFileDownloads === "true";
|
|
15262
|
+
if (ds.fileDownloadExtensions) {
|
|
15263
|
+
opts.fileDownloadExtensions = ds.fileDownloadExtensions.split(",").map((s) => s.trim().replace(/^\./, "")).filter((s) => s.length > 0);
|
|
15264
|
+
}
|
|
15265
|
+
if (ds.autoTrackNotFound)
|
|
15266
|
+
opts.autoTrackNotFound = ds.autoTrackNotFound === "true";
|
|
14081
15267
|
if (ds.sessionRecording)
|
|
14082
15268
|
opts.enableSessionRecording = ds.sessionRecording === "true";
|
|
14083
15269
|
if (ds.sessionSampleRate)
|