@magicfeedback/popup-sdk 1.17.1 → 1.18.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.
@@ -243,7 +243,13 @@ interface TriggerConfig {
243
243
  /**
244
244
  * Event types emitted by the SDK
245
245
  */
246
- type DeepdotsEventType = 'popup_shown' | 'popup_clicked' | 'survey_completed';
246
+ type DeepdotsEventType = 'popup_shown' | 'popup_clicked' | 'survey_completed'
247
+ /**
248
+ * Fallo al enviar una página del survey (el popup enseña `errorSubmit`). `data`:
249
+ * `{reason: 'send_failed' | 'no_page' | 'unknown', message}`. No es interacción del
250
+ * usuario: no marca el popup como PARTIAL. También va a analítica como `deepdots_survey_error`.
251
+ */
252
+ | 'survey_error';
247
253
  /**
248
254
  * Event payload structure
249
255
  */
@@ -342,6 +348,12 @@ interface PopupRenderer {
342
348
  show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string, userId?: string, style?: PopupStyle, sessionId?: string, miniService?: string, analyticsFeedbackSessionId?: string, renderChrome?: boolean, options?: PopupRenderOptions): void;
343
349
  /** Ocultar popup */
344
350
  hide(): void;
351
+ /**
352
+ * ¿Hay un popup a la vista ahora mismo? Opcional. Con él, el core no da por mostrado un popup
353
+ * que el renderer no va a pintar (porque ya hay otro abierto): ni `popup_shown`, ni SHOWED, ni
354
+ * cooldown gastado. Sin él (renderers del host, RN), el core se comporta como siempre.
355
+ */
356
+ isShowing?(): boolean;
345
357
  }
346
358
 
347
359
  /** Valor de un atributo de contact (info interna del usuario que solo conoce el host). */
@@ -243,7 +243,13 @@ interface TriggerConfig {
243
243
  /**
244
244
  * Event types emitted by the SDK
245
245
  */
246
- type DeepdotsEventType = 'popup_shown' | 'popup_clicked' | 'survey_completed';
246
+ type DeepdotsEventType = 'popup_shown' | 'popup_clicked' | 'survey_completed'
247
+ /**
248
+ * Fallo al enviar una página del survey (el popup enseña `errorSubmit`). `data`:
249
+ * `{reason: 'send_failed' | 'no_page' | 'unknown', message}`. No es interacción del
250
+ * usuario: no marca el popup como PARTIAL. También va a analítica como `deepdots_survey_error`.
251
+ */
252
+ | 'survey_error';
247
253
  /**
248
254
  * Event payload structure
249
255
  */
@@ -342,6 +348,12 @@ interface PopupRenderer {
342
348
  show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string, userId?: string, style?: PopupStyle, sessionId?: string, miniService?: string, analyticsFeedbackSessionId?: string, renderChrome?: boolean, options?: PopupRenderOptions): void;
343
349
  /** Ocultar popup */
344
350
  hide(): void;
351
+ /**
352
+ * ¿Hay un popup a la vista ahora mismo? Opcional. Con él, el core no da por mostrado un popup
353
+ * que el renderer no va a pintar (porque ya hay otro abierto): ni `popup_shown`, ni SHOWED, ni
354
+ * cooldown gastado. Sin él (renderers del host, RN), el core se comporta como siempre.
355
+ */
356
+ isShowing?(): boolean;
345
357
  }
346
358
 
347
359
  /** Valor de un atributo de contact (info interna del usuario que solo conoce el host). */
@@ -557,6 +557,48 @@ function ddSetSurveyBusy(el, busy){
557
557
  }
558
558
  });
559
559
 
