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