@magicfeedback/popup-sdk 1.20.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 (31) hide show
  1. package/dist/{chunk-FROREHRG.mjs → chunk-BWYWXAIQ.mjs} +2 -2
  2. package/dist/{chunk-ZJ5HG3QF.mjs → chunk-H434NTBB.mjs} +2 -2
  3. package/dist/{chunk-OPR5I7WO.mjs → chunk-UBUY6G6Z.mjs} +2 -2
  4. package/dist/index.d.mts +38 -8
  5. package/dist/index.d.ts +38 -8
  6. package/dist/index.js +66 -23
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +68 -25
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.native.d.mts +38 -8
  11. package/dist/index.native.d.ts +38 -8
  12. package/dist/index.native.js +66 -23
  13. package/dist/index.native.js.map +1 -1
  14. package/dist/index.native.mjs +68 -25
  15. package/dist/index.native.mjs.map +1 -1
  16. package/dist/react-native.d.mts +32 -8
  17. package/dist/react-native.d.ts +32 -8
  18. package/dist/react-native.js +66 -23
  19. package/dist/react-native.js.map +1 -1
  20. package/dist/react-native.mjs +68 -25
  21. package/dist/react-native.mjs.map +1 -1
  22. package/dist/{renderPopup-RUY3OBYV.mjs → renderPopup-HNSFPFVT.mjs} +2 -2
  23. package/dist/{renderPopup-I6CPIR75.mjs → renderPopup-VXKWSZ4E.mjs} +2 -2
  24. package/dist/{renderPopup-XNVNP2ZU.mjs → renderPopup-WNF67H5T.mjs} +2 -2
  25. package/package.json +1 -1
  26. /package/dist/{chunk-FROREHRG.mjs.map → chunk-BWYWXAIQ.mjs.map} +0 -0
  27. /package/dist/{chunk-ZJ5HG3QF.mjs.map → chunk-H434NTBB.mjs.map} +0 -0
  28. /package/dist/{chunk-OPR5I7WO.mjs.map → chunk-UBUY6G6Z.mjs.map} +0 -0
  29. /package/dist/{renderPopup-RUY3OBYV.mjs.map → renderPopup-HNSFPFVT.mjs.map} +0 -0
  30. /package/dist/{renderPopup-I6CPIR75.mjs.map → renderPopup-VXKWSZ4E.mjs.map} +0 -0
  31. /package/dist/{renderPopup-XNVNP2ZU.mjs.map → renderPopup-WNF67H5T.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  style_default,
30
30
  surveySdkCssUrls,
31
31
  surveySdkUrls
32
- } from "./chunk-OPR5I7WO.mjs";
32
+ } from "./chunk-UBUY6G6Z.mjs";
33
33
  import "./chunk-3QS3WKRC.mjs";
34
34
 
35
35
  // src/types/index.ts
@@ -997,7 +997,7 @@ function logRnSurveySdkChoice(choice, debug) {
997
997
  }
998
998
 
999
999
  // src/ui/preload.ts
1000
- var defaultLoader = () => import("./renderPopup-XNVNP2ZU.mjs");
1000
+ var defaultLoader = () => import("./renderPopup-HNSFPFVT.mjs");
1001
1001
  var pending = null;