560
+ // src/ui/submitError.ts
561
+ function submitErrorText(error) {
562
+ if (!error) return "";
563
+ if (typeof error === "string") return error;
564
+ const message = error.message;
565
+ return typeof message === "string" ? message : String(error);
566
+ }
567
+ function classifySubmitError(error) {
568
+ const message = submitErrorText(error).slice(0, SURVEY_ERROR_MESSAGE_MAX);
569
+ const code = error && typeof error === "object" ? error.code : void 0;
570
+ if (typeof code === "string" && REASON_BY_CODE[code]) return { reason: REASON_BY_CODE[code], message };
571
+ if (message.toLowerCase().includes("no response")) return { reason: "required", message };
572
+ return { reason: "unknown", message };
573
+ }
574
+ var SURVEY_ERROR_MESSAGE_MAX, REASON_BY_CODE, SUBMIT_ERROR_JS;
575
+ var init_submitError = __esm({
576
+ "src/ui/submitError.ts"() {
577
+ "use strict";
578
+ SURVEY_ERROR_MESSAGE_MAX = 300;
579
+ REASON_BY_CODE = {
580
+ REQUIRED: "required",
581
+ SEND_FAILED: "send_failed",
582
+ NO_PAGE: "no_page"
583
+ };
584
+ SUBMIT_ERROR_JS = `
585
+ function ddClassifySubmitError(error){
586
+ var message='';
587
+ if(error){
588
+ if(typeof error==='string'){ message=error; }
589
+ else if(typeof error.message==='string'){ message=error.message; }
590
+ else { message=String(error); }
591
+ }
592
+ message=message.slice(0, ${SURVEY_ERROR_MESSAGE_MAX});
593
+ var byCode={ REQUIRED:'required', SEND_FAILED:'send_failed', NO_PAGE:'no_page' };
594
+ var code=error && typeof error==='object' ? error.code : undefined;
595
+ if(typeof code==='string' && byCode.hasOwnProperty(code)){ return { reason: byCode[code], message: message }; }
596
+ if(message.toLowerCase().indexOf('no response')!==-1){ return { reason: 'required', message: message }; }
597
+ return { reason: 'unknown', message: message };
598
+ }`;
599
+ }
600
+ });
601
+
560
602
  // src/assets/style.css
561
603
  var style_default;
