@magicfeedback/popup-sdk 1.19.0 → 1.21.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.
Files changed (34) hide show
  1. package/dist/{chunk-EW2ARDEY.mjs → chunk-BWYWXAIQ.mjs} +23 -3
  2. package/dist/chunk-BWYWXAIQ.mjs.map +1 -0
  3. package/dist/{chunk-7ZQOAKXR.mjs → chunk-H434NTBB.mjs} +26 -4
  4. package/dist/chunk-H434NTBB.mjs.map +1 -0
  5. package/dist/{chunk-XOEEBDBJ.mjs → chunk-UBUY6G6Z.mjs} +26 -4
  6. package/dist/chunk-UBUY6G6Z.mjs.map +1 -0
  7. package/dist/index.d.mts +105 -10
  8. package/dist/index.d.ts +105 -10
  9. package/dist/index.js +186 -37
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +163 -36
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/index.native.d.mts +105 -10
  14. package/dist/index.native.d.ts +105 -10
  15. package/dist/index.native.js +204 -42
  16. package/dist/index.native.js.map +1 -1
  17. package/dist/index.native.mjs +181 -41
  18. package/dist/index.native.mjs.map +1 -1
  19. package/dist/react-native.d.mts +47 -8
  20. package/dist/react-native.d.ts +47 -8
  21. package/dist/react-native.js +200 -41
  22. package/dist/react-native.js.map +1 -1
  23. package/dist/react-native.mjs +180 -41
  24. package/dist/react-native.mjs.map +1 -1
  25. package/dist/{renderPopup-2Y4QMWR7.mjs → renderPopup-HNSFPFVT.mjs} +2 -2
  26. package/dist/{renderPopup-ZHTRMFO2.mjs → renderPopup-VXKWSZ4E.mjs} +2 -2
  27. package/dist/{renderPopup-YDJUON42.mjs → renderPopup-WNF67H5T.mjs} +2 -2
  28. package/package.json +1 -1
  29. package/dist/chunk-7ZQOAKXR.mjs.map +0 -1
  30. package/dist/chunk-EW2ARDEY.mjs.map +0 -1
  31. package/dist/chunk-XOEEBDBJ.mjs.map +0 -1
  32. /package/dist/{renderPopup-2Y4QMWR7.mjs.map → renderPopup-HNSFPFVT.mjs.map} +0 -0
  33. /package/dist/{renderPopup-ZHTRMFO2.mjs.map → renderPopup-VXKWSZ4E.mjs.map} +0 -0
  34. /package/dist/{renderPopup-YDJUON42.mjs.map → renderPopup-WNF67H5T.mjs.map} +0 -0
@@ -25,7 +25,7 @@ import {
25
25
  style_default,
26
26
  surveySdkCssUrls,
27
27
  surveySdkUrls
28
- } from "./chunk-EW2ARDEY.mjs";
28
+ } from "./chunk-BWYWXAIQ.mjs";
29
29
  import {
30
30
  __require
31
31
  } from "./chunk-BJTO5JO5.mjs";
@@ -1000,7 +1000,7 @@ function logRnSurveySdkChoice(choice, debug) {
1000
1000
  }
1001
1001
 
1002
1002
  // src/ui/preload.ts
1003
- var defaultLoader = () => import("./renderPopup-ZHTRMFO2.mjs");
1003
+ var defaultLoader = () => import("./renderPopup-VXKWSZ4E.mjs");
1004
1004
  var pending = null;
