@magicfeedback/popup-sdk 1.12.0 → 1.13.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/index.mjs CHANGED
@@ -1447,6 +1447,23 @@ var NavigationObserver = class {
1447
1447
  if (!this.installed || this.currentScreen != null || typeof window === "undefined") return;
1448
1448
  this.begin(window.location.href);
1449
1449
  }
1450
+ /**
1451
+ * La pantalla en curso, sin cerrarla ni emitir nada; null si no hay (antes de `begin`, tras
1452
+ * `stop`/`discard`). Para que el `user_engagement` lleve la pantalla: si el cierre de la
1453
+ * sesión no llega nunca (pestaña dormida y descartada, app matada), la última pantalla no
1454
+ * tiene `page_view` y solo queda esto.
1455
+ */
1456
+ current() {
1457
+ if (this.currentScreen == null) return null;
1458
+ return {
1459
+ screen: this.currentScreen,
1460
+ path: this.currentPath ?? this.currentScreen,
1461
+ seconds: this.secondsSinceEntry(this.now())
1462
+ };
1463
+ }
1464
+ secondsSinceEntry(at) {
1465
+ return Math.max(0, Math.round((at - this.entryAt) / 1e3));
1466
+ }
1450
1467
  closeCurrent() {
1451
1468
  if (this.currentScreen == null) return;
1452
1469
  const exit = this.now();
@@ -1455,7 +1472,7 @@ var NavigationObserver = class {
1455
1472
  path: this.currentPath ?? this.currentScreen,
1456
1473
  entry: this.entryAt,
1457
1474
  exit,
1458
- durationSeconds: Math.max(0, Math.round((exit - this.entryAt) / 1e3))
1475
+ durationSeconds: this.secondsSinceEntry(exit)
1459
1476
  };
1460
1477
  this.listeners.forEach((l) => {
1461
1478
  try {
@@ -2472,12 +2489,29 @@ var DeepdotsPopups = class {
2472
2489
  if (!this.tracking?.isTrackingEnabled()) return;
2473
2490
  this.analytics?.flush(this.analyticsIdentity(), options);
2474
2491
  }
2475
- /** Emite un evento `user_engagement` con el tiempo activo acumulado (#8). */
2492
+ /**
2493
+ * Emite un evento `user_engagement` con el tiempo activo acumulado (#8) y la pantalla en
2494
+ * curso: `screen` y `path` (los mismos que llevará su `page_view`) y `screen_seconds` (lo
2495
+ * que lleva en ella, medido como el `duration_seconds` del `page_view`).
2496
+ *
2497
+ * El `page_view` sale al SALIR de la pantalla; si el cierre no llega nunca (pestaña dormida
2498
+ * y descartada al volver, pestaña o app matada en segundo plano), la última pantalla de la
2499
+ * sesión se perdía y una visita de una sola pantalla se quedaba sin ninguna. Con la pantalla
2500
+ * en el latido y en el engagement de ocultar la pestaña, el backend la reconstruye.
2501
+ *
2502
+ * En los cierres (`closeSession`, `suspendSession`) el observador ya emitió el `page_view`
2503
+ * y no tiene pantalla, así que ese engagement va sin `screen`: nunca se cuenta dos veces.
2504
+ * Tampoco se emite un `page_view` aquí, por lo mismo.
2505
+ */
2476
2506
  flushEngagement() {
2477
2507
  if (!this.tracking?.isTrackingEnabled()) return;
2478
2508
  const ms = this.engagement?.consume() ?? 0;
2479
2509
  if (ms > 0) {
2480
- this.track("deepdots_user_engagement", { engagement_time_msec: ms });
2510
+ const current = this.navObserver?.current();
2511
+ this.track("deepdots_user_engagement", {
2512
+ engagement_time_msec: ms,
2513
+ ...current ? { screen: current.screen, path: current.path, screen_seconds: current.seconds } : {}
2514
+ });
2481
2515
  this.lastEngagementAt = Date.now();
2482
2516
  }
2483
2517
  }