@magicfeedback/popup-sdk 1.10.0 → 1.11.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.
package/README.md CHANGED
@@ -215,6 +215,26 @@ const renderer = new ReactNativePopupRenderer({
215
215
  `onReady` is optional: a host that opens its container on `onShow` still never shows the spinner,
216
216
  because the HTML reveals itself; the container just appears a few hundred ms before the card.
217
217
 
218
+ ### Focus on text questions
219
+
220
+ When the first question of a page is a text field (text, long text, email or number), the cursor
221
+ is placed in it so the user can start typing:
222
+
223
+ - **When the popup opens:** only on devices with a mouse or trackpad (`pointer: fine`). On touch
224
+ devices it does nothing, so the keyboard never pops up over a popup the user has not touched.
225
+ - **After Start, Next or Back:** on every device, since the user has just tapped.
226
+
227
+ Only the first question counts: if the page starts with a rating and the text field comes after
228
+ it, nothing is focused. The focus is never taken away from a field of the host page.
229
+
230
+ The focus itself comes from `@magicfeedback/native` (its `autofocus` option, which the popup sets
231
+ to `'navigation'`, and `focusFirstQuestion()` when the popup is revealed). Versions of
232
+ `@magicfeedback/native` without that option simply ignore it.
233
+
234
+ In React Native on iOS, the WebView ignores focus set from JavaScript unless the keyboard is
235
+ allowed to open without a direct tap. `DeepdotsProvider` already does this; if you mount the
236
+ WebView yourself, add `keyboardDisplayRequiresUserAction={false}` to it.
237
+
218
238
  ### `autoLaunch()`
219
239
 
220
240
  Starts the triggers derived from the popup definitions loaded during `init()`.
@@ -237,6 +257,8 @@ Example:
237
257
  popups.triggerEvent('search');
238
258
  ```
239
259
 
260
+ It can be called right after `init()`: if the popup definitions are still loading, the event is kept and evaluated as soon as they arrive (the same applies to `triggerSurvey`).
261
+
240
262
  ### `triggerSurvey(surveyId, popupId?)`
241
263
 
242
264
  Opens a specific survey directly, bypassing trigger evaluation.
@@ -500,7 +522,7 @@ interface DeepdotsEvent {
500
522
  - `action`
501
523
  - `userId`
502
524
 
503
- `popup_clicked` is a general interaction event. Depending on the flow, `data.action` can contain values such as `loaded`, `start_survey`, `manual_send`, `back`, `complete`, or `close_icon`.
525
+ `popup_clicked` means the user did something in the popup. On the web, `data.action` is one of `start_survey`, `manual_send`, `back`, `complete`, `close_icon`, or `partial` (the user answered a page and moved on; this one also marks the popup as `PARTIAL` in the backend). Loading the survey, the start of a submit, and validation or submit errors are not interactions and do not emit it. In React Native the bridge emits it once per popup, with `action: 'partial'`, on the first real interaction (sending an answer or going back).
504
526
 
505
527
  ## Important Behavior Notes
506
528
 
package/dist/index.d.mts CHANGED
@@ -188,6 +188,11 @@ interface FeedbackSinkOptions {
188
188
  * romper a quien lo pase.
189
189
  */
190
190
  sendBeaconImpl?: (url: string, body: Blob | string) => boolean;
191
+ /**
192
+ * Registro en el que seguir desde el primer lote: el de una sesión suspendida por un
193
+ * `pagehide` y reanudada tras recargar la página (ver `suspended-session.ts`).
194
+ */
195
+ initialSessionId?: string;
191
196
  /** Callback invocado cuando el backend devuelve un nuevo sessionId (primer POST). */
192
197
  onSessionId?: (id: string) => void;
193
198
  /** Callback invocado al cerrar la sesión (`completed:true`): el sessionId cacheado se olvida. */
@@ -708,6 +713,14 @@ declare class DeepdotsPopups {
708
713
  private popupContainer;
709
714
  private popupDefinitions;
710
715
  private popupsLoaded;
716
+ /**
717
+ * `true` mientras el `GET /sdk/{apiKey}/popups` de `init()` está en vuelo. En esa ventana los
718
+ * disparos del host (`triggerEvent`, `triggerSurvey`) no tienen contra qué evaluarse, así que
719
+ * se guardan en `pendingTriggers` y se reproducen al cargar. Click, scroll, time y exit no
720
+ * hacen falta: son listeners que `autoLaunch` instala ya con las definiciones cargadas.
721
+ */
722
+ private awaitingPopups;
723
+ private pendingTriggers;
711
724
  private pendingAutoLaunch;
712
725
  private answeredSurveys;
713
726
  private surveyProgress;
@@ -756,6 +769,13 @@ declare class DeepdotsPopups {
756
769
  private lastEngagementAt;
757
770
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
758
771
  private hiddenAt;
772
+ /**
773
+ * Sesión suspendida por un `pagehide` (ms epoch y `deepdots_user_id`); null si no hay.
774
+ * `openSession` la reanuda si sigue a tiempo (ver ANALYTICS_RESUME_WINDOW_MS).
775
+ */
776
+ private suspended;
777
+ /** Integración de analytics del init: la sesión suspendida solo la hereda la misma. */
778
+ private analyticsIntegration;
759
779
  /**
760
780
  * Idioma resuelto en init() (explícito > navigator.language > Intl). Única fuente de
761
781
  * verdad para el context de analytics Y para la segmentación por idioma de los popups.
@@ -898,6 +918,31 @@ declare class DeepdotsPopups {
898
918
  * - Más: ya la cerró el backend → se descarta sin enviar nada.
899
919
  */
900
920
  private onDocumentVisible;
921
+ /**
922
+ * `pagehide` en web: SUSPENDE la sesión en vez de cerrarla, porque el navegador lo lanza
923
+ * igual al recargar que al cerrar la pestaña. Vuelca lo pendiente (page_view de la
924
+ * pantalla, mini-services, engagement) con un `deepdots_session_suspend` y SIN
925
+ * `completed`, y deja el registro en `sessionStorage` (ver `suspended-session.ts`):
926
+ * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
927
+ * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
928
+ *
929
+ * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
930
+ * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
931
+ */
932
+ private suspendSession;
933
+ /**
934
+ * Recoge la sesión que dejó suspendida la carga anterior de esta pestaña (ver
935
+ * `suspendSession`). Solo con analytics configurado y el tracking activo: sin ellos no hay
936
+ * registro en el que seguir.
937
+ */
938
+ private readResumableSession;
939
+ /**
940
+ * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
941
+ * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
942
+ * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
943
+ * se abre ahora va a uno nuevo.
944
+ */
945
+ private takeSuspendedSession;
901
946
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
902
947
  private discardSession;
903
948
  /**
@@ -923,6 +968,17 @@ declare class DeepdotsPopups {
923
968
  triggerSurvey(surveyId: string, popupId?: string): void;
924
969
  /** Trigger popups configured with trigger.type = 'event' and matching trigger.value */
925
970
  triggerEvent(eventName: string): void;
971
+ private evaluateEvent;
972
+ /**
973
+ * Guarda `trigger` si las definiciones aún no han llegado. Devuelve `true` si lo guardó (el
974
+ * llamador no debe evaluarlo ahora) y `false` si no hay carga en vuelo (se evalúa ya, como
975
+ * siempre: tras cargar, tras un fallo o sin apiKey).
976
+ */
977
+ private bufferIfAwaitingPopups;
978
+ /** La carga falló: sin definiciones no hay nada que reproducir, se descarta todo. */
979
+ private dropPendingTriggers;
980
+ /** Reproduce en orden por la evaluación normal (segmentos, cooldowns y condiciones de AHORA). */
981
+ private replayPendingTriggers;
926
982
  private showDefinition;
927
983
  private shouldShow;
928
984
  private matchesSegmentsLang;
@@ -961,7 +1017,7 @@ declare class DeepdotsPopups {
961
1017
  private removeDeferredExitPopup;
962
1018
  private getDeferredExitQueue;
963
1019
  private setDeferredExitQueue;
964
- /** Fetch al servidor para obtener popups */
1020
+ /** Fetch al servidor para obtener popups. `null` si la carga falló (red, no-2xx, payload inválido). */
965
1021
  private fetchPopupsFromServer;
966
1022
  /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
967
1023
  private postContact;
package/dist/index.d.ts CHANGED
@@ -188,6 +188,11 @@ interface FeedbackSinkOptions {
188
188
  * romper a quien lo pase.
189
189
  */
190
190
  sendBeaconImpl?: (url: string, body: Blob | string) => boolean;
191
+ /**
192
+ * Registro en el que seguir desde el primer lote: el de una sesión suspendida por un
193
+ * `pagehide` y reanudada tras recargar la página (ver `suspended-session.ts`).
194
+ */
195
+ initialSessionId?: string;
191
196
  /** Callback invocado cuando el backend devuelve un nuevo sessionId (primer POST). */
192
197
  onSessionId?: (id: string) => void;
193
198
  /** Callback invocado al cerrar la sesión (`completed:true`): el sessionId cacheado se olvida. */
@@ -708,6 +713,14 @@ declare class DeepdotsPopups {
708
713
  private popupContainer;
709
714
  private popupDefinitions;
710
715
  private popupsLoaded;
716
+ /**
717
+ * `true` mientras el `GET /sdk/{apiKey}/popups` de `init()` está en vuelo. En esa ventana los
718
+ * disparos del host (`triggerEvent`, `triggerSurvey`) no tienen contra qué evaluarse, así que
719
+ * se guardan en `pendingTriggers` y se reproducen al cargar. Click, scroll, time y exit no
720
+ * hacen falta: son listeners que `autoLaunch` instala ya con las definiciones cargadas.
721
+ */
722
+ private awaitingPopups;
723
+ private pendingTriggers;
711
724
  private pendingAutoLaunch;
712
725
  private answeredSurveys;
713
726
  private surveyProgress;
@@ -756,6 +769,13 @@ declare class DeepdotsPopups {
756
769
  private lastEngagementAt;
757
770
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
758
771
  private hiddenAt;
772
+ /**
773
+ * Sesión suspendida por un `pagehide` (ms epoch y `deepdots_user_id`); null si no hay.
774
+ * `openSession` la reanuda si sigue a tiempo (ver ANALYTICS_RESUME_WINDOW_MS).
775
+ */
776
+ private suspended;
777
+ /** Integración de analytics del init: la sesión suspendida solo la hereda la misma. */
778
+ private analyticsIntegration;
759
779
  /**
760
780
  * Idioma resuelto en init() (explícito > navigator.language > Intl). Única fuente de
761
781
  * verdad para el context de analytics Y para la segmentación por idioma de los popups.
@@ -898,6 +918,31 @@ declare class DeepdotsPopups {
898
918
  * - Más: ya la cerró el backend → se descarta sin enviar nada.
899
919
  */
900
920
  private onDocumentVisible;
921
+ /**
922
+ * `pagehide` en web: SUSPENDE la sesión en vez de cerrarla, porque el navegador lo lanza
923
+ * igual al recargar que al cerrar la pestaña. Vuelca lo pendiente (page_view de la
924
+ * pantalla, mini-services, engagement) con un `deepdots_session_suspend` y SIN
925
+ * `completed`, y deja el registro en `sessionStorage` (ver `suspended-session.ts`):
926
+ * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
927
+ * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
928
+ *
929
+ * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
930
+ * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
931
+ */
932
+ private suspendSession;
933
+ /**
934
+ * Recoge la sesión que dejó suspendida la carga anterior de esta pestaña (ver
935
+ * `suspendSession`). Solo con analytics configurado y el tracking activo: sin ellos no hay
936
+ * registro en el que seguir.
937
+ */
938
+ private readResumableSession;
939
+ /**
940
+ * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
941
+ * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
942
+ * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
943
+ * se abre ahora va a uno nuevo.
944
+ */
945
+ private takeSuspendedSession;
901
946
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
902
947
  private discardSession;
903
948
  /**
@@ -923,6 +968,17 @@ declare class DeepdotsPopups {
923
968
  triggerSurvey(surveyId: string, popupId?: string): void;
924
969
  /** Trigger popups configured with trigger.type = 'event' and matching trigger.value */
925
970
  triggerEvent(eventName: string): void;
971
+ private evaluateEvent;
972
+ /**
973
+ * Guarda `trigger` si las definiciones aún no han llegado. Devuelve `true` si lo guardó (el
974
+ * llamador no debe evaluarlo ahora) y `false` si no hay carga en vuelo (se evalúa ya, como
975
+ * siempre: tras cargar, tras un fallo o sin apiKey).
976
+ */
977
+ private bufferIfAwaitingPopups;
978
+ /** La carga falló: sin definiciones no hay nada que reproducir, se descarta todo. */
979
+ private dropPendingTriggers;
980
+ /** Reproduce en orden por la evaluación normal (segmentos, cooldowns y condiciones de AHORA). */
981
+ private replayPendingTriggers;
926
982
  private showDefinition;
927
983
  private shouldShow;
928
984
  private matchesSegmentsLang;
@@ -961,7 +1017,7 @@ declare class DeepdotsPopups {
961
1017
  private removeDeferredExitPopup;
962
1018
  private getDeferredExitQueue;
963
1019
  private setDeferredExitQueue;
964
- /** Fetch al servidor para obtener popups */
1020
+ /** Fetch al servidor para obtener popups. `null` si la carga falló (red, no-2xx, payload inválido). */
965
1021
  private fetchPopupsFromServer;
966
1022
  /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
967
1023
  private postContact;