@faststats/web 0.5.0 → 0.6.0
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/chunks/api-urls-CaNa8upY.js +45 -0
- package/dist/chunks/identifiers-cUymVK5H.js +20 -0
- package/dist/chunks/{replay-CLfrGjqj.d.ts → replay-DgodPHzA.d.ts} +12 -6
- package/dist/chunks/send-data-DjdbGDDc.js +196 -0
- package/dist/error.d.ts +1 -0
- package/dist/error.js +127 -2
- package/dist/feature-flags.js +32 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +444 -1
- package/dist/replay.d.ts +1 -1
- package/dist/replay.js +506 -1
- package/dist/web-vitals.js +115 -1
- package/package.json +2 -2
- package/dist/chunks/api-urls-Bh77rElT.js +0 -1
- package/dist/chunks/identifiers-DcGHdsnG.js +0 -1
- package/dist/chunks/send-data-CIbuTxPh.js +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/utils/api-urls.ts
|
|
2
|
+
const ANALYTICS_BASE = "https://metrics.faststats.dev";
|
|
3
|
+
const FEATURE_FLAGS_BASE = "https://flags.faststats.dev";
|
|
4
|
+
function resolveBaseUrl(input, fallback) {
|
|
5
|
+
return input?.replace(/\/+$/, "") || fallback;
|
|
6
|
+
}
|
|
7
|
+
const URLS = {
|
|
8
|
+
events: "/v1/web",
|
|
9
|
+
identify: "/v1/identify",
|
|
10
|
+
replay: "/v1/replay",
|
|
11
|
+
vitals: "/v1/vitals",
|
|
12
|
+
flags: "/v1/check"
|
|
13
|
+
};
|
|
14
|
+
function sanitizeUrl(url) {
|
|
15
|
+
try {
|
|
16
|
+
const parsed = new URL(url, location.href);
|
|
17
|
+
return `${parsed.origin}${parsed.pathname}`;
|
|
18
|
+
} catch {
|
|
19
|
+
return url.split(/[?#]/, 1)[0] ?? "";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const UTM_KEYS = [
|
|
23
|
+
"utm_source",
|
|
24
|
+
"utm_medium",
|
|
25
|
+
"utm_campaign",
|
|
26
|
+
"utm_term",
|
|
27
|
+
"utm_content"
|
|
28
|
+
];
|
|
29
|
+
function getPageContext() {
|
|
30
|
+
const ctx = {
|
|
31
|
+
page: location.pathname,
|
|
32
|
+
url: sanitizeUrl(location.href),
|
|
33
|
+
referrer: document.referrer ? sanitizeUrl(document.referrer) : null,
|
|
34
|
+
title: document.title || ""
|
|
35
|
+
};
|
|
36
|
+
if (!location.search) return ctx;
|
|
37
|
+
const sp = new URLSearchParams(location.search);
|
|
38
|
+
for (const key of UTM_KEYS) {
|
|
39
|
+
const value = sp.get(key);
|
|
40
|
+
if (value) ctx[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return ctx;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { resolveBaseUrl as a, getPageContext as i, FEATURE_FLAGS_BASE as n, sanitizeUrl as o, URLS as r, ANALYTICS_BASE as t };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { d as setStorageItem, i as isCookielessMode, l as getStorageItem, n as createId, u as removeStorageItem } from "./send-data-DjdbGDDc.js";
|
|
2
|
+
//#region src/utils/identifiers.ts
|
|
3
|
+
const ANONYMOUS_ID_KEY = "faststats_anon_id";
|
|
4
|
+
function getOrCreateAnonymousId() {
|
|
5
|
+
const existingId = getStorageItem("localStorage", ANONYMOUS_ID_KEY);
|
|
6
|
+
if (existingId) return existingId;
|
|
7
|
+
const newId = createId();
|
|
8
|
+
return setStorageItem("localStorage", ANONYMOUS_ID_KEY, newId) ? newId : "";
|
|
9
|
+
}
|
|
10
|
+
function getAnonymousId(cookieless) {
|
|
11
|
+
if (cookieless ?? isCookielessMode()) return "";
|
|
12
|
+
return getOrCreateAnonymousId();
|
|
13
|
+
}
|
|
14
|
+
function resetAnonymousId(cookieless) {
|
|
15
|
+
if (cookieless) return "";
|
|
16
|
+
if (!removeStorageItem("localStorage", ANONYMOUS_ID_KEY)) return "";
|
|
17
|
+
return getOrCreateAnonymousId();
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { resetAnonymousId as n, getAnonymousId as t };
|
|
@@ -43,32 +43,34 @@ declare class ReplayTracker {
|
|
|
43
43
|
private readonly minReplayLengthMs;
|
|
44
44
|
private readonly events;
|
|
45
45
|
private readonly pending;
|
|
46
|
+
private readonly minLengthBlockedBatches;
|
|
46
47
|
private queuedEventsSizeBytes;
|
|
47
48
|
private pendingSizeBytes;
|
|
48
49
|
private viewId;
|
|
49
50
|
private chunkStartedAt;
|
|
50
51
|
private started;
|
|
52
|
+
private disposed;
|
|
51
53
|
private startGeneration;
|
|
52
54
|
private startTime;
|
|
53
55
|
private sequence;
|
|
54
56
|
private intervalId;
|
|
55
57
|
private flushTask;
|
|
56
58
|
private retryTask;
|
|
59
|
+
private retryAttempt;
|
|
57
60
|
private minLengthFlushTask;
|
|
58
61
|
private stopRecording?;
|
|
59
62
|
private sending;
|
|
60
|
-
private
|
|
61
|
-
private
|
|
63
|
+
private inFlightBatch;
|
|
64
|
+
private queuedFlush;
|
|
62
65
|
private unsubscribeRotation?;
|
|
63
66
|
private lastCookielessMode;
|
|
64
67
|
constructor(options: ReplayTrackerOptions);
|
|
65
68
|
private log;
|
|
66
69
|
private clearFlushTimers;
|
|
67
70
|
private clearQueues;
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
private writeCounter;
|
|
71
|
+
private dropMinLengthBlockedBatches;
|
|
72
|
+
private unblockSessionBatches;
|
|
73
|
+
private finalizeSessionPending;
|
|
72
74
|
private nextBatchSequence;
|
|
73
75
|
setCookielessMode(cookieless: boolean): void;
|
|
74
76
|
start(): void;
|
|
@@ -78,6 +80,8 @@ declare class ReplayTracker {
|
|
|
78
80
|
private beginRecording;
|
|
79
81
|
stop(): void;
|
|
80
82
|
private onSessionRotated;
|
|
83
|
+
private applySessionRotation;
|
|
84
|
+
private resetSessionTiming;
|
|
81
85
|
private onEvent;
|
|
82
86
|
private onUnload;
|
|
83
87
|
private hasReachedMinLength;
|
|
@@ -89,9 +93,11 @@ declare class ReplayTracker {
|
|
|
89
93
|
private eventSizeBytes;
|
|
90
94
|
private batchSizeBytes;
|
|
91
95
|
private dropOldestPending;
|
|
96
|
+
private removePending;
|
|
92
97
|
private enqueueBatch;
|
|
93
98
|
private flush;
|
|
94
99
|
private scheduleRetry;
|
|
100
|
+
private retryDelay;
|
|
95
101
|
private sendBatch;
|
|
96
102
|
}
|
|
97
103
|
//#endregion
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
//#region src/utils/storage.ts
|
|
2
|
+
function getStorageItem(name, key) {
|
|
3
|
+
try {
|
|
4
|
+
return globalThis[name]?.getItem(key) ?? null;
|
|
5
|
+
} catch {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function setStorageItem(name, key, value) {
|
|
10
|
+
try {
|
|
11
|
+
const storage = globalThis[name];
|
|
12
|
+
if (!storage) return false;
|
|
13
|
+
storage.setItem(key, value);
|
|
14
|
+
return true;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function removeStorageItem(name, key) {
|
|
20
|
+
try {
|
|
21
|
+
const storage = globalThis[name];
|
|
22
|
+
if (!storage) return false;
|
|
23
|
+
storage.removeItem(key);
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/utils/session-manager.ts
|
|
31
|
+
const IDLE_MS = 1800 * 1e3;
|
|
32
|
+
const MAX_AGE_MS = 1440 * 60 * 1e3;
|
|
33
|
+
const SESSION_KEY = "faststats_session";
|
|
34
|
+
let cookielessMode = false;
|
|
35
|
+
let memorySession = null;
|
|
36
|
+
const rotationListeners = /* @__PURE__ */ new Set();
|
|
37
|
+
function createId() {
|
|
38
|
+
if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID();
|
|
39
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
40
|
+
}
|
|
41
|
+
function readSession() {
|
|
42
|
+
const raw = getStorageItem("localStorage", SESSION_KEY);
|
|
43
|
+
if (!raw) return memorySession;
|
|
44
|
+
try {
|
|
45
|
+
const session = JSON.parse(raw);
|
|
46
|
+
return session.id ? session : memorySession;
|
|
47
|
+
} catch {}
|
|
48
|
+
return memorySession;
|
|
49
|
+
}
|
|
50
|
+
function writeSession(session) {
|
|
51
|
+
if (!setStorageItem("localStorage", SESSION_KEY, JSON.stringify(session))) memorySession = session;
|
|
52
|
+
}
|
|
53
|
+
function clearSession() {
|
|
54
|
+
memorySession = null;
|
|
55
|
+
removeStorageItem("localStorage", SESSION_KEY);
|
|
56
|
+
}
|
|
57
|
+
function expired(session, now) {
|
|
58
|
+
return now - session.activity >= IDLE_MS || now - session.start >= MAX_AGE_MS;
|
|
59
|
+
}
|
|
60
|
+
function emitRotation(prev, next) {
|
|
61
|
+
for (const listener of rotationListeners) listener(prev, next);
|
|
62
|
+
}
|
|
63
|
+
function resolveSession(cookieless, touch) {
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
if (cookieless) {
|
|
66
|
+
if (!memorySession) memorySession = {
|
|
67
|
+
id: createId(),
|
|
68
|
+
start: now,
|
|
69
|
+
activity: now
|
|
70
|
+
};
|
|
71
|
+
else if (touch) memorySession.activity = now;
|
|
72
|
+
return {
|
|
73
|
+
session: memorySession,
|
|
74
|
+
rotatedFrom: null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const existing = readSession();
|
|
78
|
+
if (existing && !expired(existing, now)) {
|
|
79
|
+
if (touch) {
|
|
80
|
+
existing.activity = now;
|
|
81
|
+
writeSession(existing);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
session: existing,
|
|
85
|
+
rotatedFrom: null
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const session = {
|
|
89
|
+
id: createId(),
|
|
90
|
+
start: now,
|
|
91
|
+
activity: now
|
|
92
|
+
};
|
|
93
|
+
writeSession(session);
|
|
94
|
+
return {
|
|
95
|
+
session,
|
|
96
|
+
rotatedFrom: existing
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function windowId(siteKey, cookieless, sessionId) {
|
|
100
|
+
if (cookieless) return sessionId;
|
|
101
|
+
const key = `faststats_window_id_${siteKey}`;
|
|
102
|
+
const existing = getStorageItem("sessionStorage", key);
|
|
103
|
+
if (existing) return existing;
|
|
104
|
+
const id = createId();
|
|
105
|
+
return setStorageItem("sessionStorage", key, id) ? id : sessionId;
|
|
106
|
+
}
|
|
107
|
+
function toContext(siteKey, session, cookieless, windowIdOverride) {
|
|
108
|
+
return {
|
|
109
|
+
sessionId: session.id,
|
|
110
|
+
windowId: windowIdOverride ?? windowId(siteKey, cookieless, session.id),
|
|
111
|
+
sessionStart: session.start
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function setCookielessMode(mode) {
|
|
115
|
+
cookielessMode = mode;
|
|
116
|
+
memorySession = null;
|
|
117
|
+
}
|
|
118
|
+
function isCookielessMode() {
|
|
119
|
+
return cookielessMode;
|
|
120
|
+
}
|
|
121
|
+
function getSessionContext(siteKey, cookieless) {
|
|
122
|
+
const useCookieless = cookieless ?? cookielessMode;
|
|
123
|
+
const { session, rotatedFrom } = resolveSession(useCookieless, false);
|
|
124
|
+
const next = toContext(siteKey, session, useCookieless);
|
|
125
|
+
if (rotatedFrom) emitRotation(toContext(siteKey, rotatedFrom, useCookieless, next.windowId), next);
|
|
126
|
+
return next;
|
|
127
|
+
}
|
|
128
|
+
function touchActivity(siteKey, cookieless) {
|
|
129
|
+
const useCookieless = cookieless ?? cookielessMode;
|
|
130
|
+
const { session, rotatedFrom } = resolveSession(useCookieless, true);
|
|
131
|
+
if (!rotatedFrom) return null;
|
|
132
|
+
const wid = windowId(siteKey, useCookieless, session.id);
|
|
133
|
+
const rotation = {
|
|
134
|
+
prev: toContext(siteKey, rotatedFrom, useCookieless, wid),
|
|
135
|
+
next: toContext(siteKey, session, useCookieless, wid)
|
|
136
|
+
};
|
|
137
|
+
emitRotation(rotation.prev, rotation.next);
|
|
138
|
+
return rotation;
|
|
139
|
+
}
|
|
140
|
+
function resetSession(siteKey) {
|
|
141
|
+
const useCookieless = cookielessMode;
|
|
142
|
+
const previous = getSessionContext(siteKey, useCookieless);
|
|
143
|
+
clearSession();
|
|
144
|
+
if (useCookieless) {
|
|
145
|
+
const now = Date.now();
|
|
146
|
+
memorySession = {
|
|
147
|
+
id: createId(),
|
|
148
|
+
start: now,
|
|
149
|
+
activity: now
|
|
150
|
+
};
|
|
151
|
+
} else removeStorageItem("sessionStorage", `faststats_window_id_${siteKey}`);
|
|
152
|
+
const next = getSessionContext(siteKey, useCookieless);
|
|
153
|
+
if (previous.sessionId !== next.sessionId) emitRotation(previous, next);
|
|
154
|
+
return next;
|
|
155
|
+
}
|
|
156
|
+
function onSessionRotated(listener) {
|
|
157
|
+
rotationListeners.add(listener);
|
|
158
|
+
return () => rotationListeners.delete(listener);
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/utils/send-data.ts
|
|
162
|
+
async function sendData(options) {
|
|
163
|
+
const { url, data, contentType = "application/json", headers = {}, debug = false, debugPrefix = "[Analytics]", useBeacon = true, keepalive = true, signal } = options;
|
|
164
|
+
if (signal?.aborted) return false;
|
|
165
|
+
if (useBeacon && typeof globalThis.navigator?.sendBeacon === "function") try {
|
|
166
|
+
const beaconBody = data instanceof Blob || typeof Blob === "undefined" ? data : new Blob([data], { type: contentType });
|
|
167
|
+
if (globalThis.navigator.sendBeacon(url, beaconBody)) {
|
|
168
|
+
if (debug) console.log(`${debugPrefix} Sent via beacon`);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
} catch {}
|
|
172
|
+
try {
|
|
173
|
+
const response = await fetch(url, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
body: data,
|
|
176
|
+
headers: {
|
|
177
|
+
"Content-Type": contentType,
|
|
178
|
+
...headers
|
|
179
|
+
},
|
|
180
|
+
keepalive,
|
|
181
|
+
credentials: "omit",
|
|
182
|
+
signal
|
|
183
|
+
});
|
|
184
|
+
const success = response.ok;
|
|
185
|
+
if (debug) {
|
|
186
|
+
const message = success ? `${debugPrefix} Sent via fetch` : `${debugPrefix} Failed: ${response.status}`;
|
|
187
|
+
console[success ? "log" : "warn"](message);
|
|
188
|
+
}
|
|
189
|
+
return success;
|
|
190
|
+
} catch {
|
|
191
|
+
if (debug) console.warn(`${debugPrefix} Failed to send`);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
export { onSessionRotated as a, touchActivity as c, setStorageItem as d, isCookielessMode as i, getStorageItem as l, createId as n, resetSession as o, getSessionContext as r, setCookielessMode as s, sendData as t, removeStorageItem as u };
|
package/dist/error.d.ts
CHANGED
package/dist/error.js
CHANGED
|
@@ -1,2 +1,127 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
|
|
1
|
+
import { a as resolveBaseUrl, i as getPageContext, r as URLS, t as ANALYTICS_BASE } from "./chunks/api-urls-CaNa8upY.js";
|
|
2
|
+
import { r as getSessionContext, t as sendData } from "./chunks/send-data-DjdbGDDc.js";
|
|
3
|
+
import { t as getAnonymousId } from "./chunks/identifiers-cUymVK5H.js";
|
|
4
|
+
//#region src/error.ts
|
|
5
|
+
const SDK_NAME = "@faststats/web";
|
|
6
|
+
const SDK_VERSION = "0.6.0";
|
|
7
|
+
const EXTENSION_RE = /(?:^|\()(chrome|moz|ms-browser|safari-web)-extension:\/\//;
|
|
8
|
+
function toEntry(kind, source, handled, fallback) {
|
|
9
|
+
if (source instanceof Error) return {
|
|
10
|
+
error: kind,
|
|
11
|
+
message: source.message || fallback,
|
|
12
|
+
handled,
|
|
13
|
+
stack: source.stack?.split("\n").map((line) => line.trim()).filter(Boolean)
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
error: kind,
|
|
17
|
+
message: typeof source === "string" ? source : fallback,
|
|
18
|
+
handled
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function entryKey({ error, message, handled }) {
|
|
22
|
+
return `${error}\0${message ?? ""}\0${handled}`;
|
|
23
|
+
}
|
|
24
|
+
function isExtensionError(filename, source) {
|
|
25
|
+
const stack = source instanceof Error ? source.stack ?? "" : "";
|
|
26
|
+
return EXTENSION_RE.test(`${filename}\n${stack}`);
|
|
27
|
+
}
|
|
28
|
+
var ErrorTracker = class {
|
|
29
|
+
options;
|
|
30
|
+
endpoint;
|
|
31
|
+
queue = /* @__PURE__ */ new Map();
|
|
32
|
+
timer = null;
|
|
33
|
+
started = false;
|
|
34
|
+
flushing = false;
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.options = options;
|
|
37
|
+
this.endpoint = `${resolveBaseUrl(options.baseUrl, ANALYTICS_BASE)}${URLS.events}`;
|
|
38
|
+
}
|
|
39
|
+
log(...args) {
|
|
40
|
+
if (this.options.debug) console.log("[ErrorTracker]", ...args);
|
|
41
|
+
}
|
|
42
|
+
start() {
|
|
43
|
+
if (this.started || typeof window === "undefined") return;
|
|
44
|
+
this.started = true;
|
|
45
|
+
window.addEventListener("error", this.onError);
|
|
46
|
+
window.addEventListener("unhandledrejection", this.onRejection);
|
|
47
|
+
this.timer = setInterval(() => void this.flush(), this.options.flushInterval ?? 5e3);
|
|
48
|
+
this.log("Started");
|
|
49
|
+
}
|
|
50
|
+
stop() {
|
|
51
|
+
if (!this.started || typeof window === "undefined") return;
|
|
52
|
+
this.started = false;
|
|
53
|
+
window.removeEventListener("error", this.onError);
|
|
54
|
+
window.removeEventListener("unhandledrejection", this.onRejection);
|
|
55
|
+
if (this.timer) clearInterval(this.timer);
|
|
56
|
+
this.timer = null;
|
|
57
|
+
this.flush();
|
|
58
|
+
this.log("Stopped");
|
|
59
|
+
}
|
|
60
|
+
onPageHidden(persisted = false) {
|
|
61
|
+
if (persisted) return;
|
|
62
|
+
this.flush();
|
|
63
|
+
}
|
|
64
|
+
captureError(error) {
|
|
65
|
+
this.enqueue(toEntry("Error", error, true, error.message));
|
|
66
|
+
}
|
|
67
|
+
onError = (event) => {
|
|
68
|
+
if (isExtensionError(event.filename ?? "", event.error)) return;
|
|
69
|
+
this.enqueue(toEntry("Error", event.error, false, event.message || "Unknown error"));
|
|
70
|
+
};
|
|
71
|
+
onRejection = (event) => {
|
|
72
|
+
if (isExtensionError("", event.reason)) return;
|
|
73
|
+
this.enqueue(toEntry("UnhandledRejection", event.reason, false, "Unhandled promise rejection"));
|
|
74
|
+
};
|
|
75
|
+
addToQueue(entry, count = 1) {
|
|
76
|
+
const key = entryKey(entry);
|
|
77
|
+
const existing = this.queue.get(key);
|
|
78
|
+
if (existing) {
|
|
79
|
+
existing.count += count;
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
this.queue.set(key, {
|
|
83
|
+
...entry,
|
|
84
|
+
count
|
|
85
|
+
});
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
enqueue(entry) {
|
|
89
|
+
if (this.addToQueue(entry)) this.log("Captured:", entry);
|
|
90
|
+
if (this.queue.size >= (this.options.maxQueueSize ?? 50)) this.flush();
|
|
91
|
+
}
|
|
92
|
+
async flush() {
|
|
93
|
+
if (this.flushing || this.queue.size === 0) return;
|
|
94
|
+
this.flushing = true;
|
|
95
|
+
const batch = this.queue;
|
|
96
|
+
this.queue = /* @__PURE__ */ new Map();
|
|
97
|
+
const errors = [...batch.values()];
|
|
98
|
+
this.log("Flushing:", errors);
|
|
99
|
+
try {
|
|
100
|
+
const buildId = globalThis.__SOURCEMAPS_BUILD__?.buildId;
|
|
101
|
+
const userId = getAnonymousId();
|
|
102
|
+
const ctx = getSessionContext(this.options.siteKey);
|
|
103
|
+
if (!await sendData({
|
|
104
|
+
url: this.endpoint,
|
|
105
|
+
data: JSON.stringify({
|
|
106
|
+
token: this.options.siteKey,
|
|
107
|
+
...userId ? { userId } : {},
|
|
108
|
+
sessionId: ctx.sessionId,
|
|
109
|
+
windowId: ctx.windowId,
|
|
110
|
+
...typeof buildId === "string" && buildId.trim() ? { buildId } : {},
|
|
111
|
+
sdkName: this.options.sdkName ?? SDK_NAME,
|
|
112
|
+
sdkVersion: this.options.sdkVersion ?? SDK_VERSION,
|
|
113
|
+
event: "error",
|
|
114
|
+
...getPageContext(),
|
|
115
|
+
properties: {},
|
|
116
|
+
errors
|
|
117
|
+
}),
|
|
118
|
+
debug: this.options.debug,
|
|
119
|
+
debugPrefix: "[ErrorTracker]"
|
|
120
|
+
})) for (const item of batch.values()) this.addToQueue(item, item.count);
|
|
121
|
+
} finally {
|
|
122
|
+
this.flushing = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
//#endregion
|
|
127
|
+
export { ErrorTracker as default };
|
package/dist/feature-flags.js
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import { a as resolveBaseUrl, n as FEATURE_FLAGS_BASE, r as URLS } from "./chunks/api-urls-CaNa8upY.js";
|
|
2
|
+
//#region src/feature-flags.ts
|
|
3
|
+
async function fetchFeatureFlagEvaluation(flagKey, context) {
|
|
4
|
+
if (!context.projectToken) throw new Error("feature flag check requires projectToken");
|
|
5
|
+
if (!context.identifier && !context.externalId) throw new Error("feature flag check requires serverId or externalId");
|
|
6
|
+
const { baseUrl, projectToken, signal, attributes, ...bodyFields } = context;
|
|
7
|
+
const body = {
|
|
8
|
+
key: flagKey,
|
|
9
|
+
...bodyFields
|
|
10
|
+
};
|
|
11
|
+
if (attributes && Object.keys(attributes).length > 0) body.attributes = attributes;
|
|
12
|
+
const headers = {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
Authorization: `Bearer ${projectToken}`
|
|
15
|
+
};
|
|
16
|
+
const url = `${resolveBaseUrl(baseUrl, FEATURE_FLAGS_BASE)}${URLS.flags}`;
|
|
17
|
+
const res = await fetch(url, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers,
|
|
20
|
+
body: JSON.stringify(body),
|
|
21
|
+
credentials: "omit",
|
|
22
|
+
signal
|
|
23
|
+
});
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
const err = await res.json().catch(() => null);
|
|
26
|
+
const detail = typeof err?.error === "string" && err.error.length > 0 ? ` — ${err.error}` : "";
|
|
27
|
+
throw new Error(`feature flag check failed: HTTP ${res.status}${detail}`);
|
|
28
|
+
}
|
|
29
|
+
return await res.json();
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { fetchFeatureFlagEvaluation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FeatureFlagEvaluation } from "./feature-flags.js";
|
|
2
|
-
import { n as ReplayTrackerOptions } from "./chunks/replay-
|
|
2
|
+
import { n as ReplayTrackerOptions } from "./chunks/replay-DgodPHzA.js";
|
|
3
3
|
|
|
4
4
|
//#region src/analytics.d.ts
|
|
5
5
|
type ConsentMode = "pending" | "granted" | "denied";
|
|
@@ -58,8 +58,9 @@ declare class WebAnalytics {
|
|
|
58
58
|
private pageKey;
|
|
59
59
|
private entry;
|
|
60
60
|
private left;
|
|
61
|
-
private
|
|
62
|
-
private
|
|
61
|
+
private visitDuration;
|
|
62
|
+
private visitStartedAt;
|
|
63
|
+
private pendingPageviewTrigger;
|
|
63
64
|
private consentMode;
|
|
64
65
|
private readonly pendingBehavior;
|
|
65
66
|
private readonly cleanup;
|
|
@@ -74,8 +75,10 @@ declare class WebAnalytics {
|
|
|
74
75
|
private cookieless;
|
|
75
76
|
private touch;
|
|
76
77
|
private bind;
|
|
78
|
+
private stopHeartbeat;
|
|
77
79
|
private loadChild;
|
|
78
80
|
private loadOptionalTrackers;
|
|
81
|
+
private enterPage;
|
|
79
82
|
private beginTracking;
|
|
80
83
|
private readonly onLinkClick;
|
|
81
84
|
private readonly onVisibilityChange;
|
|
@@ -99,6 +102,9 @@ declare class WebAnalytics {
|
|
|
99
102
|
reportError(error: Error): void;
|
|
100
103
|
private send;
|
|
101
104
|
private leavePage;
|
|
105
|
+
private startVisit;
|
|
106
|
+
private pauseVisit;
|
|
107
|
+
private resumeVisit;
|
|
102
108
|
private startHeartbeat;
|
|
103
109
|
private navigate;
|
|
104
110
|
}
|