@magicfeedback/popup-sdk 1.12.0 → 1.14.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.
@@ -18,7 +18,7 @@ import {
18
18
  sdkWarn,
19
19
  setLogger,
20
20
  style_default
21
- } from "./chunk-TSORXOQG.mjs";
21
+ } from "./chunk-GUJSOVS6.mjs";
22
22
 
23
23
  // src/react-native/index.tsx
24
24
  import { createContext, useContext, useEffect, useRef, useState } from "react";
@@ -256,7 +256,7 @@ function trimmedOrNull(value) {
256
256
  }
257
257
  function buildSurveyHtml(opts) {
258
258
  const env = opts.env === "development" ? "dev" : "prod";
259
- const version = opts.version ?? "2.2.31";
259
+ const version = opts.version ?? "2.2.33";
260
260
  const cdn = `https://cdn.jsdelivr.net/npm/@magicfeedback/native@${version}/dist/magicfeedback-sdk.browser.js`;
261
261
  const sid = jsonForScript(opts.surveyId);
262
262
  const pid = jsonForScript(opts.productId);
@@ -895,7 +895,7 @@ function createReactNativeRenderer() {
895
895
  }
896
896
 
897
897
  // src/ui/preload.ts
898
- var defaultLoader = () => import("./renderPopup-JF6IB6HL.mjs");
898
+ var defaultLoader = () => import("./renderPopup-FAEZGWRS.mjs");
899
899
  var pending = null;
900
900
  function preloadRenderPopup(loader = defaultLoader) {
901
901
  if (pending) return pending;
@@ -968,7 +968,7 @@ var BrowserPopupRenderer = class {
968
968
  if (!this.container) return;
969
969
  this.visible = true;
970
970
  const container = this.container;
971
- void import("./renderPopup-JF6IB6HL.mjs").then(({ renderPopup }) => {
971
+ void import("./renderPopup-FAEZGWRS.mjs").then(({ renderPopup }) => {
972
972
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
973
973
  });
974
974
  }
@@ -1449,6 +1449,23 @@ var NavigationObserver = class {
1449
1449
  if (!this.installed || this.currentScreen != null || typeof window === "undefined") return;
1450
1450
  this.begin(window.location.href);
1451
1451
  }
1452
+ /**
1453
+ * La pantalla en curso, sin cerrarla ni emitir nada; null si no hay (antes de `begin`, tras
1454
+ * `stop`/`discard`). Para que el `user_engagement` lleve la pantalla: si el cierre de la
1455
+ * sesión no llega nunca (pestaña dormida y descartada, app matada), la última pantalla no
1456
+ * tiene `page_view` y solo queda esto.
1457
+ */
1458
+ current() {
1459
+ if (this.currentScreen == null) return null;
1460
+ return {
1461
+ screen: this.currentScreen,
1462
+ path: this.currentPath ?? this.currentScreen,
1463
+ seconds: this.secondsSinceEntry(this.now())
1464
+ };
1465
+ }
1466
+ secondsSinceEntry(at) {
1467
+ return Math.max(0, Math.round((at - this.entryAt) / 1e3));
1468
+ }
1452
1469
  closeCurrent() {
1453
1470
  if (this.currentScreen == null) return;
1454
1471
  const exit = this.now();
@@ -1457,7 +1474,7 @@ var NavigationObserver = class {
1457
1474
  path: this.currentPath ?? this.currentScreen,
1458
1475
  entry: this.entryAt,
1459
1476
  exit,
1460
- durationSeconds: Math.max(0, Math.round((exit - this.entryAt) / 1e3))
1477
+ durationSeconds: this.secondsSinceEntry(exit)
1461
1478
  };
1462
1479
  this.listeners.forEach((l) => {
1463
1480
  try {
@@ -2474,12 +2491,29 @@ var DeepdotsPopups = class {
2474
2491
  if (!this.tracking?.isTrackingEnabled()) return;
2475
2492
  this.analytics?.flush(this.analyticsIdentity(), options);
2476
2493
  }
2477
- /** Emite un evento `user_engagement` con el tiempo activo acumulado (#8). */
2494
+ /**
2495
+ * Emite un evento `user_engagement` con el tiempo activo acumulado (#8) y la pantalla en
2496
+ * curso: `screen` y `path` (los mismos que llevará su `page_view`) y `screen_seconds` (lo
2497
+ * que lleva en ella, medido como el `duration_seconds` del `page_view`).
2498
+ *
2499
+ * El `page_view` sale al SALIR de la pantalla; si el cierre no llega nunca (pestaña dormida
2500
+ * y descartada al volver, pestaña o app matada en segundo plano), la última pantalla de la
2501
+ * sesión se perdía y una visita de una sola pantalla se quedaba sin ninguna. Con la pantalla
2502
+ * en el latido y en el engagement de ocultar la pestaña, el backend la reconstruye.
2503
+ *
2504
+ * En los cierres (`closeSession`, `suspendSession`) el observador ya emitió el `page_view`
2505
+ * y no tiene pantalla, así que ese engagement va sin `screen`: nunca se cuenta dos veces.
2506
+ * Tampoco se emite un `page_view` aquí, por lo mismo.
2507
+ */
2478
2508
  flushEngagement() {
2479
2509
  if (!this.tracking?.isTrackingEnabled()) return;
2480
2510
  const ms = this.engagement?.consume() ?? 0;
2481
2511
  if (ms > 0) {
2482
- this.track("deepdots_user_engagement", { engagement_time_msec: ms });
2512
+ const current = this.navObserver?.current();
2513
+ this.track("deepdots_user_engagement", {
2514
+ engagement_time_msec: ms,
2515
+ ...current ? { screen: current.screen, path: current.path, screen_seconds: current.seconds } : {}
2516
+ });
2483
2517
  this.lastEngagementAt = Date.now();
2484
2518
  }
2485
2519
  }
@@ -3193,7 +3227,7 @@ var DeepdotsPopups = class {
3193
3227
  }
3194
3228
  if (!this.popupContainer) return;
3195
3229
  const container = this.popupContainer;
3196
- void import("./renderPopup-JF6IB6HL.mjs").then(({ renderPopup }) => {
3230
+ void import("./renderPopup-FAEZGWRS.mjs").then(({ renderPopup }) => {
3197
3231
  renderPopup(
3198
3232
  container,
3199
3233
  surveyId,