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