@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
@@ -29,7 +29,7 @@ import {
29
29
  style_default,
30
30
  surveySdkCssUrls,
31
31
  surveySdkUrls
32
- } from "./chunk-ZJ5HG3QF.mjs";
32
+ } from "./chunk-H434NTBB.mjs";
33
33
  import "./chunk-3QS3WKRC.mjs";
34
34
 
35
35
  // src/index.native.ts
@@ -1092,7 +1092,7 @@ function logRnSurveySdkChoice(choice, debug) {
1092
1092
  }
1093
1093
 
1094
1094
  // src/ui/preload.ts
1095
- var defaultLoader = () => import("./renderPopup-RUY3OBYV.mjs");
1095
+ var defaultLoader = () => import("./renderPopup-WNF67H5T.mjs");
1096
1096
  var pending = null;
1097
1097
  function preloadRenderPopup(loader = defaultLoader) {
1098
1098
  if (pending) return pending;
@@ -1165,7 +1165,7 @@ var BrowserPopupRenderer = class {
1165
1165
  if (!this.container) return;
1166
1166
  this.visible = true;
1167
1167
  const container = this.container;
1168
- void import("./renderPopup-RUY3OBYV.mjs").then(
1168
+ void import("./renderPopup-WNF67H5T.mjs").then(
1169
1169
  ({ renderPopup }) => {
1170
1170
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1171
1171
  },
@@ -1645,9 +1645,11 @@ function createFeedbackSink(options) {
1645
1645
  const body = buildAnalyticsFeedbackBody(envelope, options.keys, feedbackSessionId, { sessionEnd });
1646
1646
  options.log?.("[DeepdotsAnalytics] POST /sdk/feedback \u2192", body);
1647
1647
  const batch = { body, at: now() };
1648
- if (sessionEnd) {
1649
- feedbackSessionId = void 0;
1650
- options.onSessionReset?.();
1648
+ if (sessionEnd || meta?.persist) {
1649
+ if (sessionEnd) {
1650
+ feedbackSessionId = void 0;
1651
+ options.onSessionReset?.();
1652
+ }
1651
1653
  addPending(batch);
1652
1654
  await drain();
1653
1655
  return;
@@ -2340,6 +2342,7 @@ var ANALYTICS_SESSION_TIMEOUT_MS = 30 * 6e4;
2340
2342
  var ANALYTICS_SERVER_IDLE_MS = 60 * 6e4;
2341
2343
  var ANALYTICS_SESSION_DISCARD_MS = ANALYTICS_SERVER_IDLE_MS - 10 * 6e4;
2342
2344
  var ANALYTICS_RESUME_WINDOW_MS = 6e4;
2345
+ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2343
2346
  var RESERVED_EVENT_PREFIX = "deepdots_";
2344
2347
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2345
2348
  var MAX_PENDING_TRIGGERS = 20;
@@ -2507,7 +2510,7 @@ var DeepdotsPopups = class {
2507
2510
  const resumable = this.readResumableSession();
2508
2511
  if (resumable) {
2509
2512
  this.analyticsFeedbackSessionId = resumable.sessionId;
2510
- this.suspended = { at: resumable.at, userId: resumable.userId };
2513
+ this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2511
2514
  }
2512
2515
  const analyticsSink = config.analytics ? createFeedbackSink({
2513
2516
  baseUrl: this.baseUrl,
@@ -2766,21 +2769,28 @@ var DeepdotsPopups = class {
2766
2769
  this.navObserver.visit(name);
2767
2770
  }
2768
2771
  }
2769
- /** App a foreground (RN: AppState 'active'): reanuda el engagement time y abre sesión nueva. */
2772
+ /**
2773
+ * App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
2774
+ * background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
2775
+ * (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
2776
+ */
2770
2777
  onForeground() {
2771
2778
  this.engagement?.resume();
2772
2779
  this.openSession("foreground");
2773
2780
  }
2774
2781
  /**
2775
- * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
2776
- * (page_view), mini-services (mini_service_exit), emite engagement + `session_end` y
2777
- * envía el último lote con `completed:true`.
2778
- *
2779
- * Es la única señal disponible en móvil: el kill de la app (swipe) NO da callback.
2782
+ * App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
2783
+ * actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
2784
+ * `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
2785
+ * - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
2786
+ * en el mismo registro;
2787
+ * - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
2788
+ * minutos con un `session_end` `background` a la hora de la suspensión.
2789
+ * Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
2780
2790
  */
2781
2791
  onBackground() {
2782
2792
  this.cancelDelayedPopups("app to background");
2783
- this.closeSession("background");
2793
+ if (!this.suspendSession("background")) this.closeSession("background");
2784
2794
  this.engagement?.pause();
2785
2795
  }
2786
2796
  /**
@@ -3005,27 +3015,37 @@ var DeepdotsPopups = class {
3005
3015
  * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
3006
3016
  * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
3007
3017
  *
3018
+ * En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
3019
+ * background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
3020
+ *
3008
3021
  * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
3009
- * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
3022
+ * POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
3023
+ * como antes.
3010
3024
  */
3011
- suspendSession() {
3025
+ suspendSession(reason) {
3012
3026
  if (!this.sessionOpen || !this.tracking?.isTrackingEnabled()) return false;
3013
3027
  const sessionId = this.analyticsFeedbackSessionId;
3014
3028
  const integration = this.analyticsIntegration;
3015
- const storage = getSessionStorage();
3016
- if (!sessionId || !integration || !storage) return false;
3029
+ if (!sessionId || !integration) return false;
3017
3030
  const at = Date.now();
3018
3031
  const userId = this.tracking.getUserId();
3019
- if (!writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
3032
+ if (reason === "page_hide") {
3033
+ const storage = getSessionStorage();
3034
+ if (!storage || !writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
3035
+ }
3020
3036
  this.sessionOpen = false;
3021
- this.suspended = { at, userId };
3037
+ this.suspended = {
3038
+ at,
3039
+ userId,
3040
+ windowMs: reason === "page_hide" ? ANALYTICS_RESUME_WINDOW_MS : ANALYTICS_BACKGROUND_RESUME_WINDOW_MS
3041
+ };
3022
3042
  this.navObserver?.stop();
3023
3043
  this.navStarted = false;
3024
3044
  this.analytics?.exitAllMiniServices();
3025
3045
  this.flushEngagement();
3026
3046
  this.engagement?.pause();
3027
- this.track("deepdots_session_suspend", { reason: "page_hide" });
3028
- this.flushAnalytics({ final: true });
3047
+ this.track("deepdots_session_suspend", { reason });
3048
+ this.flushAnalytics(reason === "page_hide" ? { final: true } : { persist: true });
3029
3049
  this.log("tracking \xB7 session suspended:", sessionId);
3030
3050
  return true;
3031
3051
  }
@@ -3047,7 +3067,8 @@ var DeepdotsPopups = class {
3047
3067
  }
3048
3068
  /**
3049
3069
  * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
3050
- * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
3070
+ * ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
3071
+ * ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
3051
3072
  * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
3052
3073
  * se abre ahora va a uno nuevo.
3053
3074
  */
@@ -3058,7 +3079,7 @@ var DeepdotsPopups = class {
3058
3079
  const storage = getSessionStorage();
3059
3080
  if (storage) clearSuspendedSession(storage);
3060
3081
  const suspendedMs = Math.max(0, Date.now() - suspended.at);
3061
- if (this.analyticsFeedbackSessionId && suspendedMs <= ANALYTICS_RESUME_WINDOW_MS && suspended.userId === (this.tracking?.getUserId() ?? null)) {
3082
+ if (this.analyticsFeedbackSessionId && suspendedMs <= suspended.windowMs && suspended.userId === (this.tracking?.getUserId() ?? null)) {
3062
3083
  return suspendedMs;
3063
3084
  }
3064
3085
  this.analytics?.discardSession(this.analyticsIdentity());
@@ -3066,6 +3087,27 @@ var DeepdotsPopups = class {
3066
3087
  this.tracking?.setSessionId(null);
3067
3088
  return null;
3068
3089
  }
3090
+ /**
3091
+ * `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
3092
+ * misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
3093
+ * (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
3094
+ * el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
3095
+ * #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
3096
+ * - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
3097
+ * - Más: el backend ya la cerró → se descarta sin enviar nada.
3098
+ * Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
3099
+ */
3100
+ closeStaleHiddenSession() {
3101
+ if (!this.sessionOpen || this.hiddenAt === null) return false;
3102
+ const hiddenFor = Date.now() - this.hiddenAt;
3103
+ if (hiddenFor < ANALYTICS_SESSION_TIMEOUT_MS) return false;
3104
+ if (hiddenFor < ANALYTICS_SESSION_DISCARD_MS) {
3105
+ this.closeSession("idle_timeout");
3106
+ } else {
3107
+ this.discardSession();
3108
+ }
3109
+ return true;
3110
+ }
3069
3111
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
3070
3112
  discardSession() {
3071
3113
  this.sessionOpen = false;
@@ -3114,7 +3156,8 @@ var DeepdotsPopups = class {
3114
3156
  if (typeof document === "undefined" || typeof window === "undefined") return;
3115
3157
  window.addEventListener("pagehide", () => {
3116
3158
  clearInterval(this.analyticsFlushTimer);
3117
- if (!this.suspendSession()) this.closeSession("page_hide");
3159
+ if (this.closeStaleHiddenSession()) return;
3160
+ if (!this.suspendSession("page_hide")) this.closeSession("page_hide");
3118
3161
  });
3119
3162
  window.addEventListener("pageshow", (event) => {
3120
3163
  if (!event.persisted) return;