@magicfeedback/popup-sdk 1.18.0 → 1.20.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/MagicfeedbackPopupSdk.podspec +18 -0
- package/README.md +23 -0
- package/dist/2.2.38-CCK7SF4A.mjs +2343 -0
- package/dist/2.2.38-CCK7SF4A.mjs.map +1 -0
- package/dist/2.2.38-LGZRM7GX.mjs +2343 -0
- package/dist/2.2.38-LGZRM7GX.mjs.map +1 -0
- package/dist/2.2.39-BJJ3YRJ4.mjs +2344 -0
- package/dist/2.2.39-BJJ3YRJ4.mjs.map +1 -0
- package/dist/2.2.39-HPNDYUPP.mjs +2344 -0
- package/dist/2.2.39-HPNDYUPP.mjs.map +1 -0
- package/dist/assets/assets/style.css +107 -1
- package/dist/assets/assets/survey-css/2.2.38.css +2335 -0
- package/dist/assets/assets/survey-css/2.2.39.css +2336 -0
- package/dist/chunk-3QS3WKRC.mjs +31 -0
- package/dist/chunk-3QS3WKRC.mjs.map +1 -0
- package/dist/chunk-BJTO5JO5.mjs +11 -0
- package/dist/chunk-BJTO5JO5.mjs.map +1 -0
- package/dist/{chunk-DNBFTJCA.mjs → chunk-FROREHRG.mjs} +516 -52
- package/dist/chunk-FROREHRG.mjs.map +1 -0
- package/dist/{chunk-7ZVOPIWE.mjs → chunk-OPR5I7WO.mjs} +557 -11
- package/dist/chunk-OPR5I7WO.mjs.map +1 -0
- package/dist/chunk-ZJ5HG3QF.mjs +3357 -0
- package/dist/chunk-ZJ5HG3QF.mjs.map +1 -0
- package/dist/index.d.mts +217 -9
- package/dist/index.d.ts +217 -9
- package/dist/index.js +7253 -1519
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +389 -49
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.d.mts +1681 -0
- package/dist/index.native.d.ts +1681 -0
- package/dist/index.native.js +15972 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.native.mjs +4011 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/react-native.d.mts +113 -7
- package/dist/react-native.d.ts +113 -7
- package/dist/react-native.js +5846 -162
- package/dist/react-native.js.map +1 -1
- package/dist/react-native.mjs +396 -51
- package/dist/react-native.mjs.map +1 -1
- package/dist/{renderPopup-B6VIV4VS.mjs → renderPopup-I6CPIR75.mjs} +133 -6
- package/dist/renderPopup-I6CPIR75.mjs.map +1 -0
- package/dist/renderPopup-RUY3OBYV.mjs +3847 -0
- package/dist/renderPopup-RUY3OBYV.mjs.map +1 -0
- package/dist/renderPopup-XNVNP2ZU.mjs +3847 -0
- package/dist/renderPopup-XNVNP2ZU.mjs.map +1 -0
- package/ios/DeepdotsBackgroundTask.m +71 -0
- package/package.json +14 -5
- package/react-native.config.js +9 -0
- package/dist/chunk-7ZVOPIWE.mjs.map +0 -1
- package/dist/chunk-DNBFTJCA.mjs.map +0 -1
- package/dist/renderPopup-B6VIV4VS.mjs.map +0 -1
- package/dist/renderPopup-BKZPAZZG.mjs +0 -3682
- package/dist/renderPopup-BKZPAZZG.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BUNDLED_SURVEY_SDK_VERSION,
|
|
2
3
|
BUSY_JS,
|
|
3
4
|
InMemoryStorage,
|
|
4
5
|
LABELS,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
RESOLVE_LOCALE_JS,
|
|
7
8
|
REVEAL_TIMEOUT_MS,
|
|
8
9
|
RTL_LOCALES,
|
|
10
|
+
SDK_IDENTIFIER,
|
|
9
11
|
STORAGE_KEYS,
|
|
10
12
|
SUBMIT_ERROR_JS,
|
|
11
13
|
SUPPORTED_LANGUAGES,
|
|
@@ -13,16 +15,22 @@ import {
|
|
|
13
15
|
buildFontFaceCss,
|
|
14
16
|
buildFontFamilyValue,
|
|
15
17
|
buildSurveyIdentity,
|
|
18
|
+
chooseSurveySdkVersion,
|
|
16
19
|
createDefaultStorage,
|
|
20
|
+
describeSurveySdkChoice,
|
|
17
21
|
directionFor,
|
|
18
22
|
getLabels,
|
|
19
23
|
isRtlLanguage,
|
|
20
24
|
resolveActionLabels,
|
|
21
25
|
resolveLocale,
|
|
26
|
+
sdkLog,
|
|
22
27
|
sdkWarn,
|
|
23
28
|
setLogger,
|
|
24
|
-
style_default
|
|
25
|
-
|
|
29
|
+
style_default,
|
|
30
|
+
surveySdkCssUrls,
|
|
31
|
+
surveySdkUrls
|
|
32
|
+
} from "./chunk-OPR5I7WO.mjs";
|
|
33
|
+
import "./chunk-3QS3WKRC.mjs";
|
|
26
34
|
|
|
27
35
|
// src/types/index.ts
|
|
28
36
|
var POPUP_TRIGGER_CONDITION_STATUSES = [
|
|
@@ -58,7 +66,7 @@ function setupTrigger(popups, trigger) {
|
|
|
58
66
|
function setupTimeTrigger(popups, trigger) {
|
|
59
67
|
const delay = toNumericValue(trigger.value, 5e3);
|
|
60
68
|
setTimeout(() => {
|
|
61
|
-
popups.triggerSurvey(trigger.surveyId, trigger.popupId);
|
|
69
|
+
popups.triggerSurvey(trigger.surveyId, trigger.popupId, { delaySeconds: trigger.delaySeconds });
|
|
62
70
|
}, delay);
|
|
63
71
|
popups.debug(`Time trigger set for ${delay}ms`);
|
|
64
72
|
}
|
|
@@ -67,7 +75,7 @@ function setupScrollTrigger(popups, trigger) {
|
|
|
67
75
|
const handler = () => {
|
|
68
76
|
const scrollPercentage = window.scrollY / (document.documentElement.scrollHeight - window.innerHeight) * 100;
|
|
69
77
|
if (scrollPercentage >= threshold) {
|
|
70
|
-
popups.triggerSurvey(trigger.surveyId, trigger.popupId);
|
|
78
|
+
popups.triggerSurvey(trigger.surveyId, trigger.popupId, { delaySeconds: trigger.delaySeconds });
|
|
71
79
|
window.removeEventListener("scroll", handler);
|
|
72
80
|
}
|
|
73
81
|
};
|
|
@@ -76,7 +84,7 @@ function setupScrollTrigger(popups, trigger) {
|
|
|
76
84
|
}
|
|
77
85
|
function setupExitTrigger(popups, trigger) {
|
|
78
86
|
if (typeof window === "undefined") return;
|
|
79
|
-
const delaySeconds = parseExitDelaySeconds(trigger.value);
|
|
87
|
+
const delaySeconds = typeof trigger.delaySeconds === "number" && trigger.delaySeconds > 0 ? trigger.delaySeconds : parseExitDelaySeconds(trigger.value);
|
|
80
88
|
const historyRef = window.history;
|
|
81
89
|
const originalPushState = historyRef.pushState.bind(historyRef);
|
|
82
90
|
const originalReplaceState = historyRef.replaceState.bind(historyRef);
|
|
@@ -187,7 +195,7 @@ function setupClickTrigger(popups, trigger) {
|
|
|
187
195
|
}
|
|
188
196
|
const handler = (e) => {
|
|
189
197
|
if (e.defaultPrevented) return;
|
|
190
|
-
popups.triggerSurvey(trigger.surveyId, trigger.popupId);
|
|
198
|
+
popups.triggerSurvey(trigger.surveyId, trigger.popupId, { delaySeconds: trigger.delaySeconds });
|
|
191
199
|
el.removeEventListener("click", handler);
|
|
192
200
|
};
|
|
193
201
|
el.addEventListener("click", handler);
|
|
@@ -255,8 +263,9 @@ function trimmedOrNull(value) {
|
|
|
255
263
|
}
|
|
256
264
|
function buildSurveyHtml(opts) {
|
|
257
265
|
const env = opts.env === "development" ? "dev" : "prod";
|
|
258
|
-
const version = opts.version ??
|
|
259
|
-
const
|
|
266
|
+
const version = opts.version ?? BUNDLED_SURVEY_SDK_VERSION;
|
|
267
|
+
const assigned = version !== BUNDLED_SURVEY_SDK_VERSION ? { version, css: surveySdkCssUrls(version), js: surveySdkUrls(version) } : null;
|
|
268
|
+
const bundledJs = surveySdkUrls(BUNDLED_SURVEY_SDK_VERSION);
|
|
260
269
|
const sid = jsonForScript(opts.surveyId);
|
|
261
270
|
const pid = jsonForScript(opts.productId);
|
|
262
271
|
const profileJson = jsonForScript(opts.profile ?? []);
|
|
@@ -308,8 +317,10 @@ function buildSurveyHtml(opts) {
|
|
|
308
317
|
return `<!DOCTYPE html><html><head>
|
|
309
318
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
310
319
|
<meta name="color-scheme" content="${colorScheme}"/>
|
|
311
|
-
<style>
|
|
320
|
+
<style id="dd-survey-css">
|
|
312
321
|
${style_default}
|
|
322
|
+
</style>
|
|
323
|
+
<style>
|
|
313
324
|
${fontFaceCss}
|
|
314
325
|
html,body{margin:0;padding:0;height:100%;font-family:${fontFamilyValue}}
|
|
315
326
|
/* Apertura diferida: ni la tarjeta ni el velo se pintan hasta que el survey est\xE1 listo
|
|
@@ -763,9 +774,9 @@ ${REVEAL_JS}
|
|
|
763
774
|
if(p && p.error){
|
|
764
775
|
setLoading(false);
|
|
765
776
|
var ddErr=ddClassifySubmitError(p.error);
|
|
766
|
-
if(ddErr.reason==='required'){
|
|
777
|
+
if(ddErr.reason==='required' || ddErr.reason==='invalid_email'){
|
|
767
778
|
// La p\xE1gina no ha cambiado: el estado de navegaci\xF3n se queda como estaba.
|
|
768
|
-
errorHint.textContent=DD_LABELS_ACTIVE.errorRequired;
|
|
779
|
+
errorHint.textContent=ddErr.reason==='invalid_email' ? DD_LABELS_ACTIVE.errorInvalidEmail : DD_LABELS_ACTIVE.errorRequired;
|
|
769
780
|
errorHint.style.display='block';
|
|
770
781
|
updateNavButtons();
|
|
771
782
|
return;
|
|
@@ -806,10 +817,46 @@ ${REVEAL_JS}
|
|
|
806
817
|
}catch(e){ ddShowLoadError('error:exception', e); }
|
|
807
818
|
return true;
|
|
808
819
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
document.
|
|
820
|
+
// DD-70: versi\xF3n asignada (hoja + JS) y, si algo falla, la empaquetada (hoja + JS).
|
|
821
|
+
var ddAssigned=${jsonForScript(assigned)}, ddBundledJs=${jsonForScript(bundledJs)};
|
|
822
|
+
var ddCssEl=document.getElementById('dd-survey-css'), ddBundledCss=ddCssEl?ddCssEl.textContent:'';
|
|
823
|
+
function ddMark(v){ try{ document.documentElement.setAttribute('data-survey-sdk', v); }catch(_){} }
|
|
824
|
+
function ddLoadScripts(urls, i, onFail){
|
|
825
|
+
if(i>=urls.length){ onFail(); return; }
|
|
826
|
+
var s=document.createElement('script'); s.src=urls[i]; s.async=true;
|
|
827
|
+
s.onload=function(){ initMF(); };
|
|
828
|
+
s.onerror=function(){
|
|
829
|
+
try{ console.warn('[Deepdots] survey SDK failed from '+urls[i]); }catch(_){}
|
|
830
|
+
ddLoadScripts(urls, i+1, onFail);
|
|
831
|
+
};
|
|
832
|
+
document.head.appendChild(s);
|
|
833
|
+
}
|
|
834
|
+
function ddLoadBundled(){
|
|
835
|
+
if(ddCssEl){ ddCssEl.textContent=ddBundledCss; }
|
|
836
|
+
ddMark(${jsonForScript(BUNDLED_SURVEY_SDK_VERSION + " bundled")});
|
|
837
|
+
ddLoadScripts(ddBundledJs, 0, function(){ ddShowLoadError('error:load', 'survey script failed to load'); });
|
|
838
|
+
}
|
|
839
|
+
function ddFetchCss(urls, i, ok, fail){
|
|
840
|
+
if(i>=urls.length || typeof fetch!=='function'){ fail(); return; }
|
|
841
|
+
fetch(urls[i]).then(function(r){ if(!r.ok) throw new Error('HTTP '+r.status); return r.text(); })
|
|
842
|
+
.then(function(css){ if(!css) throw new Error('empty'); ok(css); })
|
|
843
|
+
.catch(function(){ ddFetchCss(urls, i+1, ok, fail); });
|
|
844
|
+
}
|
|
845
|
+
if(ddAssigned){
|
|
846
|
+
ddFetchCss(ddAssigned.css, 0, function(css){
|
|
847
|
+
if(ddCssEl){ ddCssEl.textContent=css; }
|
|
848
|
+
ddMark(ddAssigned.version+' assigned');
|
|
849
|
+
ddLoadScripts(ddAssigned.js, 0, function(){
|
|
850
|
+
try{ console.warn('[Deepdots] survey SDK '+ddAssigned.version+' failed, using bundled'); }catch(_){}
|
|
851
|
+
ddLoadBundled();
|
|
852
|
+
});
|
|
853
|
+
}, function(){
|
|
854
|
+
try{ console.warn('[Deepdots] survey CSS '+ddAssigned.version+' failed, using bundled'); }catch(_){}
|
|
855
|
+
ddLoadBundled();
|
|
856
|
+
});
|
|
857
|
+
} else {
|
|
858
|
+
ddLoadBundled();
|
|
859
|
+
}
|
|
813
860
|
var tries=0, t=setInterval(function(){ if(initMF()||++tries>40){ clearInterval(t); } },150);
|
|
814
861
|
})();
|
|
815
862
|
<\/script>
|
|
@@ -838,9 +885,12 @@ var ReactNativePopupRenderer = class {
|
|
|
838
885
|
this.readyEmitted = false;
|
|
839
886
|
this.armReadyFallback(surveyId);
|
|
840
887
|
const { profile, metadata } = buildSurveyIdentity(userId ?? null, sessionId ?? null, miniService ?? null, analyticsFeedbackSessionId ?? null);
|
|
888
|
+
const surveySdk = chooseSurveySdkVersion(options?.surveySdkVersion);
|
|
889
|
+
logRnSurveySdkChoice(surveySdk, options?.debug);
|
|
841
890
|
const html = buildSurveyHtml({
|
|
842
891
|
surveyId,
|
|
843
892
|
productId,
|
|
893
|
+
version: surveySdk.version,
|
|
844
894
|
env,
|
|
845
895
|
profile,
|
|
846
896
|
metadata,
|
|
@@ -940,9 +990,14 @@ function isReactNativeEnv() {
|
|
|
940
990
|
function createReactNativeRenderer() {
|
|
941
991
|
return new ReactNativePopupRenderer();
|
|
942
992
|
}
|
|
993
|
+
function logRnSurveySdkChoice(choice, debug) {
|
|
994
|
+
const problem = choice.source === "bundled" && choice.reason === "invalid";
|
|
995
|
+
if (problem) sdkWarn(`[Deepdots] ${describeSurveySdkChoice(choice)}`);
|
|
996
|
+
else if (debug) sdkLog(`[Deepdots] ${describeSurveySdkChoice(choice)}`);
|
|
997
|
+
}
|
|
943
998
|
|
|
944
999
|
// src/ui/preload.ts
|
|
945
|
-
var defaultLoader = () => import("./renderPopup-
|
|
1000
|
+
var defaultLoader = () => import("./renderPopup-XNVNP2ZU.mjs");
|
|
946
1001
|
var pending = null;
|
|
947
1002
|
function preloadRenderPopup(loader = defaultLoader) {
|
|
948
1003
|
if (pending) return pending;
|
|
@@ -1015,7 +1070,7 @@ var BrowserPopupRenderer = class {
|
|
|
1015
1070
|
if (!this.container) return;
|
|
1016
1071
|
this.visible = true;
|
|
1017
1072
|
const container = this.container;
|
|
1018
|
-
void import("./renderPopup-
|
|
1073
|
+
void import("./renderPopup-XNVNP2ZU.mjs").then(
|
|
1019
1074
|
({ renderPopup }) => {
|
|
1020
1075
|
renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
|
|
1021
1076
|
},
|
|
@@ -1179,6 +1234,7 @@ var AnalyticsManager = class {
|
|
|
1179
1234
|
sessionId: identity.sessionId,
|
|
1180
1235
|
context: {
|
|
1181
1236
|
platform: this.platform,
|
|
1237
|
+
sdk: SDK_IDENTIFIER,
|
|
1182
1238
|
language: this.language,
|
|
1183
1239
|
device: this.device,
|
|
1184
1240
|
attributes: { ...this.attributes },
|
|
@@ -1226,6 +1282,48 @@ var AnalyticsManager = class {
|
|
|
1226
1282
|
}
|
|
1227
1283
|
};
|
|
1228
1284
|
|
|
1285
|
+
// src/analytics/background-task.ts
|
|
1286
|
+
var BACKGROUND_TASK_MAX_MS = 25e3;
|
|
1287
|
+
async function runInBackgroundTask(begin, name, work, maxMs = BACKGROUND_TASK_MAX_MS) {
|
|
1288
|
+
let end;
|
|
1289
|
+
try {
|
|
1290
|
+
end = begin?.(name);
|
|
1291
|
+
} catch {
|
|
1292
|
+
end = void 0;
|
|
1293
|
+
}
|
|
1294
|
+
if (typeof end !== "function") return work();
|
|
1295
|
+
let ended = false;
|
|
1296
|
+
const finish = () => {
|
|
1297
|
+
if (ended) return;
|
|
1298
|
+
ended = true;
|
|
1299
|
+
clearTimeout(timer);
|
|
1300
|
+
try {
|
|
1301
|
+
end();
|
|
1302
|
+
} catch {
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
const timer = setTimeout(finish, maxMs);
|
|
1306
|
+
try {
|
|
1307
|
+
return await work();
|
|
1308
|
+
} finally {
|
|
1309
|
+
finish();
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function backgroundTimerTask(timer) {
|
|
1313
|
+
let open = 0;
|
|
1314
|
+
return () => {
|
|
1315
|
+
if (open === 0) timer.start(0);
|
|
1316
|
+
open++;
|
|
1317
|
+
let closed = false;
|
|
1318
|
+
return () => {
|
|
1319
|
+
if (closed) return;
|
|
1320
|
+
closed = true;
|
|
1321
|
+
open--;
|
|
1322
|
+
if (open === 0) timer.stop();
|
|
1323
|
+
};
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1229
1327
|
// src/analytics/feedback-payload.ts
|
|
1230
1328
|
function pushKV(list, key, value) {
|
|
1231
1329
|
if (value === void 0 || value === null || value === "") return;
|
|
@@ -1239,6 +1337,7 @@ function buildAnalyticsFeedbackBody(envelope, keys, feedbackSessionId, options)
|
|
|
1239
1337
|
pushKV(metadata, "deepdots_user_id", envelope.userId);
|
|
1240
1338
|
pushKV(metadata, "deepdots_session_id", envelope.sessionId);
|
|
1241
1339
|
pushKV(metadata, "deepdots_platform", context.platform);
|
|
1340
|
+
pushKV(metadata, "deepdots_sdk", context.sdk);
|
|
1242
1341
|
pushKV(metadata, "deepdots_language", context.language);
|
|
1243
1342
|
if (context.device) {
|
|
1244
1343
|
const d = context.device;
|
|
@@ -1437,7 +1536,9 @@ function createFeedbackSink(options) {
|
|
|
1437
1536
|
savePending();
|
|
1438
1537
|
setTimeout(() => void drain(), 0);
|
|
1439
1538
|
}
|
|
1440
|
-
|
|
1539
|
+
const sink = (envelope, meta) => runInBackgroundTask(options.backgroundTask, "deepdots-analytics", () => deliver(envelope, meta));
|
|
1540
|
+
return sink;
|
|
1541
|
+
async function deliver(envelope, meta) {
|
|
1441
1542
|
if (meta?.resetSession) {
|
|
1442
1543
|
feedbackSessionId = void 0;
|
|
1443
1544
|
options.onSessionReset?.();
|
|
@@ -1458,7 +1559,7 @@ function createFeedbackSink(options) {
|
|
|
1458
1559
|
}
|
|
1459
1560
|
const retries = pending2.length ? drain() : null;
|
|
1460
1561
|
await Promise.all([retries, send(batch, final, false)]);
|
|
1461
|
-
}
|
|
1562
|
+
}
|
|
1462
1563
|
}
|
|
1463
1564
|
|
|
1464
1565
|
// src/analytics/suspended-session.ts
|
|
@@ -1880,6 +1981,8 @@ var CrashReporter = class {
|
|
|
1880
1981
|
this.windowInstalled = false;
|
|
1881
1982
|
/** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
|
|
1882
1983
|
this.hookedErrorUtils = /* @__PURE__ */ new Set();
|
|
1984
|
+
/** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
|
|
1985
|
+
this.hookedRejections = /* @__PURE__ */ new Set();
|
|
1883
1986
|
this.options = options;
|
|
1884
1987
|
this.now = options.now ?? (() => Date.now());
|
|
1885
1988
|
}
|
|
@@ -1979,6 +2082,18 @@ var CrashReporter = class {
|
|
|
1979
2082
|
previous?.(error, isFatal);
|
|
1980
2083
|
});
|
|
1981
2084
|
}
|
|
2085
|
+
/**
|
|
2086
|
+
* Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
|
|
2087
|
+
* persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
|
|
2088
|
+
* Idempotente por fuente.
|
|
2089
|
+
*/
|
|
2090
|
+
installPromiseRejections(source) {
|
|
2091
|
+
if (this.hookedRejections.has(source)) return;
|
|
2092
|
+
this.hookedRejections.add(source);
|
|
2093
|
+
source.addUnhandledListener((error) => {
|
|
2094
|
+
if (this.isEnabled()) this.captureUnhandled(error ?? "unhandledrejection");
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
1982
2097
|
/** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
|
|
1983
2098
|
_persistForTest(error) {
|
|
1984
2099
|
this.captureUnhandled(error);
|
|
@@ -2054,6 +2169,78 @@ function clearPopupState(storage) {
|
|
|
2054
2169
|
}
|
|
2055
2170
|
}
|
|
2056
2171
|
|
|
2172
|
+
// src/platform/react-native-platform.ts
|
|
2173
|
+
var registered = null;
|
|
2174
|
+
function getReactNativePlatform() {
|
|
2175
|
+
return registered;
|
|
2176
|
+
}
|
|
2177
|
+
function nativeModuleTask(mod) {
|
|
2178
|
+
let seq = 0;
|
|
2179
|
+
return (name) => {
|
|
2180
|
+
const token = `dd-${Date.now().toString(36)}-${(seq++).toString(36)}`;
|
|
2181
|
+
mod.begin(token, name);
|
|
2182
|
+
let ended = false;
|
|
2183
|
+
return () => {
|
|
2184
|
+
if (ended) return;
|
|
2185
|
+
ended = true;
|
|
2186
|
+
mod.end(token);
|
|
2187
|
+
};
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
function resolveBackgroundTask(explicit, platform) {
|
|
2191
|
+
if (explicit) return explicit;
|
|
2192
|
+
const mod = platform?.backgroundTaskModule;
|
|
2193
|
+
if (platform?.os === "ios" && mod && typeof mod.begin === "function" && typeof mod.end === "function") {
|
|
2194
|
+
return nativeModuleTask(mod);
|
|
2195
|
+
}
|
|
2196
|
+
return void 0;
|
|
2197
|
+
}
|
|
2198
|
+
var DEFAULT_REJECTION_WHITELIST = [ReferenceError, TypeError, RangeError];
|
|
2199
|
+
function createHermesRejectionHub(hermes, options) {
|
|
2200
|
+
if (!hermes || typeof hermes.enablePromiseRejectionTracker !== "function") return null;
|
|
2201
|
+
const original = hermes.enablePromiseRejectionTracker.bind(hermes);
|
|
2202
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2203
|
+
let hostOptions = null;
|
|
2204
|
+
let active = false;
|
|
2205
|
+
const forwardsToHost = (error) => !!hostOptions?.onUnhandled && (hostOptions.allRejections === true || DEFAULT_REJECTION_WHITELIST.some((type) => error instanceof type));
|
|
2206
|
+
const apply = () => {
|
|
2207
|
+
original({
|
|
2208
|
+
allRejections: true,
|
|
2209
|
+
onUnhandled: (id, error) => {
|
|
2210
|
+
listeners.forEach((listener) => {
|
|
2211
|
+
try {
|
|
2212
|
+
listener(error);
|
|
2213
|
+
} catch {
|
|
2214
|
+
}
|
|
2215
|
+
});
|
|
2216
|
+
if (hostOptions?.onUnhandled) {
|
|
2217
|
+
if (forwardsToHost(error)) hostOptions.onUnhandled(id, error);
|
|
2218
|
+
} else if (options.dev) {
|
|
2219
|
+
console.warn(`Possible unhandled promise rejection (id: ${id}):`, error);
|
|
2220
|
+
}
|
|
2221
|
+
},
|
|
2222
|
+
onHandled: (id, error) => hostOptions?.onHandled?.(id, error)
|
|
2223
|
+
});
|
|
2224
|
+
};
|
|
2225
|
+
hermes.enablePromiseRejectionTracker = (next) => {
|
|
2226
|
+
hostOptions = next ?? null;
|
|
2227
|
+
if (active) apply();
|
|
2228
|
+
else original(next);
|
|
2229
|
+
};
|
|
2230
|
+
return {
|
|
2231
|
+
addUnhandledListener(listener) {
|
|
2232
|
+
listeners.add(listener);
|
|
2233
|
+
if (!active) {
|
|
2234
|
+
active = true;
|
|
2235
|
+
apply();
|
|
2236
|
+
}
|
|
2237
|
+
return () => {
|
|
2238
|
+
listeners.delete(listener);
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2057
2244
|
// src/analytics/messaging.ts
|
|
2058
2245
|
var MESSAGE_CHANNELS = ["push", "in_app"];
|
|
2059
2246
|
function buildMessageParams(stage, o) {
|
|
@@ -2133,6 +2320,10 @@ var ANALYTICS_RESUME_WINDOW_MS = 6e4;
|
|
|
2133
2320
|
var RESERVED_EVENT_PREFIX = "deepdots_";
|
|
2134
2321
|
var CUSTOM_EVENT_PREFIX = "deepdots_event_";
|
|
2135
2322
|
var MAX_PENDING_TRIGGERS = 20;
|
|
2323
|
+
function triggerDelayMs(delaySeconds) {
|
|
2324
|
+
const n = typeof delaySeconds === "number" ? delaySeconds : Number(delaySeconds);
|
|
2325
|
+
return Number.isFinite(n) && n > 0 ? Math.round(n * 1e3) : 0;
|
|
2326
|
+
}
|
|
2136
2327
|
var DeepdotsPopups = class {
|
|
2137
2328
|
constructor() {
|
|
2138
2329
|
this.config = null;
|
|
@@ -2164,6 +2355,10 @@ var DeepdotsPopups = class {
|
|
|
2164
2355
|
this.surveyToPopupId = /* @__PURE__ */ new Map();
|
|
2165
2356
|
// surveyId -> popupId
|
|
2166
2357
|
this.deferredExitTimers = [];
|
|
2358
|
+
/** Popups esperando su `delaySeconds` (uno por popup). */
|
|
2359
|
+
this.delayedPopups = /* @__PURE__ */ new Map();
|
|
2360
|
+
/** Última pantalla de `setScreen` (React Native). */
|
|
2361
|
+
this.currentScreen = null;
|
|
2167
2362
|
this.baseUrl = "";
|
|
2168
2363
|
this.env = "production";
|
|
2169
2364
|
/** Si el SDK pinta el "modal" del popup (RN). Default true; false = el host lo envuelve. */
|
|
@@ -2209,6 +2404,10 @@ var DeepdotsPopups = class {
|
|
|
2209
2404
|
this.lastEngagementAt = 0;
|
|
2210
2405
|
/** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
|
|
2211
2406
|
this.hiddenAt = null;
|
|
2407
|
+
/** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
|
|
2408
|
+
this.autoTrackErrors = true;
|
|
2409
|
+
/** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
|
|
2410
|
+
this.appStateSubscription = void 0;
|
|
2212
2411
|
/**
|
|
2213
2412
|
* Sesión suspendida por un `pagehide` (ms epoch y `deepdots_user_id`); null si no hay.
|
|
2214
2413
|
* `openSession` la reanuda si sigue a tiempo (ver ANALYTICS_RESUME_WINDOW_MS).
|
|
@@ -2241,6 +2440,10 @@ var DeepdotsPopups = class {
|
|
|
2241
2440
|
this.log("SDK already initialized");
|
|
2242
2441
|
return;
|
|
2243
2442
|
}
|
|
2443
|
+
const rn = getReactNativePlatform();
|
|
2444
|
+
if (!config.platform && (rn?.os === "ios" || rn?.os === "android")) {
|
|
2445
|
+
config = { ...config, platform: rn.os };
|
|
2446
|
+
}
|
|
2244
2447
|
const env = resolveEnvironment(config.nodeEnv);
|
|
2245
2448
|
this.baseUrl = env.apiBaseUrl;
|
|
2246
2449
|
this.env = config.nodeEnv || "production";
|
|
@@ -2249,6 +2452,7 @@ var DeepdotsPopups = class {
|
|
|
2249
2452
|
this.surveyCss = config.surveyCss;
|
|
2250
2453
|
this.cspNonce = config.cspNonce;
|
|
2251
2454
|
this.onFeedbackSession = config.onFeedbackSession;
|
|
2455
|
+
this.autoTrackErrors = config.autoTrack?.errors !== false;
|
|
2252
2456
|
this.config = {
|
|
2253
2457
|
apiKey: config.apiKey || void 0,
|
|
2254
2458
|
debug: config.debug || false,
|
|
@@ -2291,6 +2495,10 @@ var DeepdotsPopups = class {
|
|
|
2291
2495
|
// persiste y se reenvía en el arranque siguiente. En web el cierre sale con
|
|
2292
2496
|
// `keepalive` y varias pestañas compartirían el mismo storage.
|
|
2293
2497
|
storage: (config.platform ?? "web") !== "web" ? storage : void 0,
|
|
2498
|
+
// iOS suspende la app con el POST de cierre en vuelo: el host puede darle
|
|
2499
|
+
// tiempo de background (DD-55). El reenvío del arranque siguiente sigue igual.
|
|
2500
|
+
// La del host o, en iOS, la del módulo nativo del paquete (autolinking).
|
|
2501
|
+
backgroundTask: resolveBackgroundTask(config.backgroundTask, rn),
|
|
2294
2502
|
onSessionId: (id) => {
|
|
2295
2503
|
this.analyticsFeedbackSessionId = id;
|
|
2296
2504
|
this.notifyFeedbackSession(id, "open");
|
|
@@ -2348,6 +2556,7 @@ var DeepdotsPopups = class {
|
|
|
2348
2556
|
}
|
|
2349
2557
|
}
|
|
2350
2558
|
this.initialized = true;
|
|
2559
|
+
this.installAutoLifecycle(rn, config);
|
|
2351
2560
|
this.log("SDK initialized", this.config);
|
|
2352
2561
|
if (this.renderer.init) this.renderer.init();
|
|
2353
2562
|
this.awaitingPopups = Boolean(this.config.apiKey && this.baseUrl);
|
|
@@ -2442,11 +2651,14 @@ var DeepdotsPopups = class {
|
|
|
2442
2651
|
*/
|
|
2443
2652
|
installCrashHandlers() {
|
|
2444
2653
|
if (!this.crashReporter || !this.tracking?.isTrackingEnabled()) return;
|
|
2445
|
-
this.
|
|
2446
|
-
|
|
2654
|
+
const auto = this.autoTrackErrors;
|
|
2655
|
+
if (auto) this.crashReporter.install();
|
|
2656
|
+
const errorUtils = this.rnErrorUtils ?? (auto ? globalThis.ErrorUtils : void 0);
|
|
2447
2657
|
if (errorUtils && typeof errorUtils.setGlobalHandler === "function") {
|
|
2448
2658
|
this.crashReporter.installReactNative(errorUtils);
|
|
2449
2659
|
}
|
|
2660
|
+
const rejections = auto ? getReactNativePlatform()?.promiseRejections : null;
|
|
2661
|
+
if (rejections) this.crashReporter.installPromiseRejections(rejections);
|
|
2450
2662
|
}
|
|
2451
2663
|
/**
|
|
2452
2664
|
* Info interna del usuario que solo conoce el host (idioma, edad, plan…), persistida en el
|
|
@@ -2518,6 +2730,11 @@ var DeepdotsPopups = class {
|
|
|
2518
2730
|
* El host la llama en cada cambio de pantalla; emite `page_view` al salir de la anterior.
|
|
2519
2731
|
*/
|
|
2520
2732
|
setScreen(name) {
|
|
2733
|
+
const screen2 = typeof name === "string" ? name.trim() : "";
|
|
2734
|
+
if (screen2) {
|
|
2735
|
+
this.cancelDelayedPopups("screen change", (entry) => entry.screen !== screen2);
|
|
2736
|
+
this.currentScreen = screen2;
|
|
2737
|
+
}
|
|
2521
2738
|
if (!this.navObserver) return;
|
|
2522
2739
|
if (!this.navStarted) {
|
|
2523
2740
|
this.navObserver.begin(name);
|
|
@@ -2539,9 +2756,42 @@ var DeepdotsPopups = class {
|
|
|
2539
2756
|
* Es la única señal disponible en móvil: el kill de la app (swipe) NO da callback.
|
|
2540
2757
|
*/
|
|
2541
2758
|
onBackground() {
|
|
2759
|
+
this.cancelDelayedPopups("app to background");
|
|
2542
2760
|
this.closeSession("background");
|
|
2543
2761
|
this.engagement?.pause();
|
|
2544
2762
|
}
|
|
2763
|
+
/**
|
|
2764
|
+
* App a `inactive` (RN, iOS: centro de control, llamada, app switcher, y SIEMPRE justo antes
|
|
2765
|
+
* de `background`). NO cierra la sesión (es transitorio), pero envía lo acumulado con un
|
|
2766
|
+
* `user_engagement` que lleva la pantalla en curso, como web al ocultar la pestaña: si el
|
|
2767
|
+
* lote de cierre de `background` no llega a salir (iOS suspende la app), el backend ya
|
|
2768
|
+
* tiene el tiempo activo y la última pantalla. El contador sigue en marcha.
|
|
2769
|
+
*/
|
|
2770
|
+
onInactive() {
|
|
2771
|
+
if (this.sessionOpen) this.flushEngagement();
|
|
2772
|
+
this.flushAnalytics();
|
|
2773
|
+
}
|
|
2774
|
+
/**
|
|
2775
|
+
* Ciclo de vida automático en React Native (contrato de detección automática): el SDK escucha
|
|
2776
|
+
* AppState él mismo, así que el host no tiene que llamar a `onForeground`/`onInactive`/
|
|
2777
|
+
* `onBackground`. Si el host los llama además (integraciones anteriores), no se duplica nada:
|
|
2778
|
+
* abrir o cerrar una sesión ya abierta o cerrada no hace nada, y el engagement se consume.
|
|
2779
|
+
* `autoTrack.lifecycle: false` lo apaga.
|
|
2780
|
+
*/
|
|
2781
|
+
installAutoLifecycle(rn, config) {
|
|
2782
|
+
if (config.autoTrack?.lifecycle === false) return;
|
|
2783
|
+
const appState = rn?.appState;
|
|
2784
|
+
if (!appState || typeof appState.addEventListener !== "function" || this.appStateSubscription) return;
|
|
2785
|
+
try {
|
|
2786
|
+
this.appStateSubscription = appState.addEventListener("change", (state) => {
|
|
2787
|
+
if (state === "active") this.onForeground();
|
|
2788
|
+
else if (state === "background") this.onBackground();
|
|
2789
|
+
else this.onInactive();
|
|
2790
|
+
});
|
|
2791
|
+
this.log("lifecycle \xB7 AppState wired automatically");
|
|
2792
|
+
} catch {
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2545
2795
|
/**
|
|
2546
2796
|
* Cierre EXPLÍCITO de la sesión por parte del host (logout, fin de flujo…): emite
|
|
2547
2797
|
* `session_end` y envía el último lote con `completed:true`.
|
|
@@ -2554,11 +2804,24 @@ var DeepdotsPopups = class {
|
|
|
2554
2804
|
* anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
|
|
2555
2805
|
* identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
|
|
2556
2806
|
*
|
|
2807
|
+
* Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
|
|
2808
|
+
* persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
|
|
2809
|
+
* `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
|
|
2810
|
+
* cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
|
|
2811
|
+
* respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
|
|
2812
|
+
* contaba dos veces: una que "abandona" en el login y otra registrada nueva.
|
|
2813
|
+
*
|
|
2557
2814
|
* Equivale a llamar a `init()` otra vez con otro `userId`.
|
|
2558
2815
|
*/
|
|
2559
2816
|
setUserId(userId) {
|
|
2560
2817
|
const next = userId || void 0;
|
|
2561
2818
|
if (!this.initialized || !this.config || next === this.config.userId) return;
|
|
2819
|
+
const identifying = !this.config.userId && !!next;
|
|
2820
|
+
const previous = identifying ? {
|
|
2821
|
+
identified: true,
|
|
2822
|
+
previous_user_id: this.tracking?.getUserId() ?? void 0,
|
|
2823
|
+
previous_session_id: this.analyticsFeedbackSessionId
|
|
2824
|
+
} : void 0;
|
|
2562
2825
|
this.closeSession("user_change");
|
|
2563
2826
|
const enabled = this.tracking?.isTrackingEnabled() ?? true;
|
|
2564
2827
|
const storage = this.storage ?? createDefaultStorage();
|
|
@@ -2571,13 +2834,18 @@ var DeepdotsPopups = class {
|
|
|
2571
2834
|
post: (body) => this.postContact(body)
|
|
2572
2835
|
}) : null;
|
|
2573
2836
|
this.analytics?.resetUserScope();
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2837
|
+
if (!identifying) {
|
|
2838
|
+
this.messageGuard.reset();
|
|
2839
|
+
this.lastShown.clear();
|
|
2840
|
+
this.surveyProgress.clear();
|
|
2841
|
+
this.answeredSurveys.clear();
|
|
2842
|
+
clearPopupState(storage);
|
|
2843
|
+
}
|
|
2844
|
+
this.log(
|
|
2845
|
+
identifying ? "tracking \xB7 user identified \xB7 user_id:" : "tracking \xB7 user_change \xB7 user_id:",
|
|
2846
|
+
this.tracking.getUserId()
|
|
2847
|
+
);
|
|
2848
|
+
this.openSession("user_change", previous);
|
|
2581
2849
|
}
|
|
2582
2850
|
/**
|
|
2583
2851
|
* Cierra la sesión actual: vuelca todo lo que quedaba abierto y envía el último lote
|
|
@@ -2613,14 +2881,14 @@ var DeepdotsPopups = class {
|
|
|
2613
2881
|
* - `bfcache_restore`: vuelta desde la bfcache fuera de la ventana de reanudación.
|
|
2614
2882
|
* Si hay una sesión suspendida a tiempo emite `deepdots_session_resume` en su lugar, sin reason.
|
|
2615
2883
|
*/
|
|
2616
|
-
openSession(reason) {
|
|
2884
|
+
openSession(reason, extra) {
|
|
2617
2885
|
if (this.sessionOpen) return;
|
|
2618
2886
|
if (!this.tracking?.isTrackingEnabled()) return;
|
|
2619
2887
|
const suspendedMs = this.takeSuspendedSession();
|
|
2620
2888
|
this.sessionOpen = true;
|
|
2621
2889
|
this.lastEngagementAt = Date.now();
|
|
2622
2890
|
if (suspendedMs === null) {
|
|
2623
|
-
this.track("deepdots_session_start", { reason });
|
|
2891
|
+
this.track("deepdots_session_start", { reason, ...extra });
|
|
2624
2892
|
} else {
|
|
2625
2893
|
this.track("deepdots_session_resume", { suspended_ms: suspendedMs });
|
|
2626
2894
|
this.log("tracking \xB7 session resumed after", suspendedMs, "ms:", this.analyticsFeedbackSessionId);
|
|
@@ -2882,16 +3150,21 @@ var DeepdotsPopups = class {
|
|
|
2882
3150
|
return;
|
|
2883
3151
|
}
|
|
2884
3152
|
const value = type === "time" && typeof trigger.value === "number" ? trigger.value * 1e3 : trigger.value;
|
|
2885
|
-
derived.push({ type, value, surveyId: def.surveyId, popupId: def.id });
|
|
3153
|
+
derived.push({ type, value, surveyId: def.surveyId, popupId: def.id, delaySeconds: trigger.delaySeconds });
|
|
2886
3154
|
});
|
|
2887
3155
|
});
|
|
2888
3156
|
if (derived.length) {
|
|
2889
3157
|
this.configureTriggers(derived);
|
|
2890
3158
|
}
|
|
2891
3159
|
}
|
|
2892
|
-
/**
|
|
2893
|
-
|
|
2894
|
-
|
|
3160
|
+
/**
|
|
3161
|
+
* Lógica para evaluar condiciones antes de mostrar una encuesta. `options.delaySeconds`
|
|
3162
|
+
* (lo pasan los triggers time/scroll/click con el "Delay" del Admin) espera ese tiempo y
|
|
3163
|
+
* vuelve a evaluar antes de mostrar; sin él, al momento como siempre.
|
|
3164
|
+
*/
|
|
3165
|
+
triggerSurvey(surveyId, popupId, options) {
|
|
3166
|
+
const delaySeconds = options?.delaySeconds;
|
|
3167
|
+
if (this.bufferIfAwaitingPopups({ kind: "survey", surveyId, popupId, delaySeconds })) return;
|
|
2895
3168
|
const def = this.findPopupDefinition(surveyId, popupId);
|
|
2896
3169
|
if (!def) {
|
|
2897
3170
|
this.debug("No popup definition for trigger", { surveyId, popupId });
|
|
@@ -2901,7 +3174,7 @@ var DeepdotsPopups = class {
|
|
|
2901
3174
|
this.debug("Conditions prevented showing popup", def.id);
|
|
2902
3175
|
return;
|
|
2903
3176
|
}
|
|
2904
|
-
this.
|
|
3177
|
+
this.showAfterDelay(def, delaySeconds);
|
|
2905
3178
|
}
|
|
2906
3179
|
/** Trigger popups configured with trigger.type = 'event' and matching trigger.value */
|
|
2907
3180
|
triggerEvent(eventName) {
|
|
@@ -2918,9 +3191,9 @@ var DeepdotsPopups = class {
|
|
|
2918
3191
|
}
|
|
2919
3192
|
evaluateEvent(normalized) {
|
|
2920
3193
|
const candidates = this.popupDefinitions.filter((def) => {
|
|
2921
|
-
return def.triggers.some((
|
|
2922
|
-
const triggerValue = String(
|
|
2923
|
-
return
|
|
3194
|
+
return def.triggers.some((trigger2) => {
|
|
3195
|
+
const triggerValue = String(trigger2.value ?? "").trim();
|
|
3196
|
+
return trigger2.type === "event" && triggerValue === normalized;
|
|
2924
3197
|
});
|
|
2925
3198
|
});
|
|
2926
3199
|
if (!candidates.length) {
|
|
@@ -2932,7 +3205,69 @@ var DeepdotsPopups = class {
|
|
|
2932
3205
|
this.debug("Event popup blocked by conditions/segments", { eventName: normalized });
|
|
2933
3206
|
return;
|
|
2934
3207
|
}
|
|
2935
|
-
|
|
3208
|
+
const trigger = matched.triggers.find(
|
|
3209
|
+
(t) => t.type === "event" && String(t.value ?? "").trim() === normalized
|
|
3210
|
+
);
|
|
3211
|
+
this.showAfterDelay(matched, trigger?.delaySeconds);
|
|
3212
|
+
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Muestra `def` ya, o tras su "Delay (seconds)" del Admin. Mientras espera:
|
|
3215
|
+
* - el mismo popup no se programa dos veces (el primer vencimiento manda);
|
|
3216
|
+
* - cambiar de ruta/pantalla o pasar a background lo cancela;
|
|
3217
|
+
* y al vencer se vuelve a evaluar todo (segmentos, idioma, cooldowns) como un disparo nuevo.
|
|
3218
|
+
* Si entonces hay otro popup abierto, `showDefinition` lo salta sin efectos, igual que hoy.
|
|
3219
|
+
*/
|
|
3220
|
+
showAfterDelay(def, delaySeconds) {
|
|
3221
|
+
const delayMs = triggerDelayMs(delaySeconds);
|
|
3222
|
+
if (delayMs <= 0) {
|
|
3223
|
+
this.showDefinition(def);
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
if (this.delayedPopups.has(def.id)) {
|
|
3227
|
+
this.debug("Popup already waiting for its delay", def.id);
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
const entry = {
|
|
3231
|
+
popupId: def.id,
|
|
3232
|
+
timer: setTimeout(() => this.showDelayedPopup(def.id), delayMs),
|
|
3233
|
+
firedAt: Date.now(),
|
|
3234
|
+
href: this.currentHref(),
|
|
3235
|
+
screen: this.currentScreen
|
|
3236
|
+
};
|
|
3237
|
+
this.delayedPopups.set(def.id, entry);
|
|
3238
|
+
this.debug(`Popup delayed ${delayMs}ms`, def.id);
|
|
3239
|
+
}
|
|
3240
|
+
showDelayedPopup(popupId) {
|
|
3241
|
+
const entry = this.delayedPopups.get(popupId);
|
|
3242
|
+
if (!entry) return;
|
|
3243
|
+
this.delayedPopups.delete(popupId);
|
|
3244
|
+
const def = this.popupDefinitions.find((popup) => popup.id === popupId);
|
|
3245
|
+
if (!def) return;
|
|
3246
|
+
if (this.currentHref() !== entry.href || this.currentScreen !== entry.screen) {
|
|
3247
|
+
this.debug("Delayed popup dropped: route changed", popupId);
|
|
3248
|
+
return;
|
|
3249
|
+
}
|
|
3250
|
+
if (!this.shouldShow(def)) {
|
|
3251
|
+
this.debug("Delayed popup dropped by conditions at due time", popupId);
|
|
3252
|
+
return;
|
|
3253
|
+
}
|
|
3254
|
+
if ((this.lastShown.get(popupId) ?? 0) >= entry.firedAt) {
|
|
3255
|
+
this.debug("Delayed popup dropped: already shown while waiting", popupId);
|
|
3256
|
+
return;
|
|
3257
|
+
}
|
|
3258
|
+
this.showDefinition(def);
|
|
3259
|
+
}
|
|
3260
|
+
cancelDelayedPopups(reason, predicate = () => true) {
|
|
3261
|
+
this.delayedPopups.forEach((entry, popupId) => {
|
|
3262
|
+
if (!predicate(entry)) return;
|
|
3263
|
+
clearTimeout(entry.timer);
|
|
3264
|
+
this.delayedPopups.delete(popupId);
|
|
3265
|
+
this.debug(`Delayed popup cancelled (${reason})`, popupId);
|
|
3266
|
+
});
|
|
3267
|
+
}
|
|
3268
|
+
currentHref() {
|
|
3269
|
+
if (typeof window === "undefined" || !window.location) return "";
|
|
3270
|
+
return this.normalizeUrl(window.location.href || "");
|
|
2936
3271
|
}
|
|
2937
3272
|
/**
|
|
2938
3273
|
* Guarda `trigger` si las definiciones aún no han llegado. Devuelve `true` si lo guardó (el
|
|
@@ -2965,7 +3300,7 @@ var DeepdotsPopups = class {
|
|
|
2965
3300
|
this.debug("Replaying triggers received before popups loaded", replay.length);
|
|
2966
3301
|
replay.forEach((trigger) => {
|
|
2967
3302
|
if (trigger.kind === "event") this.evaluateEvent(trigger.name);
|
|
2968
|
-
else this.triggerSurvey(trigger.surveyId, trigger.popupId);
|
|
3303
|
+
else this.triggerSurvey(trigger.surveyId, trigger.popupId, { delaySeconds: trigger.delaySeconds });
|
|
2969
3304
|
});
|
|
2970
3305
|
}
|
|
2971
3306
|
showDefinition(def) {
|
|
@@ -2977,7 +3312,7 @@ var DeepdotsPopups = class {
|
|
|
2977
3312
|
this.surveyToPopupId.set(def.surveyId, def.id);
|
|
2978
3313
|
this.lastShown.set(def.id, Date.now());
|
|
2979
3314
|
this.persistPopupState();
|
|
2980
|
-
this.renderPopup(def.surveyId, def.productId, def.actions, def.style, def.title);
|
|
3315
|
+
this.renderPopup(def.surveyId, def.productId, def.actions, def.style, def.title, def.surveyFrontend?.sdkVersion);
|
|
2981
3316
|
this.emitEvent("popup_shown", def.surveyId, { popupId: def.id });
|
|
2982
3317
|
}
|
|
2983
3318
|
shouldShow(def, pathUrl, skipPathCheck = false) {
|
|
@@ -3349,7 +3684,7 @@ var DeepdotsPopups = class {
|
|
|
3349
3684
|
}
|
|
3350
3685
|
}
|
|
3351
3686
|
/** Render the popup UI */
|
|
3352
|
-
renderPopup(surveyId, productId, actions, style, title) {
|
|
3687
|
+
renderPopup(surveyId, productId, actions, style, title, surveySdkVersion) {
|
|
3353
3688
|
const userId = this.tracking?.getUserId() ?? this.config?.userId;
|
|
3354
3689
|
const sessionId = this.tracking?.getSessionId() ?? void 0;
|
|
3355
3690
|
const miniService = this.analytics?.getMiniService() ?? void 0;
|
|
@@ -3368,7 +3703,7 @@ var DeepdotsPopups = class {
|
|
|
3368
3703
|
miniService,
|
|
3369
3704
|
analyticsFeedbackSessionId,
|
|
3370
3705
|
this.renderChrome,
|
|
3371
|
-
{ title, showProgressBar: this.showProgressBar, surveyCss: this.surveyCss, language: this.language, cspNonce: this.cspNonce }
|
|
3706
|
+
{ title, showProgressBar: this.showProgressBar, surveyCss: this.surveyCss, language: this.language, cspNonce: this.cspNonce, surveySdkVersion, debug: this.config?.debug }
|
|
3372
3707
|
);
|
|
3373
3708
|
}
|
|
3374
3709
|
/** Hide the popup */
|
|
@@ -3535,10 +3870,10 @@ var DeepdotsPopups = class {
|
|
|
3535
3870
|
}
|
|
3536
3871
|
normalizeTriggers(value) {
|
|
3537
3872
|
const items = Array.isArray(value) ? value : value ? [value] : [];
|
|
3538
|
-
return items.filter((trigger) => this.isPopupTrigger(trigger)).map((trigger) =>
|
|
3539
|
-
|
|
3540
|
-
value: trigger.value
|
|
3541
|
-
})
|
|
3873
|
+
return items.filter((trigger) => this.isPopupTrigger(trigger)).map((trigger) => {
|
|
3874
|
+
const delayMs = triggerDelayMs(trigger.delaySeconds);
|
|
3875
|
+
return delayMs > 0 ? { type: trigger.type, value: trigger.value, delaySeconds: delayMs / 1e3 } : { type: trigger.type, value: trigger.value };
|
|
3876
|
+
});
|
|
3542
3877
|
}
|
|
3543
3878
|
normalizeCooldown(value) {
|
|
3544
3879
|
if (!Array.isArray(value)) return [];
|
|
@@ -3593,7 +3928,9 @@ function setupReactNative(sdk, config, deps = {}) {
|
|
|
3593
3928
|
const storage = deps.mmkv ? mmkvStorage(deps.mmkv) : config.storage;
|
|
3594
3929
|
const device = deps.deviceInfo ? collectRnDevice(deps.deviceInfo) : config.device;
|
|
3595
3930
|
const platform = deps.platform ?? config.platform;
|
|
3596
|
-
|
|
3931
|
+
const backgroundTask = config.backgroundTask ?? deps.backgroundTask ?? void 0;
|
|
3932
|
+
const autoTrack = deps.appState?.addEventListener ? { ...config.autoTrack, lifecycle: false } : config.autoTrack;
|
|
3933
|
+
sdk.init({ ...config, storage, device, platform, backgroundTask, autoTrack });
|
|
3597
3934
|
const errorUtils = deps.errorUtils ?? globalThis.ErrorUtils;
|
|
3598
3935
|
if (errorUtils && typeof errorUtils.setGlobalHandler === "function") {
|
|
3599
3936
|
sdk.installReactNativeCrashHandler(errorUtils);
|
|
@@ -3603,7 +3940,7 @@ function setupReactNative(sdk, config, deps = {}) {
|
|
|
3603
3940
|
subscription = deps.appState.addEventListener("change", (state) => {
|
|
3604
3941
|
if (state === "active") sdk.onForeground();
|
|
3605
3942
|
else if (state === "background") sdk.onBackground();
|
|
3606
|
-
else sdk.
|
|
3943
|
+
else sdk.onInactive();
|
|
3607
3944
|
});
|
|
3608
3945
|
}
|
|
3609
3946
|
return () => {
|
|
@@ -3611,6 +3948,7 @@ function setupReactNative(sdk, config, deps = {}) {
|
|
|
3611
3948
|
};
|
|
3612
3949
|
}
|
|
3613
3950
|
export {
|
|
3951
|
+
BACKGROUND_TASK_MAX_MS,
|
|
3614
3952
|
BrowserPopupRenderer,
|
|
3615
3953
|
ContactManager,
|
|
3616
3954
|
CrashReporter,
|
|
@@ -3627,6 +3965,7 @@ export {
|
|
|
3627
3965
|
RTL_LOCALES,
|
|
3628
3966
|
ReactNativePopupRenderer,
|
|
3629
3967
|
SUPPORTED_LANGUAGES,
|
|
3968
|
+
backgroundTimerTask,
|
|
3630
3969
|
buildAnalyticsFeedbackBody,
|
|
3631
3970
|
buildMessageParams,
|
|
3632
3971
|
buildSurveyHtml,
|
|
@@ -3634,6 +3973,7 @@ export {
|
|
|
3634
3973
|
crashRecordToParams,
|
|
3635
3974
|
createDefaultRenderer,
|
|
3636
3975
|
createFeedbackSink,
|
|
3976
|
+
createHermesRejectionHub,
|
|
3637
3977
|
directionFor,
|
|
3638
3978
|
getLabels,
|
|
3639
3979
|
isRtlLanguage,
|