@faststats/web 0.4.2 → 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-DLpWrsx1.d.ts → replay-DgodPHzA.d.ts} +20 -4
- 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 +12 -9
- package/dist/index.js +444 -1
- package/dist/replay.d.ts +1 -1
- package/dist/replay.js +506 -1
- package/dist/web-vitals.d.ts +3 -3
- package/dist/web-vitals.js +115 -1
- package/package.json +5 -4
- package/dist/chunks/api-urls-Bh77rElT.js +0 -1
- package/dist/chunks/identifiers-uytEhnH9.js +0 -1
- package/dist/chunks/send-data-Cc1nxIlg.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1,444 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import { a as resolveBaseUrl, i as getPageContext, n as FEATURE_FLAGS_BASE, o as sanitizeUrl, r as URLS, t as ANALYTICS_BASE } from "./chunks/api-urls-CaNa8upY.js";
|
|
2
|
+
import { c as touchActivity, l as getStorageItem, o as resetSession, r as getSessionContext, s as setCookielessMode, t as sendData } from "./chunks/send-data-DjdbGDDc.js";
|
|
3
|
+
import { n as resetAnonymousId, t as getAnonymousId } from "./chunks/identifiers-cUymVK5H.js";
|
|
4
|
+
//#region src/outbound-links.ts
|
|
5
|
+
const DEDUPE_MS = 500;
|
|
6
|
+
var OutboundLinkTracker = class {
|
|
7
|
+
lastActivation = null;
|
|
8
|
+
getHref(event) {
|
|
9
|
+
if (!(event instanceof MouseEvent) || !isEligibleActivation(event)) return null;
|
|
10
|
+
const anchor = findOutboundAnchor(event);
|
|
11
|
+
if (!anchor || this.isDuplicate(event, anchor.href)) return null;
|
|
12
|
+
return anchor.href;
|
|
13
|
+
}
|
|
14
|
+
isDuplicate(event, href) {
|
|
15
|
+
const activation = {
|
|
16
|
+
button: event.button,
|
|
17
|
+
href,
|
|
18
|
+
clientX: event.clientX,
|
|
19
|
+
clientY: event.clientY,
|
|
20
|
+
at: Date.now()
|
|
21
|
+
};
|
|
22
|
+
const previous = this.lastActivation;
|
|
23
|
+
this.lastActivation = activation;
|
|
24
|
+
return !!(previous && previous.href === activation.href && previous.button === activation.button && previous.clientX === activation.clientX && previous.clientY === activation.clientY && activation.at - previous.at <= DEDUPE_MS);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function isEligibleActivation(event) {
|
|
28
|
+
if (event.defaultPrevented) return false;
|
|
29
|
+
if (event.type === "click") return event.button === 0;
|
|
30
|
+
if (event.type === "auxclick") return event.button === 1;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function findOutboundAnchor(event) {
|
|
34
|
+
for (const node of event.composedPath()) if (isOutboundAnchor(node)) return node;
|
|
35
|
+
let node = event.target;
|
|
36
|
+
while (node) {
|
|
37
|
+
if (isOutboundAnchor(node)) return node;
|
|
38
|
+
node = node.parentNode;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function isOutboundAnchor(node) {
|
|
43
|
+
return node instanceof HTMLAnchorElement && !!node.href && node.host !== location.host;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/analytics.ts
|
|
47
|
+
let instance = null;
|
|
48
|
+
let pendingConsentMode;
|
|
49
|
+
function getInstance() {
|
|
50
|
+
return instance;
|
|
51
|
+
}
|
|
52
|
+
function activeInstance() {
|
|
53
|
+
if (typeof window === "undefined" || isTrackingDisabled()) return null;
|
|
54
|
+
return instance;
|
|
55
|
+
}
|
|
56
|
+
function trackEvent(eventName, properties) {
|
|
57
|
+
activeInstance()?.track(eventName, properties);
|
|
58
|
+
}
|
|
59
|
+
async function identify(externalId, email, options) {
|
|
60
|
+
return activeInstance()?.identify(externalId, email, options) ?? false;
|
|
61
|
+
}
|
|
62
|
+
function logout(resetAnonymousIdentity = true) {
|
|
63
|
+
activeInstance()?.logout(resetAnonymousIdentity);
|
|
64
|
+
}
|
|
65
|
+
function setConsentMode(mode) {
|
|
66
|
+
if (instance) instance.setConsentMode(mode);
|
|
67
|
+
else pendingConsentMode = mode;
|
|
68
|
+
}
|
|
69
|
+
function optIn() {
|
|
70
|
+
setConsentMode("granted");
|
|
71
|
+
}
|
|
72
|
+
function optOut() {
|
|
73
|
+
setConsentMode("denied");
|
|
74
|
+
}
|
|
75
|
+
function reportError(error) {
|
|
76
|
+
activeInstance()?.reportError(error);
|
|
77
|
+
}
|
|
78
|
+
function isTrackingDisabled() {
|
|
79
|
+
const value = getStorageItem("localStorage", "disable-faststats");
|
|
80
|
+
return value === "true" || value === "1";
|
|
81
|
+
}
|
|
82
|
+
var WebAnalytics = class {
|
|
83
|
+
options;
|
|
84
|
+
baseUrl;
|
|
85
|
+
debug;
|
|
86
|
+
started = false;
|
|
87
|
+
destroyed = false;
|
|
88
|
+
epoch = 0;
|
|
89
|
+
heartbeatTimer = null;
|
|
90
|
+
pageKey = "";
|
|
91
|
+
entry = {
|
|
92
|
+
path: "",
|
|
93
|
+
url: "",
|
|
94
|
+
hash: ""
|
|
95
|
+
};
|
|
96
|
+
left = false;
|
|
97
|
+
visitDuration = 0;
|
|
98
|
+
visitStartedAt = null;
|
|
99
|
+
pendingPageviewTrigger = null;
|
|
100
|
+
consentMode;
|
|
101
|
+
pendingBehavior;
|
|
102
|
+
cleanup = [];
|
|
103
|
+
childTrackers = [];
|
|
104
|
+
outboundLinks = new OutboundLinkTracker();
|
|
105
|
+
constructor(options) {
|
|
106
|
+
this.options = options;
|
|
107
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl, ANALYTICS_BASE);
|
|
108
|
+
this.debug = options.debug ?? false;
|
|
109
|
+
this.consentMode = pendingConsentMode ?? options.consent?.mode ?? "granted";
|
|
110
|
+
pendingConsentMode = void 0;
|
|
111
|
+
this.pendingBehavior = options.consent?.pendingBehavior ?? "anonymous";
|
|
112
|
+
if (options.autoTrack ?? true) {
|
|
113
|
+
if (typeof window === "undefined") return;
|
|
114
|
+
if (isTrackingDisabled()) {
|
|
115
|
+
this.log("disabled");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
setTimeout(() => void this.start(), 0);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
log(msg) {
|
|
122
|
+
if (this.debug) console.log(`[Analytics] ${msg}`);
|
|
123
|
+
}
|
|
124
|
+
isTrackingBlocked() {
|
|
125
|
+
return typeof window === "undefined" || this.destroyed || isTrackingDisabled();
|
|
126
|
+
}
|
|
127
|
+
ensureActive() {
|
|
128
|
+
if (this.isTrackingBlocked()) return false;
|
|
129
|
+
if (!this.started) this.start();
|
|
130
|
+
return this.started && !this.destroyed && instance === this;
|
|
131
|
+
}
|
|
132
|
+
canTrack() {
|
|
133
|
+
return !(this.consentMode === "pending" && this.pendingBehavior === "disabled");
|
|
134
|
+
}
|
|
135
|
+
canSendEvents() {
|
|
136
|
+
return !this.isTrackingBlocked() && this.canTrack();
|
|
137
|
+
}
|
|
138
|
+
cookieless() {
|
|
139
|
+
return !!this.options.cookieless || this.consentMode === "denied" || this.consentMode === "pending" && this.pendingBehavior === "anonymous";
|
|
140
|
+
}
|
|
141
|
+
touch() {
|
|
142
|
+
if (this.canTrack()) touchActivity(this.options.siteKey, this.cookieless());
|
|
143
|
+
}
|
|
144
|
+
bind(target, type, listener, options) {
|
|
145
|
+
target.addEventListener(type, listener, options);
|
|
146
|
+
this.cleanup.push(() => target.removeEventListener(type, listener, options));
|
|
147
|
+
}
|
|
148
|
+
stopHeartbeat() {
|
|
149
|
+
if (!this.heartbeatTimer) return;
|
|
150
|
+
clearInterval(this.heartbeatTimer);
|
|
151
|
+
this.heartbeatTimer = null;
|
|
152
|
+
}
|
|
153
|
+
loadChild(name, create) {
|
|
154
|
+
const epoch = this.epoch;
|
|
155
|
+
create().then(async (tracker) => {
|
|
156
|
+
if (this.epoch !== epoch || !this.started) return tracker.stop?.();
|
|
157
|
+
await tracker.start();
|
|
158
|
+
if (this.epoch !== epoch || !this.started) return tracker.stop?.();
|
|
159
|
+
this.childTrackers.push(tracker);
|
|
160
|
+
this.log(`${name} loaded`);
|
|
161
|
+
}).catch((error) => this.log(`failed to initialize ${name} tracker: ${String(error)}`));
|
|
162
|
+
}
|
|
163
|
+
loadOptionalTrackers() {
|
|
164
|
+
const o = this.options;
|
|
165
|
+
const base = {
|
|
166
|
+
siteKey: o.siteKey,
|
|
167
|
+
baseUrl: this.baseUrl,
|
|
168
|
+
debug: this.debug
|
|
169
|
+
};
|
|
170
|
+
if (o.sessionReplays?.enabled) this.loadChild("replay", async () => {
|
|
171
|
+
const { default: ReplayTracker } = await import("./replay.js");
|
|
172
|
+
return new ReplayTracker({
|
|
173
|
+
...base,
|
|
174
|
+
...o.replayOptions
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
if (o.errorTracking?.enabled) this.loadChild("error", async () => {
|
|
178
|
+
const { default: ErrorTracker } = await import("./error.js");
|
|
179
|
+
return new ErrorTracker({
|
|
180
|
+
...base,
|
|
181
|
+
sdkName: o.sdkName,
|
|
182
|
+
sdkVersion: o.sdkVersion
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
if (o.webVitals?.enabled) this.loadChild("web-vitals", async () => {
|
|
186
|
+
const { default: WebVitalsTracker } = await import("./web-vitals.js");
|
|
187
|
+
return new WebVitalsTracker({
|
|
188
|
+
...base,
|
|
189
|
+
attribution: o.webVitals?.attribution ?? false
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
enterPage() {
|
|
194
|
+
this.entry = {
|
|
195
|
+
path: location.pathname,
|
|
196
|
+
url: sanitizeUrl(location.href),
|
|
197
|
+
hash: location.hash
|
|
198
|
+
};
|
|
199
|
+
this.left = false;
|
|
200
|
+
this.startVisit();
|
|
201
|
+
}
|
|
202
|
+
beginTracking(trigger) {
|
|
203
|
+
this.touch();
|
|
204
|
+
this.loadOptionalTrackers();
|
|
205
|
+
this.enterPage();
|
|
206
|
+
this.pageKey = "";
|
|
207
|
+
if (document.visibilityState === "visible") {
|
|
208
|
+
this.pageview({ trigger });
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.pendingPageviewTrigger = trigger;
|
|
212
|
+
}
|
|
213
|
+
onLinkClick = (event) => {
|
|
214
|
+
const href = this.outboundLinks.getHref(event);
|
|
215
|
+
if (href) this.track("outbound_link", { outbound_link: sanitizeUrl(href) });
|
|
216
|
+
};
|
|
217
|
+
onVisibilityChange = () => {
|
|
218
|
+
this.touch();
|
|
219
|
+
if (document.visibilityState === "hidden") {
|
|
220
|
+
this.pauseVisit();
|
|
221
|
+
for (const tracker of this.childTrackers) tracker.onPageHidden?.();
|
|
222
|
+
this.stopHeartbeat();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
this.startHeartbeat();
|
|
226
|
+
this.resumeVisit();
|
|
227
|
+
const trigger = this.pendingPageviewTrigger;
|
|
228
|
+
this.pendingPageviewTrigger = null;
|
|
229
|
+
if (trigger) this.pageview({ trigger });
|
|
230
|
+
};
|
|
231
|
+
onPageHide = (event) => {
|
|
232
|
+
const persisted = event.persisted;
|
|
233
|
+
this.pauseVisit();
|
|
234
|
+
for (const tracker of this.childTrackers) tracker.onPageHidden?.(persisted);
|
|
235
|
+
if (!persisted) this.leavePage();
|
|
236
|
+
};
|
|
237
|
+
onPageShow = (event) => {
|
|
238
|
+
if (document.visibilityState === "visible") this.resumeVisit();
|
|
239
|
+
for (const tracker of this.childTrackers) tracker.onPageShow?.(event.persisted);
|
|
240
|
+
};
|
|
241
|
+
async start() {
|
|
242
|
+
if (this.started) return;
|
|
243
|
+
if (this.isTrackingBlocked()) {
|
|
244
|
+
if (isTrackingDisabled()) this.log("disabled");
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (instance && instance !== this) {
|
|
248
|
+
this.log("already started by another instance");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.started = true;
|
|
252
|
+
instance = this;
|
|
253
|
+
setCookielessMode(this.cookieless());
|
|
254
|
+
this.bind(document, "click", this.onLinkClick, true);
|
|
255
|
+
this.bind(document, "auxclick", this.onLinkClick, true);
|
|
256
|
+
this.bind(document, "visibilitychange", this.onVisibilityChange);
|
|
257
|
+
this.bind(window, "pagehide", this.onPageHide);
|
|
258
|
+
this.bind(window, "pageshow", this.onPageShow);
|
|
259
|
+
this.bind(window, "popstate", () => this.navigate());
|
|
260
|
+
if (this.options.trackHash ?? false) this.bind(window, "hashchange", () => this.navigate());
|
|
261
|
+
for (const method of ["pushState", "replaceState"]) {
|
|
262
|
+
const original = history[method];
|
|
263
|
+
const wrapped = (data, unused, url) => {
|
|
264
|
+
Reflect.apply(original, history, [
|
|
265
|
+
data,
|
|
266
|
+
unused,
|
|
267
|
+
url
|
|
268
|
+
]);
|
|
269
|
+
this.navigate();
|
|
270
|
+
};
|
|
271
|
+
history[method] = wrapped;
|
|
272
|
+
this.cleanup.push(() => {
|
|
273
|
+
if (history[method] === wrapped) history[method] = original;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
this.startHeartbeat();
|
|
277
|
+
if (this.canTrack()) this.beginTracking("load");
|
|
278
|
+
}
|
|
279
|
+
destroy() {
|
|
280
|
+
if (this.destroyed) return;
|
|
281
|
+
this.epoch++;
|
|
282
|
+
if (this.started && typeof window !== "undefined") this.leavePage();
|
|
283
|
+
this.pendingPageviewTrigger = null;
|
|
284
|
+
this.stopHeartbeat();
|
|
285
|
+
for (const fn of this.cleanup.splice(0)) fn();
|
|
286
|
+
for (const tracker of this.childTrackers.splice(0)) tracker.stop?.();
|
|
287
|
+
if (instance === this) instance = null;
|
|
288
|
+
this.started = false;
|
|
289
|
+
this.destroyed = true;
|
|
290
|
+
}
|
|
291
|
+
pageview(extra = {}) {
|
|
292
|
+
if (!this.ensureActive()) return;
|
|
293
|
+
const trackHash = this.options.trackHash ?? false;
|
|
294
|
+
const key = `${location.pathname}|${trackHash ? location.hash : ""}`;
|
|
295
|
+
if (key === this.pageKey) return;
|
|
296
|
+
this.pageKey = key;
|
|
297
|
+
this.send("pageview", extra);
|
|
298
|
+
}
|
|
299
|
+
track(name, extra = {}) {
|
|
300
|
+
if (!this.ensureActive()) return;
|
|
301
|
+
const eventName = name.trim();
|
|
302
|
+
if (!eventName) return;
|
|
303
|
+
this.send(eventName, extra);
|
|
304
|
+
}
|
|
305
|
+
async identify(externalId, email, options = {}) {
|
|
306
|
+
if (!this.ensureActive() || !this.canTrack() || this.cookieless()) return false;
|
|
307
|
+
const trimmedExternalId = externalId.trim();
|
|
308
|
+
const trimmedEmail = email.trim();
|
|
309
|
+
if (!trimmedExternalId || !trimmedEmail) return false;
|
|
310
|
+
return sendData({
|
|
311
|
+
url: `${this.baseUrl}${URLS.identify}`,
|
|
312
|
+
data: JSON.stringify({
|
|
313
|
+
token: this.options.siteKey,
|
|
314
|
+
identifier: this.getAnonymousId(),
|
|
315
|
+
externalId: trimmedExternalId,
|
|
316
|
+
email: trimmedEmail,
|
|
317
|
+
name: options.name?.trim() || void 0,
|
|
318
|
+
phone: options.phone?.trim() || void 0,
|
|
319
|
+
avatarUrl: options.avatarUrl?.trim() || void 0,
|
|
320
|
+
traits: options.traits ?? {}
|
|
321
|
+
}),
|
|
322
|
+
contentType: "text/plain",
|
|
323
|
+
debug: this.debug,
|
|
324
|
+
debugPrefix: "[Analytics] identify",
|
|
325
|
+
useBeacon: false
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
logout(resetAnonymousIdentity = true) {
|
|
329
|
+
if (!this.ensureActive()) return;
|
|
330
|
+
if (resetAnonymousIdentity) resetAnonymousId(this.cookieless());
|
|
331
|
+
resetSession(this.options.siteKey);
|
|
332
|
+
}
|
|
333
|
+
setConsentMode(mode) {
|
|
334
|
+
const wasBlocked = !this.canTrack();
|
|
335
|
+
this.consentMode = mode;
|
|
336
|
+
const cookieless = this.cookieless();
|
|
337
|
+
setCookielessMode(cookieless);
|
|
338
|
+
for (const tracker of this.childTrackers) tracker.setCookielessMode?.(cookieless);
|
|
339
|
+
if (wasBlocked && this.canTrack() && this.started) this.beginTracking("consent");
|
|
340
|
+
}
|
|
341
|
+
getConsentMode() {
|
|
342
|
+
return this.consentMode;
|
|
343
|
+
}
|
|
344
|
+
getAnonymousId() {
|
|
345
|
+
if (!this.canTrack()) return "";
|
|
346
|
+
return getAnonymousId(this.cookieless());
|
|
347
|
+
}
|
|
348
|
+
getSessionId() {
|
|
349
|
+
return getSessionContext(this.options.siteKey, this.cookieless()).sessionId;
|
|
350
|
+
}
|
|
351
|
+
getWindowId() {
|
|
352
|
+
return getSessionContext(this.options.siteKey, this.cookieless()).windowId;
|
|
353
|
+
}
|
|
354
|
+
async checkFeatureFlag(key, attributes, opts) {
|
|
355
|
+
if (typeof window === "undefined" || isTrackingDisabled() || !this.canTrack()) return { value: "false" };
|
|
356
|
+
const externalId = opts?.externalId?.trim();
|
|
357
|
+
const identifier = this.getAnonymousId();
|
|
358
|
+
if (!externalId && !identifier) return { value: "false" };
|
|
359
|
+
const { fetchFeatureFlagEvaluation } = await import("./feature-flags.js");
|
|
360
|
+
return fetchFeatureFlagEvaluation(key, {
|
|
361
|
+
baseUrl: resolveBaseUrl(this.options.featureFlagsBaseUrl, FEATURE_FLAGS_BASE),
|
|
362
|
+
projectToken: this.options.siteKey,
|
|
363
|
+
...identifier ? { identifier } : {},
|
|
364
|
+
...externalId ? { externalId } : {},
|
|
365
|
+
sessionId: this.getSessionId(),
|
|
366
|
+
attributes,
|
|
367
|
+
signal: opts?.signal
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
reportError(error) {
|
|
371
|
+
if (!this.ensureActive() || !this.options.errorTracking?.enabled || !this.canTrack()) return;
|
|
372
|
+
this.childTrackers.find((tracker) => tracker.captureError)?.captureError?.(error);
|
|
373
|
+
}
|
|
374
|
+
send(event, properties = {}, dims = {}) {
|
|
375
|
+
if (!this.canSendEvents()) return;
|
|
376
|
+
const cookieless = this.cookieless();
|
|
377
|
+
const id = getAnonymousId(cookieless);
|
|
378
|
+
const ctx = getSessionContext(this.options.siteKey, cookieless);
|
|
379
|
+
this.log(event);
|
|
380
|
+
sendData({
|
|
381
|
+
url: `${this.baseUrl}${URLS.events}`,
|
|
382
|
+
data: JSON.stringify({
|
|
383
|
+
token: this.options.siteKey,
|
|
384
|
+
...id ? { userId: id } : {},
|
|
385
|
+
sessionId: ctx.sessionId,
|
|
386
|
+
windowId: ctx.windowId,
|
|
387
|
+
event,
|
|
388
|
+
...getPageContext(),
|
|
389
|
+
...dims,
|
|
390
|
+
properties
|
|
391
|
+
}),
|
|
392
|
+
contentType: "text/plain",
|
|
393
|
+
debug: this.debug,
|
|
394
|
+
debugPrefix: `[Analytics] ${event}`
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
leavePage() {
|
|
398
|
+
if (this.destroyed || this.left) return;
|
|
399
|
+
this.pauseVisit();
|
|
400
|
+
this.left = true;
|
|
401
|
+
const ctx = getSessionContext(this.options.siteKey, this.cookieless());
|
|
402
|
+
this.send("page_leave", {
|
|
403
|
+
time_on_page: this.visitDuration,
|
|
404
|
+
session_duration: Date.now() - ctx.sessionStart
|
|
405
|
+
}, {
|
|
406
|
+
page: this.entry.path,
|
|
407
|
+
url: this.entry.url
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
startVisit() {
|
|
411
|
+
this.visitDuration = 0;
|
|
412
|
+
this.visitStartedAt = document.visibilityState === "visible" ? Date.now() : null;
|
|
413
|
+
}
|
|
414
|
+
pauseVisit() {
|
|
415
|
+
if (this.visitStartedAt === null) return;
|
|
416
|
+
this.visitDuration += Math.max(0, Date.now() - this.visitStartedAt);
|
|
417
|
+
this.visitStartedAt = null;
|
|
418
|
+
}
|
|
419
|
+
resumeVisit() {
|
|
420
|
+
if (this.left || this.visitStartedAt !== null) return;
|
|
421
|
+
this.visitStartedAt = Date.now();
|
|
422
|
+
}
|
|
423
|
+
startHeartbeat() {
|
|
424
|
+
this.stopHeartbeat();
|
|
425
|
+
this.heartbeatTimer = setInterval(() => {
|
|
426
|
+
if (document.visibilityState === "hidden") {
|
|
427
|
+
this.stopHeartbeat();
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
this.touch();
|
|
431
|
+
}, 300 * 1e3);
|
|
432
|
+
}
|
|
433
|
+
navigate() {
|
|
434
|
+
if (!this.started || this.destroyed) return;
|
|
435
|
+
const trackHash = this.options.trackHash ?? false;
|
|
436
|
+
if (location.pathname === this.entry.path && (!trackHash || location.hash === this.entry.hash)) return;
|
|
437
|
+
for (const tracker of this.childTrackers) tracker.trackPageChange?.(sanitizeUrl(location.href));
|
|
438
|
+
this.leavePage();
|
|
439
|
+
this.enterPage();
|
|
440
|
+
this.pageview({ trigger: "navigation" });
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
//#endregion
|
|
444
|
+
export { WebAnalytics, getInstance, identify, isTrackingDisabled, logout, optIn, optOut, reportError, setConsentMode, trackEvent };
|
package/dist/replay.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as ReplayTrackerOptions, t as ReplayTracker } from "./chunks/replay-
|
|
1
|
+
import { n as ReplayTrackerOptions, t as ReplayTracker } from "./chunks/replay-DgodPHzA.js";
|
|
2
2
|
export { ReplayTrackerOptions, ReplayTracker as default };
|