1002
1002
  function preloadRenderPopup(loader = defaultLoader) {
1003
1003
  if (pending) return pending;
@@ -1070,7 +1070,7 @@ var BrowserPopupRenderer = class {
1070
1070
  if (!this.container) return;
1071
1071
  this.visible = true;
1072
1072
  const container = this.container;
1073
- void import("./renderPopup-XNVNP2ZU.mjs").then(
1073
+ void import("./renderPopup-HNSFPFVT.mjs").then(
1074
1074
  ({ renderPopup }) => {
1075
1075
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1076
1076
  },
@@ -1550,9 +1550,11 @@ function createFeedbackSink(options) {
1550
1550
  const body = buildAnalyticsFeedbackBody(envelope, options.keys, feedbackSessionId, { sessionEnd });
1551
1551
  options.log?.("[DeepdotsAnalytics] POST /sdk/feedback \u2192", body);
1552
1552
  const batch = { body, at: now() };
1553
- if (sessionEnd) {
1554
- feedbackSessionId = void 0;
1555
- options.onSessionReset?.();
1553
+ if (sessionEnd || meta?.persist) {
1554
+ if (sessionEnd) {
1555
+ feedbackSessionId = void 0;
1556
+ options.onSessionReset?.();
1557
+ }
1556
1558
  addPending(batch);
1557
1559
  await drain();
1558
1560
  return;
@@ -2317,6 +2319,7 @@ var ANALYTICS_SESSION_TIMEOUT_MS = 30 * 6e4;
2317
2319
  var ANALYTICS_SERVER_IDLE_MS = 60 * 6e4;
2318
2320
  var ANALYTICS_SESSION_DISCARD_MS = ANALYTICS_SERVER_IDLE_MS - 10 * 6e4;
2319
2321
  var ANALYTICS_RESUME_WINDOW_MS = 6e4;
2322
+ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2320
2323
  var RESERVED_EVENT_PREFIX = "deepdots_";
2321
2324
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2322
2325
  var MAX_PENDING_TRIGGERS = 20;
@@ -2484,7 +2487,7 @@ var DeepdotsPopups = class {
2484
2487
  const resumable = this.readResumableSession();
2485
2488
  if (resumable) {
2486
2489
  this.analyticsFeedbackSessionId = resumable.sessionId;
2487
- this.suspended = { at: resumable.at, userId: resumable.userId };
2490
+ this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2488
2491
  }
2489
2492
  const analyticsSink = config.analytics ? createFeedbackSink({
2490
2493
  baseUrl: this.baseUrl,
@@ -2743,21 +2746,28 @@ var DeepdotsPopups = class {
2743
2746
  this.navObserver.visit(name);
2744
2747
  }
2745
2748
  }
2746
- /** App a foreground (RN: AppState 'active'): reanuda el engagement time y abre sesión nueva. */
2749
+ /**
2750
+ * App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
2751
+ * background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
2752
+ * (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
2753
+ */
2747
2754
  onForeground() {
2748
2755
  this.engagement?.resume();
2749
2756
  this.openSession("foreground");
2750
2757
  }
2751
2758
  /**
2752
- * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
2753
- * (page_view), mini-services (mini_service_exit), emite engagement + `session_end` y
2754
- * envía el último lote con `completed:true`.
2755
- *
2756
- * Es la única señal disponible en móvil: el kill de la app (swipe) NO da callback.
2759
+ * App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
2760
+ * actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
2761
+ * `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
2762
+ * - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
2763
+ * en el mismo registro;
2764
+ * - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
2765
+ * minutos con un `session_end` `background` a la hora de la suspensión.
2766
+ * Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
2757
2767
  */
2758
2768
  onBackground() {
2759
2769
  this.cancelDelayedPopups("app to background");
2760
- this.closeSession("background");
2770
+ if (!this.suspendSession("background")) this.closeSession("background");
2761
2771
  this.engagement?.pause();
2762
2772
  }
2763
2773
  /**
@@ -2982,27 +2992,37 @@ var DeepdotsPopups = class {
2982
2992
  * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
2983
2993
  * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
2984
2994
  *
2995
+ * En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
2996
+ * background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
2997
+ *
2985
2998
  * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
2986
- * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
2999
+ * POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
3000
+ * como antes.
2987
3001
  */
2988
- suspendSession() {
3002
+ suspendSession(reason) {
2989
3003
  if (!this.sessionOpen || !this.tracking?.isTrackingEnabled()) return false;
2990
3004
  const sessionId = this.analyticsFeedbackSessionId;
2991
3005
  const integration = this.analyticsIntegration;
2992
- const storage = getSessionStorage();
2993
- if (!sessionId || !integration || !storage) return false;
3006
+ if (!sessionId || !integration) return false;
2994
3007
  const at = Date.now();
2995
3008
  const userId = this.tracking.getUserId();
2996
- if (!writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
3009
+ if (reason === "page_hide") {
3010
+ const storage = getSessionStorage();
3011
+ if (!storage || !writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
3012
+ }
2997
3013
  this.sessionOpen = false;
2998
- this.suspended = { at, userId };
3014
+ this.suspended = {
3015
+ at,
3016
+ userId,
3017
+ windowMs: reason === "page_hide" ? ANALYTICS_RESUME_WINDOW_MS : ANALYTICS_BACKGROUND_RESUME_WINDOW_MS
3018
+ };
2999
3019
  this.navObserver?.stop();
3000
3020
  this.navStarted = false;
3001
3021
  this.analytics?.exitAllMiniServices();
3002
3022
  this.flushEngagement();
3003
3023
  this.engagement?.pause();
3004
- this.track("deepdots_session_suspend", { reason: "page_hide" });
3005
- this.flushAnalytics({ final: true });
3024
+ this.track("deepdots_session_suspend", { reason });
3025
+ this.flushAnalytics(reason === "page_hide" ? { final: true } : { persist: true });
3006
3026
  this.log("tracking \xB7 session suspended:", sessionId);
3007
3027
  return true;
3008
3028
  }
@@ -3024,7 +3044,8 @@ var DeepdotsPopups = class {
3024
3044
  }
3025
3045
  /**
3026
3046
  * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
3027
- * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
3047
+ * ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
3048
+ * ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
3028
3049
  * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
3029
3050
  * se abre ahora va a uno nuevo.
3030
3051
  */
@@ -3035,7 +3056,7 @@ var DeepdotsPopups = class {
3035
3056
  const storage = getSessionStorage();
3036
3057
  if (storage) clearSuspendedSession(storage);
3037
3058
  const suspendedMs = Math.max(0, Date.now() - suspended.at);
3038
- if (this.analyticsFeedbackSessionId && suspendedMs <= ANALYTICS_RESUME_WINDOW_MS && suspended.userId === (this.tracking?.getUserId() ?? null)) {
3059
+ if (this.analyticsFeedbackSessionId && suspendedMs <= suspended.windowMs && suspended.userId === (this.tracking?.getUserId() ?? null)) {
3039
3060
  return suspendedMs;
3040
3061
  }
3041
3062
  this.analytics?.discardSession(this.analyticsIdentity());
@@ -3043,6 +3064,27 @@ var DeepdotsPopups = class {
3043
3064
  this.tracking?.setSessionId(null);
3044
3065
  return null;
3045
3066
  }
3067
+ /**
3068
+ * `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
3069
+ * misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
3070
+ * (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
3071
+ * el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
3072
+ * #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
3073
+ * - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
3074
+ * - Más: el backend ya la cerró → se descarta sin enviar nada.
3075
+ * Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
3076
+ */
3077
+ closeStaleHiddenSession() {
3078
+ if (!this.sessionOpen || this.hiddenAt === null) return false;
3079
+ const hiddenFor = Date.now() - this.hiddenAt;
3080
+ if (hiddenFor < ANALYTICS_SESSION_TIMEOUT_MS) return false;
3081
+ if (hiddenFor < ANALYTICS_SESSION_DISCARD_MS) {
3082
+ this.closeSession("idle_timeout");
3083
+ } else {
3084
+ this.discardSession();
3085
+ }
3086
+ return true;
3087
+ }
3046
3088
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
3047
3089
  discardSession() {
3048
3090
  this.sessionOpen = false;
@@ -3091,7 +3133,8 @@ var DeepdotsPopups = class {
3091
3133
  if (typeof document === "undefined" || typeof window === "undefined") return;
3092
3134
  window.addEventListener("pagehide", () => {
3093
3135
  clearInterval(this.analyticsFlushTimer);
3094
- if (!this.suspendSession()) this.closeSession("page_hide");
3136
+ if (this.closeStaleHiddenSession()) return;
3137
+ if (!this.suspendSession("page_hide")) this.closeSession("page_hide");
3095
3138
  });
3096
3139
  window.addEventListener("pageshow", (event) => {
3097
3140
  if (!event.persisted) return;