featurely-site-manager 1.1.6 → 1.1.9
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/index.js +25 -21
- package/dist/index.mjs +25 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -383,30 +383,30 @@ var _SiteManager = class _SiteManager {
|
|
|
383
383
|
if (this.analyticsQueue.length === 0) {
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
386
|
+
const url = `${this.config.apiUrl}/api/projects/${this.config.projectId}/analytics/events`;
|
|
386
387
|
const eventsToSend = [...this.analyticsQueue];
|
|
387
388
|
this.analyticsQueue = [];
|
|
388
389
|
for (const event of eventsToSend) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
390
|
+
const payload = JSON.stringify({
|
|
391
|
+
eventName: event.eventName,
|
|
392
|
+
properties: event.properties,
|
|
393
|
+
userId: this.config.userId,
|
|
394
|
+
sessionId: this.sessionId,
|
|
395
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
396
|
+
platform: typeof navigator !== "undefined" ? navigator.platform : void 0,
|
|
397
|
+
appVersion: this.config.appVersion
|
|
398
|
+
});
|
|
399
|
+
const sentViaBeacon = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(url, payload);
|
|
400
|
+
if (!sentViaBeacon) {
|
|
401
|
+
try {
|
|
402
|
+
await fetch(url, {
|
|
393
403
|
method: "POST",
|
|
394
|
-
headers: {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
userId: this.config.userId,
|
|
401
|
-
sessionId: this.sessionId,
|
|
402
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
403
|
-
platform: typeof navigator !== "undefined" ? navigator.platform : void 0,
|
|
404
|
-
appVersion: this.config.appVersion
|
|
405
|
-
})
|
|
406
|
-
}
|
|
407
|
-
);
|
|
408
|
-
} catch (error) {
|
|
409
|
-
console.error("Failed to send analytics event:", error);
|
|
404
|
+
headers: { "Content-Type": "application/json" },
|
|
405
|
+
body: payload
|
|
406
|
+
});
|
|
407
|
+
} catch (error) {
|
|
408
|
+
console.error("Failed to send analytics event:", error);
|
|
409
|
+
}
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
412
|
}
|
|
@@ -423,6 +423,7 @@ var _SiteManager = class _SiteManager {
|
|
|
423
423
|
this.currentPagePath = window.location.pathname;
|
|
424
424
|
this.pageEntryTime = Date.now();
|
|
425
425
|
this.trackPageView();
|
|
426
|
+
setTimeout(() => this.flushAnalytics(), 2e3);
|
|
426
427
|
const originalPushState = history.pushState.bind(history);
|
|
427
428
|
const originalReplaceState = history.replaceState.bind(history);
|
|
428
429
|
const self = this;
|
|
@@ -476,7 +477,10 @@ var _SiteManager = class _SiteManager {
|
|
|
476
477
|
}
|
|
477
478
|
this.currentPagePath = newPath;
|
|
478
479
|
this.pageEntryTime = Date.now();
|
|
479
|
-
setTimeout(() =>
|
|
480
|
+
setTimeout(() => {
|
|
481
|
+
this.trackPageView();
|
|
482
|
+
this.flushAnalytics();
|
|
483
|
+
}, 100);
|
|
480
484
|
}
|
|
481
485
|
generateSessionId() {
|
|
482
486
|
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
package/dist/index.mjs
CHANGED
|
@@ -348,30 +348,30 @@ var _SiteManager = class _SiteManager {
|
|
|
348
348
|
if (this.analyticsQueue.length === 0) {
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
351
|
+
const url = `${this.config.apiUrl}/api/projects/${this.config.projectId}/analytics/events`;
|
|
351
352
|
const eventsToSend = [...this.analyticsQueue];
|
|
352
353
|
this.analyticsQueue = [];
|
|
353
354
|
for (const event of eventsToSend) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
const payload = JSON.stringify({
|
|
356
|
+
eventName: event.eventName,
|
|
357
|
+
properties: event.properties,
|
|
358
|
+
userId: this.config.userId,
|
|
359
|
+
sessionId: this.sessionId,
|
|
360
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
361
|
+
platform: typeof navigator !== "undefined" ? navigator.platform : void 0,
|
|
362
|
+
appVersion: this.config.appVersion
|
|
363
|
+
});
|
|
364
|
+
const sentViaBeacon = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(url, payload);
|
|
365
|
+
if (!sentViaBeacon) {
|
|
366
|
+
try {
|
|
367
|
+
await fetch(url, {
|
|
358
368
|
method: "POST",
|
|
359
|
-
headers: {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
userId: this.config.userId,
|
|
366
|
-
sessionId: this.sessionId,
|
|
367
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
368
|
-
platform: typeof navigator !== "undefined" ? navigator.platform : void 0,
|
|
369
|
-
appVersion: this.config.appVersion
|
|
370
|
-
})
|
|
371
|
-
}
|
|
372
|
-
);
|
|
373
|
-
} catch (error) {
|
|
374
|
-
console.error("Failed to send analytics event:", error);
|
|
369
|
+
headers: { "Content-Type": "application/json" },
|
|
370
|
+
body: payload
|
|
371
|
+
});
|
|
372
|
+
} catch (error) {
|
|
373
|
+
console.error("Failed to send analytics event:", error);
|
|
374
|
+
}
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
}
|
|
@@ -388,6 +388,7 @@ var _SiteManager = class _SiteManager {
|
|
|
388
388
|
this.currentPagePath = window.location.pathname;
|
|
389
389
|
this.pageEntryTime = Date.now();
|
|
390
390
|
this.trackPageView();
|
|
391
|
+
setTimeout(() => this.flushAnalytics(), 2e3);
|
|
391
392
|
const originalPushState = history.pushState.bind(history);
|
|
392
393
|
const originalReplaceState = history.replaceState.bind(history);
|
|
393
394
|
const self = this;
|
|
@@ -441,7 +442,10 @@ var _SiteManager = class _SiteManager {
|
|
|
441
442
|
}
|
|
442
443
|
this.currentPagePath = newPath;
|
|
443
444
|
this.pageEntryTime = Date.now();
|
|
444
|
-
setTimeout(() =>
|
|
445
|
+
setTimeout(() => {
|
|
446
|
+
this.trackPageView();
|
|
447
|
+
this.flushAnalytics();
|
|
448
|
+
}, 100);
|
|
445
449
|
}
|
|
446
450
|
generateSessionId() {
|
|
447
451
|
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "featurely-site-manager",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Complete site management SDK for maintenance mode, status messages, feature flags, version checking, and analytics",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|