@magicfeedback/popup-sdk 1.20.0 → 1.21.1
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/dist/{chunk-ZJ5HG3QF.mjs → chunk-4C3DSMUT.mjs} +2 -2
- package/dist/{chunk-OPR5I7WO.mjs → chunk-7KMBH25G.mjs} +2 -2
- package/dist/{chunk-FROREHRG.mjs → chunk-NNWYOG43.mjs} +2 -2
- package/dist/index.d.mts +38 -8
- package/dist/index.d.ts +38 -8
- package/dist/index.js +100 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -31
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.d.mts +38 -8
- package/dist/index.native.d.ts +38 -8
- package/dist/index.native.js +117 -39
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +119 -41
- package/dist/index.native.mjs.map +1 -1
- package/dist/react-native.d.mts +32 -8
- package/dist/react-native.d.ts +32 -8
- package/dist/react-native.js +117 -39
- package/dist/react-native.js.map +1 -1
- package/dist/react-native.mjs +119 -41
- package/dist/react-native.mjs.map +1 -1
- package/dist/{renderPopup-I6CPIR75.mjs → renderPopup-IKPXPDB7.mjs} +2 -2
- package/dist/{renderPopup-RUY3OBYV.mjs → renderPopup-M5ZIXNV6.mjs} +2 -2
- package/dist/{renderPopup-XNVNP2ZU.mjs → renderPopup-QVMBE4L4.mjs} +2 -2
- package/package.json +1 -1
- /package/dist/{chunk-ZJ5HG3QF.mjs.map → chunk-4C3DSMUT.mjs.map} +0 -0
- /package/dist/{chunk-OPR5I7WO.mjs.map → chunk-7KMBH25G.mjs.map} +0 -0
- /package/dist/{chunk-FROREHRG.mjs.map → chunk-NNWYOG43.mjs.map} +0 -0
- /package/dist/{renderPopup-I6CPIR75.mjs.map → renderPopup-IKPXPDB7.mjs.map} +0 -0
- /package/dist/{renderPopup-RUY3OBYV.mjs.map → renderPopup-M5ZIXNV6.mjs.map} +0 -0
- /package/dist/{renderPopup-XNVNP2ZU.mjs.map → renderPopup-QVMBE4L4.mjs.map} +0 -0
package/dist/index.native.d.mts
CHANGED
|
@@ -146,6 +146,12 @@ interface AnalyticsFlushMeta {
|
|
|
146
146
|
* registro nuevo, igual que tras `sessionEnd`, pero sin POST.
|
|
147
147
|
*/
|
|
148
148
|
resetSession?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* `true` cuando el lote puede ser lo último que salga de la sesión sin cerrarla (app a
|
|
151
|
+
* background en RN: la sesión queda suspendida). El sink lo guarda ANTES de enviarlo, como
|
|
152
|
+
* el lote de cierre, para reenviarlo en el arranque siguiente si el SO mata la app.
|
|
153
|
+
*/
|
|
154
|
+
persist?: boolean;
|
|
149
155
|
}
|
|
150
156
|
/**
|
|
151
157
|
* Envío del lote. Si devuelve una promesa que **rechaza**, el manager re-encola los
|
|
@@ -1056,14 +1062,21 @@ declare class DeepdotsPopups {
|
|
|
1056
1062
|
* El host la llama en cada cambio de pantalla; emite `page_view` al salir de la anterior.
|
|
1057
1063
|
*/
|
|
1058
1064
|
setScreen(name: string): void;
|
|
1059
|
-
/**
|
|
1065
|
+
/**
|
|
1066
|
+
* App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
|
|
1067
|
+
* background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
|
|
1068
|
+
* (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
|
|
1069
|
+
*/
|
|
1060
1070
|
onForeground(): void;
|
|
1061
1071
|
/**
|
|
1062
|
-
* App a background (RN: AppState 'background'):
|
|
1063
|
-
* (page_view), mini-services (mini_service_exit)
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1072
|
+
* App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
|
|
1073
|
+
* actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
|
|
1074
|
+
* `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
|
|
1075
|
+
* - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
|
|
1076
|
+
* en el mismo registro;
|
|
1077
|
+
* - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
|
|
1078
|
+
* minutos con un `session_end` `background` a la hora de la suspensión.
|
|
1079
|
+
* Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
|
|
1067
1080
|
*/
|
|
1068
1081
|
onBackground(): void;
|
|
1069
1082
|
/**
|
|
@@ -1135,6 +1148,7 @@ declare class DeepdotsPopups {
|
|
|
1135
1148
|
flushAnalytics(options?: {
|
|
1136
1149
|
final?: boolean;
|
|
1137
1150
|
sessionEnd?: boolean;
|
|
1151
|
+
persist?: boolean;
|
|
1138
1152
|
}): void;
|
|
1139
1153
|
/**
|
|
1140
1154
|
* Emite un evento `user_engagement` con el tiempo activo acumulado (#8) y la pantalla en
|
|
@@ -1170,8 +1184,12 @@ declare class DeepdotsPopups {
|
|
|
1170
1184
|
* - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
|
|
1171
1185
|
* - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
|
|
1172
1186
|
*
|
|
1187
|
+
* En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
|
|
1188
|
+
* background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
|
|
1189
|
+
*
|
|
1173
1190
|
* Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
|
|
1174
|
-
* POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra
|
|
1191
|
+
* POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
|
|
1192
|
+
* como antes.
|
|
1175
1193
|
*/
|
|
1176
1194
|
private suspendSession;
|
|
1177
1195
|
/**
|
|
@@ -1182,11 +1200,23 @@ declare class DeepdotsPopups {
|
|
|
1182
1200
|
private readResumableSession;
|
|
1183
1201
|
/**
|
|
1184
1202
|
* Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
|
|
1185
|
-
* ella (mismo usuario, dentro de
|
|
1203
|
+
* ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
|
|
1204
|
+
* ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
|
|
1186
1205
|
* En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
|
|
1187
1206
|
* se abre ahora va a uno nuevo.
|
|
1188
1207
|
*/
|
|
1189
1208
|
private takeSuspendedSession;
|
|
1209
|
+
/**
|
|
1210
|
+
* `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
|
|
1211
|
+
* misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
|
|
1212
|
+
* (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
|
|
1213
|
+
* el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
|
|
1214
|
+
* #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
|
|
1215
|
+
* - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
|
|
1216
|
+
* - Más: el backend ya la cerró → se descarta sin enviar nada.
|
|
1217
|
+
* Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
|
|
1218
|
+
*/
|
|
1219
|
+
private closeStaleHiddenSession;
|
|
1190
1220
|
/** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
|
|
1191
1221
|
private discardSession;
|
|
1192
1222
|
/**
|
package/dist/index.native.d.ts
CHANGED
|
@@ -146,6 +146,12 @@ interface AnalyticsFlushMeta {
|
|
|
146
146
|
* registro nuevo, igual que tras `sessionEnd`, pero sin POST.
|
|
147
147
|
*/
|
|
148
148
|
resetSession?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* `true` cuando el lote puede ser lo último que salga de la sesión sin cerrarla (app a
|
|
151
|
+
* background en RN: la sesión queda suspendida). El sink lo guarda ANTES de enviarlo, como
|
|
152
|
+
* el lote de cierre, para reenviarlo en el arranque siguiente si el SO mata la app.
|
|
153
|
+
*/
|
|
154
|
+
persist?: boolean;
|
|
149
155
|
}
|
|
150
156
|
/**
|
|
151
157
|
* Envío del lote. Si devuelve una promesa que **rechaza**, el manager re-encola los
|
|
@@ -1056,14 +1062,21 @@ declare class DeepdotsPopups {
|
|
|
1056
1062
|
* El host la llama en cada cambio de pantalla; emite `page_view` al salir de la anterior.
|
|
1057
1063
|
*/
|
|
1058
1064
|
setScreen(name: string): void;
|
|
1059
|
-
/**
|
|
1065
|
+
/**
|
|
1066
|
+
* App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
|
|
1067
|
+
* background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
|
|
1068
|
+
* (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
|
|
1069
|
+
*/
|
|
1060
1070
|
onForeground(): void;
|
|
1061
1071
|
/**
|
|
1062
|
-
* App a background (RN: AppState 'background'):
|
|
1063
|
-
* (page_view), mini-services (mini_service_exit)
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1072
|
+
* App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
|
|
1073
|
+
* actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
|
|
1074
|
+
* `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
|
|
1075
|
+
* - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
|
|
1076
|
+
* en el mismo registro;
|
|
1077
|
+
* - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
|
|
1078
|
+
* minutos con un `session_end` `background` a la hora de la suspensión.
|
|
1079
|
+
* Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
|
|
1067
1080
|
*/
|
|
1068
1081
|
onBackground(): void;
|
|
1069
1082
|
/**
|
|
@@ -1135,6 +1148,7 @@ declare class DeepdotsPopups {
|
|
|
1135
1148
|
flushAnalytics(options?: {
|
|
1136
1149
|
final?: boolean;
|
|
1137
1150
|
sessionEnd?: boolean;
|
|
1151
|
+
persist?: boolean;
|
|
1138
1152
|
}): void;
|
|
1139
1153
|
/**
|
|
1140
1154
|
* Emite un evento `user_engagement` con el tiempo activo acumulado (#8) y la pantalla en
|
|
@@ -1170,8 +1184,12 @@ declare class DeepdotsPopups {
|
|
|
1170
1184
|
* - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
|
|
1171
1185
|
* - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
|
|
1172
1186
|
*
|
|
1187
|
+
* En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
|
|
1188
|
+
* background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
|
|
1189
|
+
*
|
|
1173
1190
|
* Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
|
|
1174
|
-
* POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra
|
|
1191
|
+
* POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
|
|
1192
|
+
* como antes.
|
|
1175
1193
|
*/
|
|
1176
1194
|
private suspendSession;
|
|
1177
1195
|
/**
|
|
@@ -1182,11 +1200,23 @@ declare class DeepdotsPopups {
|
|
|
1182
1200
|
private readResumableSession;
|
|
1183
1201
|
/**
|
|
1184
1202
|
* Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
|
|
1185
|
-
* ella (mismo usuario, dentro de
|
|
1203
|
+
* ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
|
|
1204
|
+
* ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
|
|
1186
1205
|
* En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
|
|
1187
1206
|
* se abre ahora va a uno nuevo.
|
|
1188
1207
|
*/
|
|
1189
1208
|
private takeSuspendedSession;
|
|
1209
|
+
/**
|
|
1210
|
+
* `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
|
|
1211
|
+
* misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
|
|
1212
|
+
* (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
|
|
1213
|
+
* el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
|
|
1214
|
+
* #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
|
|
1215
|
+
* - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
|
|
1216
|
+
* - Más: el backend ya la cerró → se descarta sin enviar nada.
|
|
1217
|
+
* Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
|
|
1218
|
+
*/
|
|
1219
|
+
private closeStaleHiddenSession;
|
|
1190
1220
|
/** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
|
|
1191
1221
|
private discardSession;
|
|
1192
1222
|
/**
|
package/dist/index.native.js
CHANGED
|
@@ -38,7 +38,7 @@ var SDK_VERSION, SDK_IDENTIFIER, POPUP_CHANNEL;
|
|
|
38
38
|
var init_version = __esm({
|
|
39
39
|
"src/version.ts"() {
|
|
40
40
|
"use strict";
|
|
41
|
-
SDK_VERSION = "1.
|
|
41
|
+
SDK_VERSION = "1.21.1";
|
|
42
42
|
SDK_IDENTIFIER = `${"react-native"}@${SDK_VERSION}`;
|
|
43
43
|
POPUP_CHANNEL = "popup";
|
|
44
44
|
}
|
|
@@ -12034,13 +12034,26 @@ function resolveBackgroundTask(explicit, platform) {
|
|
|
12034
12034
|
}
|
|
12035
12035
|
var DEFAULT_REJECTION_WHITELIST = [ReferenceError, TypeError, RangeError];
|
|
12036
12036
|
function createHermesRejectionHub(hermes, options) {
|
|
12037
|
-
|
|
12038
|
-
|
|
12037
|
+
let original;
|
|
12038
|
+
try {
|
|
12039
|
+
if (!hermes || typeof hermes.enablePromiseRejectionTracker !== "function") return null;
|
|
12040
|
+
original = hermes.enablePromiseRejectionTracker.bind(hermes);
|
|
12041
|
+
} catch {
|
|
12042
|
+
return null;
|
|
12043
|
+
}
|
|
12039
12044
|
const listeners = /* @__PURE__ */ new Set();
|
|
12040
12045
|
let hostOptions = null;
|
|
12041
12046
|
let active2 = false;
|
|
12042
12047
|
const forwardsToHost = (error) => !!hostOptions?.onUnhandled && (hostOptions.allRejections === true || DEFAULT_REJECTION_WHITELIST.some((type) => error instanceof type));
|
|
12043
12048
|
const apply = () => {
|
|
12049
|
+
try {
|
|
12050
|
+
install();
|
|
12051
|
+
return true;
|
|
12052
|
+
} catch {
|
|
12053
|
+
return false;
|
|
12054
|
+
}
|
|
12055
|
+
};
|
|
12056
|
+
const install = () => {
|
|
12044
12057
|
original({
|
|
12045
12058
|
allRejections: true,
|
|
12046
12059
|
onUnhandled: (id, error) => {
|
|
@@ -12059,17 +12072,17 @@ function createHermesRejectionHub(hermes, options) {
|
|
|
12059
12072
|
onHandled: (id, error) => hostOptions?.onHandled?.(id, error)
|
|
12060
12073
|
});
|
|
12061
12074
|
};
|
|
12062
|
-
|
|
12075
|
+
const wrapper = (next) => {
|
|
12063
12076
|
hostOptions = next ?? null;
|
|
12064
|
-
if (active2)
|
|
12077
|
+
if (active2) install();
|
|
12065
12078
|
else original(next);
|
|
12066
12079
|
};
|
|
12080
|
+
if (!replaceTracker(hermes, wrapper)) return null;
|
|
12067
12081
|
return {
|
|
12068
12082
|
addUnhandledListener(listener) {
|
|
12069
12083
|
listeners.add(listener);
|
|
12070
12084
|
if (!active2) {
|
|
12071
|
-
active2 =
|
|
12072
|
-
apply();
|
|
12085
|
+
active2 = apply();
|
|
12073
12086
|
}
|
|
12074
12087
|
return () => {
|
|
12075
12088
|
listeners.delete(listener);
|
|
@@ -12077,22 +12090,44 @@ function createHermesRejectionHub(hermes, options) {
|
|
|
12077
12090
|
}
|
|
12078
12091
|
};
|
|
12079
12092
|
}
|
|
12093
|
+
var TRACKER_KEY = "enablePromiseRejectionTracker";
|
|
12094
|
+
function replaceTracker(hermes, wrapper) {
|
|
12095
|
+
try {
|
|
12096
|
+
const own = Object.getOwnPropertyDescriptor(hermes, TRACKER_KEY);
|
|
12097
|
+
if (own && own.writable === false && !own.set) {
|
|
12098
|
+
if (!own.configurable) return false;
|
|
12099
|
+
Object.defineProperty(hermes, TRACKER_KEY, { ...own, value: wrapper });
|
|
12100
|
+
} else {
|
|
12101
|
+
hermes.enablePromiseRejectionTracker = wrapper;
|
|
12102
|
+
}
|
|
12103
|
+
return hermes.enablePromiseRejectionTracker === wrapper;
|
|
12104
|
+
} catch {
|
|
12105
|
+
return false;
|
|
12106
|
+
}
|
|
12107
|
+
}
|
|
12080
12108
|
|
|
12081
12109
|
// src/platform/react-native-defaults.ts
|
|
12082
12110
|
var hub;
|
|
12083
12111
|
function registerReactNativeDefaults(rn) {
|
|
12084
12112
|
if (hub === void 0) {
|
|
12085
|
-
|
|
12086
|
-
|
|
12087
|
-
|
|
12088
|
-
|
|
12113
|
+
try {
|
|
12114
|
+
hub = getReactNativePlatform()?.promiseRejections ?? createHermesRejectionHub(
|
|
12115
|
+
globalThis.HermesInternal,
|
|
12116
|
+
{ dev: typeof __DEV__ !== "undefined" && !!__DEV__ }
|
|
12117
|
+
);
|
|
12118
|
+
} catch {
|
|
12119
|
+
hub = null;
|
|
12120
|
+
}
|
|
12121
|
+
}
|
|
12122
|
+
try {
|
|
12123
|
+
registerReactNativePlatform({
|
|
12124
|
+
os: rn.Platform.OS,
|
|
12125
|
+
appState: rn.AppState,
|
|
12126
|
+
backgroundTaskModule: rn.NativeModules?.DeepdotsBackgroundTask ?? null,
|
|
12127
|
+
promiseRejections: hub
|
|
12128
|
+
});
|
|
12129
|
+
} catch {
|
|
12089
12130
|
}
|
|
12090
|
-
registerReactNativePlatform({
|
|
12091
|
-
os: rn.Platform.OS,
|
|
12092
|
-
appState: rn.AppState,
|
|
12093
|
-
backgroundTaskModule: rn.NativeModules?.DeepdotsBackgroundTask ?? null,
|
|
12094
|
-
promiseRejections: hub
|
|
12095
|
-
});
|
|
12096
12131
|
}
|
|
12097
12132
|
|
|
12098
12133
|
// src/types/index.ts
|
|
@@ -13632,9 +13667,11 @@ function createFeedbackSink(options) {
|
|
|
13632
13667
|
const body = buildAnalyticsFeedbackBody(envelope, options.keys, feedbackSessionId, { sessionEnd });
|
|
13633
13668
|
options.log?.("[DeepdotsAnalytics] POST /sdk/feedback \u2192", body);
|
|
13634
13669
|
const batch = { body, at: now() };
|
|
13635
|
-
if (sessionEnd) {
|
|
13636
|
-
|
|
13637
|
-
|
|
13670
|
+
if (sessionEnd || meta?.persist) {
|
|
13671
|
+
if (sessionEnd) {
|
|
13672
|
+
feedbackSessionId = void 0;
|
|
13673
|
+
options.onSessionReset?.();
|
|
13674
|
+
}
|
|
13638
13675
|
addPending(batch);
|
|
13639
13676
|
await drain();
|
|
13640
13677
|
return;
|
|
@@ -14331,6 +14368,7 @@ var ANALYTICS_SESSION_TIMEOUT_MS = 30 * 6e4;
|
|
|
14331
14368
|
var ANALYTICS_SERVER_IDLE_MS = 60 * 6e4;
|
|
14332
14369
|
var ANALYTICS_SESSION_DISCARD_MS = ANALYTICS_SERVER_IDLE_MS - 10 * 6e4;
|
|
14333
14370
|
var ANALYTICS_RESUME_WINDOW_MS = 6e4;
|
|
14371
|
+
var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
|
|
14334
14372
|
var RESERVED_EVENT_PREFIX = "deepdots_";
|
|
14335
14373
|
var CUSTOM_EVENT_PREFIX = "deepdots_event_";
|
|
14336
14374
|
var MAX_PENDING_TRIGGERS = 20;
|
|
@@ -14498,7 +14536,7 @@ var DeepdotsPopups = class {
|
|
|
14498
14536
|
const resumable = this.readResumableSession();
|
|
14499
14537
|
if (resumable) {
|
|
14500
14538
|
this.analyticsFeedbackSessionId = resumable.sessionId;
|
|
14501
|
-
this.suspended = { at: resumable.at, userId: resumable.userId };
|
|
14539
|
+
this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
|
|
14502
14540
|
}
|
|
14503
14541
|
const analyticsSink = config.analytics ? createFeedbackSink({
|
|
14504
14542
|
baseUrl: this.baseUrl,
|
|
@@ -14757,21 +14795,28 @@ var DeepdotsPopups = class {
|
|
|
14757
14795
|
this.navObserver.visit(name);
|
|
14758
14796
|
}
|
|
14759
14797
|
}
|
|
14760
|
-
/**
|
|
14798
|
+
/**
|
|
14799
|
+
* App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
|
|
14800
|
+
* background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
|
|
14801
|
+
* (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
|
|
14802
|
+
*/
|
|
14761
14803
|
onForeground() {
|
|
14762
14804
|
this.engagement?.resume();
|
|
14763
14805
|
this.openSession("foreground");
|
|
14764
14806
|
}
|
|
14765
14807
|
/**
|
|
14766
|
-
* App a background (RN: AppState 'background'):
|
|
14767
|
-
* (page_view), mini-services (mini_service_exit)
|
|
14768
|
-
*
|
|
14769
|
-
*
|
|
14770
|
-
*
|
|
14808
|
+
* App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
|
|
14809
|
+
* actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
|
|
14810
|
+
* `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
|
|
14811
|
+
* - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
|
|
14812
|
+
* en el mismo registro;
|
|
14813
|
+
* - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
|
|
14814
|
+
* minutos con un `session_end` `background` a la hora de la suspensión.
|
|
14815
|
+
* Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
|
|
14771
14816
|
*/
|
|
14772
14817
|
onBackground() {
|
|
14773
14818
|
this.cancelDelayedPopups("app to background");
|
|
14774
|
-
this.closeSession("background");
|
|
14819
|
+
if (!this.suspendSession("background")) this.closeSession("background");
|
|
14775
14820
|
this.engagement?.pause();
|
|
14776
14821
|
}
|
|
14777
14822
|
/**
|
|
@@ -14996,27 +15041,37 @@ var DeepdotsPopups = class {
|
|
|
14996
15041
|
* - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
|
|
14997
15042
|
* - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
|
|
14998
15043
|
*
|
|
15044
|
+
* En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
|
|
15045
|
+
* background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
|
|
15046
|
+
*
|
|
14999
15047
|
* Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
|
|
15000
|
-
* POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra
|
|
15048
|
+
* POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
|
|
15049
|
+
* como antes.
|
|
15001
15050
|
*/
|
|
15002
|
-
suspendSession() {
|
|
15051
|
+
suspendSession(reason) {
|
|
15003
15052
|
if (!this.sessionOpen || !this.tracking?.isTrackingEnabled()) return false;
|
|
15004
15053
|
const sessionId = this.analyticsFeedbackSessionId;
|
|
15005
15054
|
const integration = this.analyticsIntegration;
|
|
15006
|
-
|
|
15007
|
-
if (!sessionId || !integration || !storage) return false;
|
|
15055
|
+
if (!sessionId || !integration) return false;
|
|
15008
15056
|
const at = Date.now();
|
|
15009
15057
|
const userId = this.tracking.getUserId();
|
|
15010
|
-
if (
|
|
15058
|
+
if (reason === "page_hide") {
|
|
15059
|
+
const storage = getSessionStorage();
|
|
15060
|
+
if (!storage || !writeSuspendedSession(storage, { sessionId, integration, userId, at })) return false;
|
|
15061
|
+
}
|
|
15011
15062
|
this.sessionOpen = false;
|
|
15012
|
-
this.suspended = {
|
|
15063
|
+
this.suspended = {
|
|
15064
|
+
at,
|
|
15065
|
+
userId,
|
|
15066
|
+
windowMs: reason === "page_hide" ? ANALYTICS_RESUME_WINDOW_MS : ANALYTICS_BACKGROUND_RESUME_WINDOW_MS
|
|
15067
|
+
};
|
|
15013
15068
|
this.navObserver?.stop();
|
|
15014
15069
|
this.navStarted = false;
|
|
15015
15070
|
this.analytics?.exitAllMiniServices();
|
|
15016
15071
|
this.flushEngagement();
|
|
15017
15072
|
this.engagement?.pause();
|
|
15018
|
-
this.track("deepdots_session_suspend", { reason
|
|
15019
|
-
this.flushAnalytics({ final: true });
|
|
15073
|
+
this.track("deepdots_session_suspend", { reason });
|
|
15074
|
+
this.flushAnalytics(reason === "page_hide" ? { final: true } : { persist: true });
|
|
15020
15075
|
this.log("tracking \xB7 session suspended:", sessionId);
|
|
15021
15076
|
return true;
|
|
15022
15077
|
}
|
|
@@ -15038,7 +15093,8 @@ var DeepdotsPopups = class {
|
|
|
15038
15093
|
}
|
|
15039
15094
|
/**
|
|
15040
15095
|
* Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
|
|
15041
|
-
* ella (mismo usuario, dentro de
|
|
15096
|
+
* ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
|
|
15097
|
+
* ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
|
|
15042
15098
|
* En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
|
|
15043
15099
|
* se abre ahora va a uno nuevo.
|
|
15044
15100
|
*/
|
|
@@ -15049,7 +15105,7 @@ var DeepdotsPopups = class {
|
|
|
15049
15105
|
const storage = getSessionStorage();
|
|
15050
15106
|
if (storage) clearSuspendedSession(storage);
|
|
15051
15107
|
const suspendedMs = Math.max(0, Date.now() - suspended.at);
|
|
15052
|
-
if (this.analyticsFeedbackSessionId && suspendedMs <=
|
|
15108
|
+
if (this.analyticsFeedbackSessionId && suspendedMs <= suspended.windowMs && suspended.userId === (this.tracking?.getUserId() ?? null)) {
|
|
15053
15109
|
return suspendedMs;
|
|
15054
15110
|
}
|
|
15055
15111
|
this.analytics?.discardSession(this.analyticsIdentity());
|
|
@@ -15057,6 +15113,27 @@ var DeepdotsPopups = class {
|
|
|
15057
15113
|
this.tracking?.setSessionId(null);
|
|
15058
15114
|
return null;
|
|
15059
15115
|
}
|
|
15116
|
+
/**
|
|
15117
|
+
* `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
|
|
15118
|
+
* misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
|
|
15119
|
+
* (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
|
|
15120
|
+
* el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
|
|
15121
|
+
* #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
|
|
15122
|
+
* - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
|
|
15123
|
+
* - Más: el backend ya la cerró → se descarta sin enviar nada.
|
|
15124
|
+
* Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
|
|
15125
|
+
*/
|
|
15126
|
+
closeStaleHiddenSession() {
|
|
15127
|
+
if (!this.sessionOpen || this.hiddenAt === null) return false;
|
|
15128
|
+
const hiddenFor = Date.now() - this.hiddenAt;
|
|
15129
|
+
if (hiddenFor < ANALYTICS_SESSION_TIMEOUT_MS) return false;
|
|
15130
|
+
if (hiddenFor < ANALYTICS_SESSION_DISCARD_MS) {
|
|
15131
|
+
this.closeSession("idle_timeout");
|
|
15132
|
+
} else {
|
|
15133
|
+
this.discardSession();
|
|
15134
|
+
}
|
|
15135
|
+
return true;
|
|
15136
|
+
}
|
|
15060
15137
|
/** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
|
|
15061
15138
|
discardSession() {
|
|
15062
15139
|
this.sessionOpen = false;
|
|
@@ -15105,7 +15182,8 @@ var DeepdotsPopups = class {
|
|
|
15105
15182
|
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
15106
15183
|
window.addEventListener("pagehide", () => {
|
|
15107
15184
|
clearInterval(this.analyticsFlushTimer);
|
|
15108
|
-
if (
|
|
15185
|
+
if (this.closeStaleHiddenSession()) return;
|
|
15186
|
+
if (!this.suspendSession("page_hide")) this.closeSession("page_hide");
|
|
15109
15187
|
});
|
|
15110
15188
|
window.addEventListener("pageshow", (event) => {
|
|
15111
15189
|
if (!event.persisted) return;
|