featurely-site-manager 1.1.8 → 1.1.10

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 CHANGED
@@ -383,30 +383,35 @@ 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) {
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
+ });
389
399
  try {
390
- await fetch(
391
- `${this.config.apiUrl}/api/projects/${this.config.projectId}/analytics/events`,
392
- {
393
- method: "POST",
394
- headers: {
395
- "Content-Type": "application/json"
396
- },
397
- body: JSON.stringify({
398
- eventName: event.eventName,
399
- properties: event.properties,
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);
400
+ const res = await fetch(url, {
401
+ method: "POST",
402
+ headers: { "Content-Type": "application/json" },
403
+ body: payload,
404
+ keepalive: true
405
+ });
406
+ if (!res.ok) {
407
+ const body = await res.text().catch(() => "(unreadable)");
408
+ console.error(`[Featurely] Analytics event "${event.eventName}" rejected by server: ${res.status} ${res.statusText} \u2014 ${body}`);
409
+ }
410
+ } catch (fetchError) {
411
+ const sentViaBeacon = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(url, payload);
412
+ if (!sentViaBeacon) {
413
+ console.error(`[Featurely] Failed to send analytics event "${event.eventName}":`, fetchError);
414
+ }
410
415
  }
411
416
  }
412
417
  }
package/dist/index.mjs CHANGED
@@ -348,30 +348,35 @@ 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) {
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
+ });
354
364
  try {
355
- await fetch(
356
- `${this.config.apiUrl}/api/projects/${this.config.projectId}/analytics/events`,
357
- {
358
- method: "POST",
359
- headers: {
360
- "Content-Type": "application/json"
361
- },
362
- body: JSON.stringify({
363
- eventName: event.eventName,
364
- properties: event.properties,
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);
365
+ const res = await fetch(url, {
366
+ method: "POST",
367
+ headers: { "Content-Type": "application/json" },
368
+ body: payload,
369
+ keepalive: true
370
+ });
371
+ if (!res.ok) {
372
+ const body = await res.text().catch(() => "(unreadable)");
373
+ console.error(`[Featurely] Analytics event "${event.eventName}" rejected by server: ${res.status} ${res.statusText} \u2014 ${body}`);
374
+ }
375
+ } catch (fetchError) {
376
+ const sentViaBeacon = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(url, payload);
377
+ if (!sentViaBeacon) {
378
+ console.error(`[Featurely] Failed to send analytics event "${event.eventName}":`, fetchError);
379
+ }
375
380
  }
376
381
  }
377
382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "featurely-site-manager",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
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",