@magicfeedback/popup-sdk 1.11.0 → 1.12.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
@@ -2176,7 +2176,7 @@ var DeepdotsPopups = class {
2176
2176
  this.navObserver.install();
2177
2177
  this.engagement = new EngagementTracker();
2178
2178
  this.setupAnalyticsFlush();
2179
- this.openSession();
2179
+ this.openSession("cold_start");
2180
2180
  if (resumable && this.analyticsFeedbackSessionId === resumable.sessionId) {
2181
2181
  this.notifyFeedbackSession(resumable.sessionId, "open");
2182
2182
  }
@@ -2234,7 +2234,7 @@ var DeepdotsPopups = class {
2234
2234
  setTrackingEnabled(enabled) {
2235
2235
  if (!enabled) this.closeSession("tracking_disabled");
2236
2236
  this.tracking?.setTrackingEnabled(enabled);
2237
- if (enabled) this.openSession();
2237
+ if (enabled) this.openSession("tracking_enabled");
2238
2238
  if (enabled) this.resolveGeo();
2239
2239
  this.log("tracking \xB7 setTrackingEnabled:", enabled, "\xB7 session_id:", this.tracking?.getSessionId() ?? null);
2240
2240
  }
@@ -2351,7 +2351,7 @@ var DeepdotsPopups = class {
2351
2351
  /** App a foreground (RN: AppState 'active'): reanuda el engagement time y abre sesión nueva. */
2352
2352
  onForeground() {
2353
2353
  this.engagement?.resume();
2354
- this.openSession();
2354
+ this.openSession("foreground");
2355
2355
  }
2356
2356
  /**
2357
2357
  * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
@@ -2399,7 +2399,7 @@ var DeepdotsPopups = class {
2399
2399
  this.answeredSurveys.clear();
2400
2400
  clearPopupState(storage);
2401
2401
  this.log("tracking \xB7 user_change \xB7 user_id:", this.tracking.getUserId());
2402
- this.openSession();
2402
+ this.openSession("user_change");
2403
2403
  }
2404
2404
  /**
2405
2405
  * Cierra la sesión actual: vuelca todo lo que quedaba abierto y envía el último lote
@@ -2425,17 +2425,24 @@ var DeepdotsPopups = class {
2425
2425
  this.log("tracking \xB7 session_end:", reason);
2426
2426
  }
2427
2427
  /**
2428
- * Abre sesión (`session_start`) si no hay una abierta y el tracking está activo. Idempotente:
2429
- * se llama en init(), al volver a foreground y al conceder el consentimiento.
2428
+ * Abre sesión (`session_start`) si no hay una abierta y el tracking está activo. Idempotente.
2429
+ * El `reason` dice por qué empieza (ver `SessionStartReason`):
2430
+ * - `cold_start`: init() (carga de la página / arranque de la app RN).
2431
+ * - `foreground`: onForeground() tras un cierre (RN).
2432
+ * - `tracking_enabled`: setTrackingEnabled(true).
2433
+ * - `user_change`: setUserId() o init() con otro userId.
2434
+ * - `idle_timeout`: la pestaña vuelve a verse tras más de 30 min oculta.
2435
+ * - `bfcache_restore`: vuelta desde la bfcache fuera de la ventana de reanudación.
2436
+ * Si hay una sesión suspendida a tiempo emite `deepdots_session_resume` en su lugar, sin reason.
2430
2437
  */
2431
- openSession() {
2438
+ openSession(reason) {
2432
2439
  if (this.sessionOpen) return;
2433
2440
  if (!this.tracking?.isTrackingEnabled()) return;
2434
2441
  const suspendedMs = this.takeSuspendedSession();
2435
2442
  this.sessionOpen = true;
2436
2443
  this.lastEngagementAt = Date.now();
2437
2444
  if (suspendedMs === null) {
2438
- this.track("deepdots_session_start", {});
2445
+ this.track("deepdots_session_start", { reason });
2439
2446
  } else {
2440
2447
  this.track("deepdots_session_resume", { suspended_ms: suspendedMs });
2441
2448
  this.log("tracking \xB7 session resumed after", suspendedMs, "ms:", this.analyticsFeedbackSessionId);
@@ -2502,7 +2509,7 @@ var DeepdotsPopups = class {
2502
2509
  } else {
2503
2510
  this.discardSession();
2504
2511
  }
2505
- this.openSession();
2512
+ this.openSession("idle_timeout");
2506
2513
  }
2507
2514
  /**
2508
2515
  * `pagehide` en web: SUSPENDE la sesión en vez de cerrarla, porque el navegador lo lanza
@@ -2626,7 +2633,7 @@ var DeepdotsPopups = class {
2626
2633
  window.addEventListener("pageshow", (event) => {
2627
2634
  if (!event.persisted) return;
2628
2635
  this.startAnalyticsFlushTimer();
2629
- this.openSession();
2636
+ this.openSession("bfcache_restore");
2630
2637
  });
2631
2638
  document.addEventListener("visibilitychange", () => {
2632
2639
  if (document.visibilityState === "hidden") {