@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
@@ -25,7 +25,7 @@ import {
25
25
  style_default,
26
26
  surveySdkCssUrls,
27
27
  surveySdkUrls
28
- } from "./chunk-FROREHRG.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-I6CPIR75.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-I6CPIR75.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;
@@ -2309,6 +2311,7 @@ var ANALYTICS_SESSION_TIMEOUT_MS = 30 * 6e4;
2309
2311
  var ANALYTICS_SERVER_IDLE_MS = 60 * 6e4;
2310
2312
  var ANALYTICS_SESSION_DISCARD_MS = ANALYTICS_SERVER_IDLE_MS - 10 * 6e4;
2311
2313
  var ANALYTICS_RESUME_WINDOW_MS = 6e4;
2314
+ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2312
2315
  var RESERVED_EVENT_PREFIX = "deepdots_";
2313
2316
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2314
2317
  var MAX_PENDING_TRIGGERS = 20;
@@ -2476,7 +2479,7 @@ var DeepdotsPopups = class {
2476
2479
  const resumable = this.readResumableSession();
2477
2480
  if (resumable) {
2478
2481
  this.analyticsFeedbackSessionId = resumable.sessionId;
2479
- this.suspended = { at: resumable.at, userId: resumable.userId };
2482
+ this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2480
2483
  }
2481
2484
  const analyticsSink = config.analytics ? createFeedbackSink({
2482
2485
  baseUrl: this.baseUrl,
@@ -2735,21 +2738,28 @@ var DeepdotsPopups = class {
2735
2738
  this.navObserver.visit(name);
2736
2739
  }
2737
2740
  }
2738
- /** 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
+ */
2739
2746
  onForeground() {
2740
2747
  this.engagement?.resume();
2741
2748
  this.openSession("foreground");
2742
2749
  }
2743
2750
  /**
2744
- * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
2745
- * (page_view), mini-services (mini_service_exit), emite engagement + `session_end` y
2746
- * envía el último lote con `completed:true`.
2747
- *
2748
- * 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.
2749
2759
  */
2750
2760
  onBackground() {
2751
2761
  this.cancelDelayedPopups("app to background");
2752
- this.closeSession("background");
2762
+ if (!this.suspendSession("background")) this.closeSession("background");
2753
2763
  this.engagement?.pause();
2754
2764
  }
2755
2765
  /**
@@ -2974,27 +2984,37 @@ var DeepdotsPopups = class {
2974
2984
  * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
2975
2985
  * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
2976
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
+ *
2977
2990
  * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
2978
- * 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.
2979
2993
  */
2980
- suspendSession() {
2994
+ suspendSession(reason) {
2981
2995
  if (!this.sessionOpen || !this.tracking?.isTrackingEnabled()) return false;
2982
2996
  const sessionId = this.analyticsFeedbackSessionId;
2983
2997
  const integration = this.analyticsIntegration;
2984
- const storage = getSessionStorage();
2985
- if (!sessionId || !integration || !storage) return false;
2998
+ if (!sessionId || !integration) return false;
2986
2999
  const at = Date.now();
2987
3000
  const userId = this.tracking.getUserId();
2988
- 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
+ }
2989
3005
  this.sessionOpen = false;
2990
- 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
+ };
2991
3011
  this.navObserver?.stop();
2992
3012
  this.navStarted = false;
2993
3013
  this.analytics?.exitAllMiniServices();
2994
3014
  this.flushEngagement();
2995
3015
  this.engagement?.pause();
2996
- this.track("deepdots_session_suspend", { reason: "page_hide" });
2997
- this.flushAnalytics({ final: true });
3016
+ this.track("deepdots_session_suspend", { reason });
3017
+ this.flushAnalytics(reason === "page_hide" ? { final: true } : { persist: true });
2998
3018
  this.log("tracking \xB7 session suspended:", sessionId);
2999
3019
  return true;
3000
3020
  }
@@ -3016,7 +3036,8 @@ var DeepdotsPopups = class {
3016
3036
  }
3017
3037
  /**
3018
3038
  * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
3019
- * 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.
3020
3041
  * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
3021
3042
  * se abre ahora va a uno nuevo.
3022
3043
  */
@@ -3027,7 +3048,7 @@ var DeepdotsPopups = class {
3027
3048
  const storage = getSessionStorage();
3028
3049
  if (storage) clearSuspendedSession(storage);
3029
3050
  const suspendedMs = Math.max(0, Date.now() - suspended.at);
3030
- 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)) {
3031
3052
  return suspendedMs;
3032
3053
  }
3033
3054
  this.analytics?.discardSession(this.analyticsIdentity());
@@ -3035,6 +3056,27 @@ var DeepdotsPopups = class {
3035
3056
  this.tracking?.setSessionId(null);
3036
3057
  return null;
3037
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
+ }
3038
3080
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
3039
3081
  discardSession() {
3040
3082
  this.sessionOpen = false;
@@ -3083,7 +3125,8 @@ var DeepdotsPopups = class {
3083
3125
  if (typeof document === "undefined" || typeof window === "undefined") return;
3084
3126
  window.addEventListener("pagehide", () => {
3085
3127
  clearInterval(this.analyticsFlushTimer);
3086
- if (!this.suspendSession()) this.closeSession("page_hide");
3128
+ if (this.closeStaleHiddenSession()) return;
3129
+ if (!this.suspendSession("page_hide")) this.closeSession("page_hide");
3087
3130
  });
3088
3131
  window.addEventListener("pageshow", (event) => {
3089
3132
  if (!event.persisted) return;