1005
1005
  function preloadRenderPopup(loader = defaultLoader) {
1006
1006
  if (pending) return pending;
@@ -1073,7 +1073,7 @@ var BrowserPopupRenderer = class {
1073
1073
  if (!this.container) return;
1074
1074
  this.visible = true;
1075
1075
  const container = this.container;
1076
- void import("./renderPopup-ZHTRMFO2.mjs").then(
1076
+ void import("./renderPopup-VXKWSZ4E.mjs").then(
1077
1077
  ({ renderPopup }) => {
1078
1078
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1079
1079
  },
@@ -1539,9 +1539,11 @@ function createFeedbackSink(options) {
1539
1539
  const body = buildAnalyticsFeedbackBody(envelope, options.keys, feedbackSessionId, { sessionEnd });
1540
1540
  options.log?.("[DeepdotsAnalytics] POST /sdk/feedback \u2192", body);
1541
1541
  const batch = { body, at: now() };
1542
- if (sessionEnd) {
1543
- feedbackSessionId = void 0;
1544
- options.onSessionReset?.();
1542
+ if (sessionEnd || meta?.persist) {
1543
+ if (sessionEnd) {
1544
+ feedbackSessionId = void 0;
1545
+ options.onSessionReset?.();
1546
+ }
1545
1547
  addPending(batch);
1546
1548
  await drain();
1547
1549
  return;
@@ -1970,6 +1972,8 @@ var CrashReporter = class {
1970
1972
  this.windowInstalled = false;
1971
1973
  /** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
1972
1974
  this.hookedErrorUtils = /* @__PURE__ */ new Set();
1975
+ /** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
1976
+ this.hookedRejections = /* @__PURE__ */ new Set();
1973
1977
  this.options = options;
1974
1978
  this.now = options.now ?? (() => Date.now());
1975
1979
  }
@@ -2069,6 +2073,18 @@ var CrashReporter = class {
2069
2073
  previous?.(error, isFatal);
2070
2074
  });
2071
2075
  }
2076
+ /**
2077
+ * Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
2078
+ * persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
2079
+ * Idempotente por fuente.
2080
+ */
2081
+ installPromiseRejections(source) {
2082
+ if (this.hookedRejections.has(source)) return;
2083
+ this.hookedRejections.add(source);
2084
+ source.addUnhandledListener((error) => {
2085
+ if (this.isEnabled()) this.captureUnhandled(error ?? "unhandledrejection");
2086
+ });
2087
+ }
2072
2088
  /** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
2073
2089
  _persistForTest(error) {
2074
2090
  this.captureUnhandled(error);
@@ -2173,6 +2189,51 @@ function resolveBackgroundTask(explicit, platform) {
2173
2189
  }
2174
2190
  return void 0;
2175
2191
  }
2192
+ var DEFAULT_REJECTION_WHITELIST = [ReferenceError, TypeError, RangeError];
2193
+ function createHermesRejectionHub(hermes, options) {
2194
+ if (!hermes || typeof hermes.enablePromiseRejectionTracker !== "function") return null;
2195
+ const original = hermes.enablePromiseRejectionTracker.bind(hermes);
2196
+ const listeners = /* @__PURE__ */ new Set();
2197
+ let hostOptions = null;
2198
+ let active = false;
2199
+ const forwardsToHost = (error) => !!hostOptions?.onUnhandled && (hostOptions.allRejections === true || DEFAULT_REJECTION_WHITELIST.some((type) => error instanceof type));
2200
+ const apply = () => {
2201
+ original({
2202
+ allRejections: true,
2203
+ onUnhandled: (id, error) => {
2204
+ listeners.forEach((listener) => {
2205
+ try {
2206
+ listener(error);
2207
+ } catch {
2208
+ }
2209
+ });
2210
+ if (hostOptions?.onUnhandled) {
2211
+ if (forwardsToHost(error)) hostOptions.onUnhandled(id, error);
2212
+ } else if (options.dev) {
2213
+ console.warn(`Possible unhandled promise rejection (id: ${id}):`, error);
2214
+ }
2215
+ },
2216
+ onHandled: (id, error) => hostOptions?.onHandled?.(id, error)
2217
+ });
2218
+ };
2219
+ hermes.enablePromiseRejectionTracker = (next) => {
2220
+ hostOptions = next ?? null;
2221
+ if (active) apply();
2222
+ else original(next);
2223
+ };
2224
+ return {
2225
+ addUnhandledListener(listener) {
2226
+ listeners.add(listener);
2227
+ if (!active) {
2228
+ active = true;
2229
+ apply();
2230
+ }
2231
+ return () => {
2232
+ listeners.delete(listener);
2233
+ };
2234
+ }
2235
+ };
2236
+ }
2176
2237
 
2177
2238
  // src/analytics/messaging.ts
2178
2239
  var MESSAGE_CHANNELS = ["push", "in_app"];
@@ -2250,6 +2311,7 @@ var ANALYTICS_SESSION_TIMEOUT_MS = 30 * 6e4;
2250
2311
  var ANALYTICS_SERVER_IDLE_MS = 60 * 6e4;
2251
2312
  var ANALYTICS_SESSION_DISCARD_MS = ANALYTICS_SERVER_IDLE_MS - 10 * 6e4;
2252
2313
  var ANALYTICS_RESUME_WINDOW_MS = 6e4;
2314
+ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2253
2315
  var RESERVED_EVENT_PREFIX = "deepdots_";
2254
2316
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2255
2317
  var MAX_PENDING_TRIGGERS = 20;
@@ -2337,6 +2399,8 @@ var DeepdotsPopups = class {
2337
2399
  this.lastEngagementAt = 0;
2338
2400
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
2339
2401
  this.hiddenAt = null;
2402
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
2403
+ this.autoTrackErrors = true;
2340
2404
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
2341
2405
  this.appStateSubscription = void 0;
2342
2406
  /**
@@ -2383,6 +2447,7 @@ var DeepdotsPopups = class {
2383
2447
  this.surveyCss = config.surveyCss;
2384
2448
  this.cspNonce = config.cspNonce;
2385
2449
  this.onFeedbackSession = config.onFeedbackSession;
2450
+ this.autoTrackErrors = config.autoTrack?.errors !== false;
2386
2451
  this.config = {
2387
2452
  apiKey: config.apiKey || void 0,
2388
2453
  debug: config.debug || false,
@@ -2414,7 +2479,7 @@ var DeepdotsPopups = class {
2414
2479
  const resumable = this.readResumableSession();
2415
2480
  if (resumable) {
2416
2481
  this.analyticsFeedbackSessionId = resumable.sessionId;
2417
- this.suspended = { at: resumable.at, userId: resumable.userId };
2482
+ this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2418
2483
  }
2419
2484
  const analyticsSink = config.analytics ? createFeedbackSink({
2420
2485
  baseUrl: this.baseUrl,
@@ -2581,11 +2646,14 @@ var DeepdotsPopups = class {
2581
2646
  */
2582
2647
  installCrashHandlers() {
2583
2648
  if (!this.crashReporter || !this.tracking?.isTrackingEnabled()) return;
2584
- this.crashReporter.install();
2585
- const errorUtils = this.rnErrorUtils ?? globalThis.ErrorUtils;
2649
+ const auto = this.autoTrackErrors;
2650
+ if (auto) this.crashReporter.install();
2651
+ const errorUtils = this.rnErrorUtils ?? (auto ? globalThis.ErrorUtils : void 0);
2586
2652
  if (errorUtils && typeof errorUtils.setGlobalHandler === "function") {
2587
2653
  this.crashReporter.installReactNative(errorUtils);
2588
2654
  }
2655
+ const rejections = auto ? getReactNativePlatform()?.promiseRejections : null;
2656
+ if (rejections) this.crashReporter.installPromiseRejections(rejections);
2589
2657
  }
2590
2658
  /**
2591
2659
  * Info interna del usuario que solo conoce el host (idioma, edad, plan…), persistida en el
@@ -2670,21 +2738,28 @@ var DeepdotsPopups = class {
2670
2738
  this.navObserver.visit(name);
2671
2739
  }
2672
2740
  }
2673
- /** App a foreground (RN: AppState 'active'): reanuda el engagement time y abre sesión nueva. */
2741
+ /**
2742
+ * App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
2743
+ * background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
2744
+ * (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
2745
+ */
2674
2746
  onForeground() {
2675
2747
  this.engagement?.resume();
2676
2748
  this.openSession("foreground");
2677
2749
  }
2678
2750
  /**
2679
- * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
2680
- * (page_view), mini-services (mini_service_exit), emite engagement + `session_end` y
2681
- * envía el último lote con `completed:true`.
2682
- *
2683
- * Es la única señal disponible en móvil: el kill de la app (swipe) NO da callback.
2751
+ * App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
2752
+ * actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
2753
+ * `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
2754
+ * - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
2755
+ * en el mismo registro;
2756
+ * - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
2757
+ * minutos con un `session_end` `background` a la hora de la suspensión.
2758
+ * Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
2684
2759
  */
2685
2760
  onBackground() {
2686
2761
  this.cancelDelayedPopups("app to background");
2687
- this.closeSession("background");
2762
+ if (!this.suspendSession("background")) this.closeSession("background");
2688
2763
  this.engagement?.pause();
2689
2764
  }
2690
2765
  /**
@@ -2731,11 +2806,24 @@ var DeepdotsPopups = class {
2731
2806
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
2732
2807
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
2733
2808
  *
2809
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
2810
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
2811
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
2812
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
2813
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
2814
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
2815
+ *
2734
2816
  * Equivale a llamar a `init()` otra vez con otro `userId`.
2735
2817
  */
2736
2818
  setUserId(userId) {
2737
2819
  const next = userId || void 0;
2738
2820
  if (!this.initialized || !this.config || next === this.config.userId) return;
2821
+ const identifying = !this.config.userId && !!next;
2822
+ const previous = identifying ? {
2823
+ identified: true,
2824
+ previous_user_id: this.tracking?.getUserId() ?? void 0,
2825
+ previous_session_id: this.analyticsFeedbackSessionId
2826
+ } : void 0;
2739
2827
  this.closeSession("user_change");
2740
2828
  const enabled = this.tracking?.isTrackingEnabled() ?? true;
2741
2829
  const storage = this.storage ?? createDefaultStorage();
@@ -2748,13 +2836,18 @@ var DeepdotsPopups = class {
2748
2836
  post: (body) => this.postContact(body)
2749
2837
  }) : null;
2750
2838
  this.analytics?.resetUserScope();
2751
- this.messageGuard.reset();
2752
- this.lastShown.clear();
2753
- this.surveyProgress.clear();
2754
- this.answeredSurveys.clear();
2755
- clearPopupState(storage);
2756
- this.log("tracking \xB7 user_change \xB7 user_id:", this.tracking.getUserId());
2757
- this.openSession("user_change");
2839
+ if (!identifying) {
2840
+ this.messageGuard.reset();
2841
+ this.lastShown.clear();
2842
+ this.surveyProgress.clear();
2843
+ this.answeredSurveys.clear();
2844
+ clearPopupState(storage);
2845
+ }
2846
+ this.log(
2847
+ identifying ? "tracking \xB7 user identified \xB7 user_id:" : "tracking \xB7 user_change \xB7 user_id:",
2848
+ this.tracking.getUserId()
2849
+ );
2850
+ this.openSession("user_change", previous);
2758
2851
  }
2759
2852
  /**
2760
2853
  * Cierra la sesión actual: vuelca todo lo que quedaba abierto y envía el último lote
@@ -2790,14 +2883,14 @@ var DeepdotsPopups = class {
2790
2883
  * - `bfcache_restore`: vuelta desde la bfcache fuera de la ventana de reanudación.
2791
2884
  * Si hay una sesión suspendida a tiempo emite `deepdots_session_resume` en su lugar, sin reason.
2792
2885
  */
2793
- openSession(reason) {
2886
+ openSession(reason, extra) {
2794
2887
  if (this.sessionOpen) return;
2795
2888
  if (!this.tracking?.isTrackingEnabled()) return;
2796
2889
  const suspendedMs = this.takeSuspendedSession();
2797
2890
  this.sessionOpen = true;
2798
2891
  this.lastEngagementAt = Date.now();
2799
2892
  if (suspendedMs === null) {
2800
- this.track("deepdots_session_start", { reason });
2893
+ this.track("deepdots_session_start", { reason, ...extra });
2801
2894
  } else {
2802
2895
  this.track("deepdots_session_resume", { suspended_ms: suspendedMs });
2803
2896
  this.log("tracking \xB7 session resumed after", suspendedMs, "ms:", this.analyticsFeedbackSessionId);
@@ -2891,27 +2984,37 @@ var DeepdotsPopups = class {
2891
2984
  * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
2892
2985
  * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
2893
2986
  *
2987
+ * En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
2988
+ * background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
2989
+ *
2894
2990
  * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
2895
- * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
2991
+ * POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
2992
+ * como antes.
2896
2993
  */
2897
- suspendSession() {
2994
+ suspendSession(reason) {
2898
2995
  if (!this.sessionOpen || !this.tracking?.isTrackingEnabled()) return false;
2899
2996
  const sessionId = this.analyticsFeedbackSessionId;
2900
2997
  const integration = this.analyticsIntegration;
2901
- const storage = getSessionStorage();
2902
- if (!sessionId || !integration || !storage) return false;
2998
+ if (!sessionId || !integration) return false;
2903
2999
  const at = Date.now();
2904
3000
  const userId = this.tracking.getUserId();
2905
- if (!writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
3001
+ if (reason === "page_hide") {
3002
+ const storage = getSessionStorage();
3003
+ if (!storage || !writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
3004
+ }
2906
3005
  this.sessionOpen = false;
2907
- this.suspended = { at, userId };
3006
+ this.suspended = {
3007
+ at,
3008
+ userId,
3009
+ windowMs: reason === "page_hide" ? ANALYTICS_RESUME_WINDOW_MS : ANALYTICS_BACKGROUND_RESUME_WINDOW_MS
3010
+ };
2908
3011
  this.navObserver?.stop();
2909
3012
  this.navStarted = false;
2910
3013
  this.analytics?.exitAllMiniServices();
2911
3014
  this.flushEngagement();
2912
3015
  this.engagement?.pause();
2913
- this.track("deepdots_session_suspend", { reason: "page_hide" });
2914
- this.flushAnalytics({ final: true });
3016
+ this.track("deepdots_session_suspend", { reason });
3017
+ this.flushAnalytics(reason === "page_hide" ? { final: true } : { persist: true });
2915
3018
  this.log("tracking \xB7 session suspended:", sessionId);
2916
3019
  return true;
2917
3020
  }
@@ -2933,7 +3036,8 @@ var DeepdotsPopups = class {
2933
3036
  }
2934
3037
  /**
2935
3038
  * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
2936
- * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
3039
+ * ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
3040
+ * ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
2937
3041
  * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
2938
3042
  * se abre ahora va a uno nuevo.
2939
3043
  */
@@ -2944,7 +3048,7 @@ var DeepdotsPopups = class {
2944
3048
  const storage = getSessionStorage();
2945
3049
  if (storage) clearSuspendedSession(storage);
2946
3050
  const suspendedMs = Math.max(0, Date.now() - suspended.at);
2947
- if (this.analyticsFeedbackSessionId && suspendedMs <= ANALYTICS_RESUME_WINDOW_MS && suspended.userId === (this.tracking?.getUserId() ?? null)) {
3051
+ if (this.analyticsFeedbackSessionId && suspendedMs <= suspended.windowMs && suspended.userId === (this.tracking?.getUserId() ?? null)) {
2948
3052
  return suspendedMs;
2949
3053
  }
2950
3054
  this.analytics?.discardSession(this.analyticsIdentity());
@@ -2952,6 +3056,27 @@ var DeepdotsPopups = class {
2952
3056
  this.tracking?.setSessionId(null);
2953
3057
  return null;
2954
3058
  }
3059
+ /**
3060
+ * `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
3061
+ * misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
3062
+ * (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
3063
+ * el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
3064
+ * #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
3065
+ * - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
3066
+ * - Más: el backend ya la cerró → se descarta sin enviar nada.
3067
+ * Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
3068
+ */
3069
+ closeStaleHiddenSession() {
3070
+ if (!this.sessionOpen || this.hiddenAt === null) return false;
3071
+ const hiddenFor = Date.now() - this.hiddenAt;
3072
+ if (hiddenFor < ANALYTICS_SESSION_TIMEOUT_MS) return false;
3073
+ if (hiddenFor < ANALYTICS_SESSION_DISCARD_MS) {
3074
+ this.closeSession("idle_timeout");
3075
+ } else {
3076
+ this.discardSession();
3077
+ }
3078
+ return true;
3079
+ }
2955
3080
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
2956
3081
  discardSession() {
2957
3082
  this.sessionOpen = false;
@@ -3000,7 +3125,8 @@ var DeepdotsPopups = class {
3000
3125
  if (typeof document === "undefined" || typeof window === "undefined") return;
3001
3126
  window.addEventListener("pagehide", () => {
3002
3127
  clearInterval(this.analyticsFlushTimer);
3003
- if (!this.suspendSession()) this.closeSession("page_hide");
3128
+ if (this.closeStaleHiddenSession()) return;
3129
+ if (!this.suspendSession("page_hide")) this.closeSession("page_hide");
3004
3130
  });
3005
3131
  window.addEventListener("pageshow", (event) => {
3006
3132
  if (!event.persisted) return;
@@ -3857,13 +3983,26 @@ function setupReactNative(sdk2, config, deps = {}) {
3857
3983
  };
3858
3984
  }
3859
3985
 
3986
+ // src/platform/react-native-defaults.ts
3987
+ var hub;
3988
+ function registerReactNativeDefaults(rn) {
3989
+ if (hub === void 0) {
3990
+ hub = getReactNativePlatform()?.promiseRejections ?? createHermesRejectionHub(
3991
+ globalThis.HermesInternal,
3992
+ { dev: typeof __DEV__ !== "undefined" && !!__DEV__ }
3993
+ );
3994
+ }
3995
+ registerReactNativePlatform({
3996
+ os: rn.Platform.OS,
3997
+ appState: rn.AppState,
3998
+ backgroundTaskModule: rn.NativeModules?.DeepdotsBackgroundTask ?? null,
3999
+ promiseRejections: hub
4000
+ });
4001
+ }
4002
+
3860
4003
  // src/react-native/index.tsx
3861
4004
  import { jsx, jsxs } from "react/jsx-runtime";
3862
- registerReactNativePlatform({
3863
- os: Platform.OS,
3864
- appState: AppState,
3865
- backgroundTaskModule: NativeModules?.DeepdotsBackgroundTask ?? null
3866
- });
4005
+ registerReactNativeDefaults({ AppState, NativeModules, Platform });
3867
4006
  var sdk = new DeepdotsPopups();
3868
4007
  var DeepdotsContext = createContext(sdk);
3869
4008
  var useDeepdots = () => useContext(DeepdotsContext);