562
604
  var init_style = __esm({
@@ -564,7 +606,7 @@ var init_style = __esm({
564
606
  style_default = `/**
565
607
  * NO EDITAR A MANO \u2014 generado por scripts/vendor-survey-css.mjs
566
608
  *
567
- * Copia de @magicfeedback/native@2.2.33 \u2192 dist/styles/magicfeedback-default.css
609
+ * Copia de @magicfeedback/native@2.2.37 \u2192 dist/styles/magicfeedback-default.css
568
610
  * (la hoja can\xF3nica del paquete, la que apunta su campo "style"), con estos cambios locales:
569
611
  *
570
612
  * 1. Sin el @import de Google Fonts (Nunito): no queremos una petici\xF3n externa desde la
@@ -1033,6 +1075,36 @@ div.magicfeedback-radio {
1033
1075
  width: 100%;
1034
1076
  }
1035
1077
 
1078
+ /* Single choice in a row (assets.direction "row"): one equal box per
1079
+ option. The "other" text field wraps to its own line below. Stacked
1080
+ (phone, or too narrow) it is the usual vertical list again. */
1081
+ .magicfeedback-radio--row {
1082
+ flex-direction: row;
1083
+ flex-wrap: wrap;
1084
+ }
1085
+
1086
+ .magicfeedback-radio--row > .magicfeedback-radio-container {
1087
+ flex: 1 1 0;
1088
+ min-width: 0;
1089
+ }
1090
+
1091
+ .magicfeedback-radio--row > .magicfeedback-extra-option {
1092
+ flex-basis: 100%;
1093
+ }
1094
+
1095
+ .magicfeedback-radio--row.magicfeedback-radio--stacked {
1096
+ flex-direction: column;
1097
+ flex-wrap: nowrap;
1098
+ }
1099
+
1100
+ .magicfeedback-radio--row.magicfeedback-radio--stacked > .magicfeedback-radio-container {
1101
+ flex: none;
1102
+ }
1103
+
1104
+ .magicfeedback-radio--row .magicfeedback-radio-container label {
1105
+ overflow-wrap: anywhere;
1106
+ }
1107
+
1036
1108
  .magicfeedback-checkbox-container,
1037
1109
  .magicfeedback-radio-container {
1038
1110
  display: flex;
@@ -1256,6 +1328,34 @@ div.magicfeedback-radio {
1256
1328
  overflow-wrap: anywhere;
1257
1329
  }
1258
1330
 
1331
+ /* assets.minMaxPlaceholderPosition: the caption above or below the row. */
1332
+ .magicfeedback-rating-number-scale-labels--top {
1333
+ margin-top: 0;
1334
+ margin-bottom: var(--mf-space-sm);
1335
+ }
1336
+
1337
+ .magicfeedback-rating-number-scale-labels--bottom {
1338
+ margin-top: var(--mf-space-sm);
1339
+ margin-bottom: 0;
1340
+ }
1341
+
1342
+ /* Row with a text per number: the text sits above each chip (below with
1343
+ numberPlaceholdersPosition "bottom"). The option is a column laid out
1344
+ inline; this only spaces and styles the text. */
1345
+ .magicfeedback-rating-number-option--captioned {
1346
+ gap: var(--mf-space-xs);
1347
+ }
1348
+
1349
+ .magicfeedback-rating-number-option-caption {
1350
+ font-size: var(--mf-font-size-sm);
1351
+ font-weight: var(--mf-font-weight-semibold);
1352
+ color: var(--mf-text-secondary);
1353
+ text-align: center;
1354
+ line-height: 1.25;
1355
+ overflow-wrap: anywhere;
1356
+ cursor: pointer;
1357
+ }
1358
+
1259
1359
  .magicfeedback-rating-number-scale-label:last-child {
1260
1360
  text-align: end;
1261
1361
  }
@@ -2930,12 +3030,14 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
2930
3030
  "top-left": { justifyContent: "flex-start", alignItems: "flex-start", padding: "16px", background: "transparent" }
2931
3031
  };
2932
3032
  const pos = positionMap[style?.position ?? "center"] ?? positionMap["center"];
3033
+ const passThrough = pos.background === "transparent";
2933
3034
  const popup = document.createElement("div");
2934
3035
  popup.id = "dd-popup";
2935
3036
  popup.className = "deepdots-popup";
2936
3037
  popup.setAttribute("dir", direction);
2937
3038
  popup.style.cssText = `
2938
3039
  position: relative;
3040
+ pointer-events: auto;
2939
3041
  display: flex;
2940
3042
  flex-direction: column;
2941
3043
  justify-content: flex-start;
@@ -3381,7 +3483,7 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
3381
3483
  }
3382
3484
  if (!container.contains(popup)) return;
3383
3485
  container.style.visibility = "visible";
3384
- container.style.pointerEvents = "";
3486
+ container.style.pointerEvents = passThrough ? "none" : "";
3385
3487
  autofocusOnOpen();
3386
3488
  }
3387
3489
  function revealWhenPainted2() {
@@ -3504,14 +3606,15 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
3504
3606
  autofocusOnOpen();
3505
3607
  }
3506
3608
  };
3609
+ let lastReportedError = null;
3507
3610
  generateOptions.beforeSubmitEvent = () => {
3508
3611
  setLoading(true);
3509
3612
  };
3510
3613
  generateOptions.afterSubmitEvent = ({ error, completed, total, progress, followup }) => {
3511
- const errText = error ? typeof error === "string" ? error : error.message ?? String(error) : "";
3512
- if (errText) {
3614
+ if (error) {
3513
3615
  setLoading(false);
3514
- if (errText.toLowerCase().includes("no response")) {
3616
+ const { reason, message } = classifySubmitError(error);
3617
+ if (reason === "required") {
3515
3618
  errorHint.textContent = labels.errorRequired;
3516
3619
  errorHint.style.display = "block";
3517
3620
  updateNavButtons();
@@ -3519,7 +3622,11 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
3519
3622
  }
3520
3623
  errorHint.textContent = labels.errorSubmit;
3521
3624
  errorHint.style.display = "block";
3522
- sdkWarn("[Deepdots] survey submit error:", errText);
3625
+ sdkWarn("[Deepdots] survey submit error:", reason, message);
3626
+ if (error !== lastReportedError) {
3627
+ lastReportedError = error;
3628
+ emit("survey_error", surveyId, { reason, message });
3629
+ }
3523
3630
  return;
3524
3631
  }
3525
3632
  errorHint.style.display = "none";
@@ -3563,6 +3670,7 @@ var init_renderPopup = __esm({
3563
3670
  init_logger();
3564
3671
  init_labels();
3565
3672
  init_reveal();
3673
+ init_submitError();
3566
3674
  import_native = __toESM(require("@magicfeedback/native"));
3567
3675
  init_style();
3568
3676
  init_reveal();
@@ -3780,6 +3888,7 @@ init_labels();
3780
3888
  init_reveal();
3781
3889
  init_surveyPalette();
3782
3890
  init_busy();
3891
+ init_submitError();
3783
3892
  init_style();
3784
3893
  var REVEAL_JS = `
3785
3894
  function ddCreateReveal(popup, onReveal, timeoutMs){
@@ -3823,7 +3932,7 @@ function trimmedOrNull(value) {
3823
3932
  }
3824
3933
  function buildSurveyHtml(opts) {
3825
3934
  const env = opts.env === "development" ? "dev" : "prod";
3826
- const version = opts.version ?? "2.2.33";
3935
+ const version = opts.version ?? "2.2.37";
3827
3936
  const cdn = `https://cdn.jsdelivr.net/npm/@magicfeedback/native@${version}/dist/magicfeedback-sdk.browser.js`;
3828
3937
  const sid = jsonForScript(opts.surveyId);
3829
3938
  const pid = jsonForScript(opts.productId);
@@ -3995,6 +4104,7 @@ ${customCss}
3995
4104
  (function(){
3996
4105
  function emit(s){ try{ if(window.ReactNativeWebView){ window.ReactNativeWebView.postMessage(s); } }catch(e){} }
3997
4106
  function emitJSON(n,p){ try{ emit(JSON.stringify({name:n,payload:p||{}})); }catch(e){} }
4107
+ var ddLastReportedError=null;
3998
4108
  window.DeepdotsClose = function(){ emitJSON('popup_close'); };
3999
4109
  var chromeOn=${chrome ? "true" : "false"};
4000
4110
 
@@ -4175,6 +4285,7 @@ ${customCss}
4175
4285
 
4176
4286
  ${PRIMARY_COLOR_JS}
4177
4287
  ${BUSY_JS}
4288
+ ${SUBMIT_ERROR_JS}
4178
4289
  ${REVEAL_JS}
4179
4290
  // Foco en la primera pregunta si es de escribir. Al navegar lo pone @magicfeedback/native
4180
4291
  // (autofocus:'navigation'); la apertura la decide el popup, que es quien sabe cu\xE1ndo se revela.
@@ -4326,10 +4437,10 @@ ${REVEAL_JS}
4326
4437
  emitJSON('before_submit');
4327
4438
  },
4328
4439
  afterSubmitEvent:function(p){
4329
- var error=p && p.error ? (typeof p.error==='string' ? p.error : String(p.error)) : '';
4330
- if(error){
4440
+ if(p && p.error){
4331
4441
  setLoading(false);
4332
- if(error.toLowerCase().indexOf('no response')!==-1){
4442
+ var ddErr=ddClassifySubmitError(p.error);
4443
+ if(ddErr.reason==='required'){
4333
4444
  // La p\xE1gina no ha cambiado: el estado de navegaci\xF3n se queda como estaba.
4334
4445
  errorHint.textContent=DD_LABELS_ACTIVE.errorRequired;
4335
4446
  errorHint.style.display='block';
@@ -4338,6 +4449,11 @@ ${REVEAL_JS}
4338
4449
  }
4339
4450
  errorHint.textContent=DD_LABELS_ACTIVE.errorSubmit;
4340
4451
  errorHint.style.display='block';
4452
+ // Un solo aviso por fallo: native repite el mismo objeto al cerrar el survey.
4453
+ if(p.error!==ddLastReportedError){
4454
+ ddLastReportedError=p.error;
4455
+ emitJSON('survey_error', ddErr);
4456
+ }
4341
4457
  return;
4342
4458
  }
4343
4459
  errorHint.style.display='none';
@@ -4462,8 +4578,9 @@ var ReactNativePopupRenderer = class {
4462
4578
  const surveyId = this.currentSurveyId;
4463
4579
  if (!surveyId || !this.emitFn) return;
4464
4580
  let name;
4581
+ let payload;
4465
4582
  try {
4466
- name = JSON.parse(raw).name;
4583
+ ({ name, payload } = JSON.parse(raw));
4467
4584
  } catch {
4468
4585
  name = raw;
4469
4586
  }
@@ -4484,6 +4601,9 @@ var ReactNativePopupRenderer = class {
4484
4601
  case "survey_completed":
4485
4602
  this.emitFn("survey_completed", surveyId);
4486
4603
  break;
4604
+ case "survey_error":
4605
+ this.emitFn("survey_error", surveyId, { reason: payload?.reason, message: payload?.message });
4606
+ break;
4487
4607
  case "popup_close":
4488
4608
  this.onCloseFn?.();
4489
4609
  break;
@@ -4528,6 +4648,7 @@ function schedulePreloadRenderPopup(loader) {
4528
4648
  }
4529
4649
 
4530
4650
  // src/platform/renderer.ts
4651
+ init_logger();
4531
4652
  var NoopPopupRenderer = class {
4532
4653
  show() {
4533
4654
  }
@@ -4574,9 +4695,18 @@ var BrowserPopupRenderer = class {
4574
4695
  if (!this.container) return;
4575
4696
  this.visible = true;
4576
4697
  const container = this.container;
4577
- void Promise.resolve().then(() => (init_renderPopup(), renderPopup_exports)).then(({ renderPopup: renderPopup2 }) => {
4578
- renderPopup2(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
4579
- });
4698
+ void Promise.resolve().then(() => (init_renderPopup(), renderPopup_exports)).then(
4699
+ ({ renderPopup: renderPopup2 }) => {
4700
+ renderPopup2(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
4701
+ },
4702
+ (error) => {
4703
+ this.visible = false;
4704
+ sdkWarn("[Deepdots] popup renderer failed to load:", error);
4705
+ }
4706
+ );
4707
+ }
4708
+ isShowing() {
4709
+ return this.visible;
4580
4710
  }
4581
4711
  hide() {
4582
4712
  this.visible = false;
@@ -6526,6 +6656,10 @@ var DeepdotsPopups = class {
6526
6656
  });
6527
6657
  }
6528
6658
  showDefinition(def) {
6659
+ if (this.renderer.isShowing?.()) {
6660
+ this.debug("Popup skipped: another popup is already open", def.id);
6661
+ return;
6662
+ }
6529
6663
  this.log("Showing popup (definition)", def);
6530
6664
  this.surveyToPopupId.set(def.surveyId, def.id);
6531
6665
  this.lastShown.set(def.id, Date.now());
@@ -6932,6 +7066,15 @@ var DeepdotsPopups = class {
6932
7066
  emitEvent(type, surveyId, data) {
6933
7067
  const event = { type, surveyId, timestamp: Date.now(), data };
6934
7068
  this.log("Event emitted", event);
7069
+ if (type === "survey_error") {
7070
+ const popupId = data?.popupId || this.surveyToPopupId.get(surveyId);
7071
+ this.track("deepdots_survey_error", {
7072
+ survey_id: surveyId,
7073
+ ...popupId ? { popup_id: popupId } : {},
7074
+ reason: data?.reason,
7075
+ message: data?.message
7076
+ });
7077
+ }
6935
7078
  const isPartialClick = type === "popup_clicked" && data?.action === "partial";
6936
7079
  if (isPartialClick) {
6937
7080
  this.markSurveyProgress(surveyId, "PARTIAL");