@product7/product7-js 0.4.9 → 0.5.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/product7-js.js +71 -34
- package/dist/product7-js.js.map +1 -1
- package/dist/product7-js.min.js +1 -1
- package/dist/product7-js.min.js.map +1 -1
- package/package.json +1 -1
- package/src/api/services/SurveyService.js +2 -3
- package/src/core/Product7.js +1 -0
- package/src/styles/survey.js +6 -0
- package/src/widgets/SurveyWidget.js +62 -31
package/package.json
CHANGED
|
@@ -81,9 +81,8 @@ export class SurveyService {
|
|
|
81
81
|
const contact = this.api.getContactIdentity?.() || null;
|
|
82
82
|
|
|
83
83
|
const payload = {
|
|
84
|
-
|
|
85
|
-
feedback: responseData.feedback
|
|
86
|
-
answers: responseData.answers || {},
|
|
84
|
+
answers: Array.isArray(responseData.answers) ? responseData.answers : [],
|
|
85
|
+
...(responseData.feedback && { feedback: responseData.feedback }),
|
|
87
86
|
...(respondent.respondent_id && {
|
|
88
87
|
respondent_id: respondent.respondent_id,
|
|
89
88
|
}),
|
package/src/core/Product7.js
CHANGED
|
@@ -456,6 +456,7 @@ export class Product7 {
|
|
|
456
456
|
page.multipleChoiceConfig || page.multiple_choice_config || null,
|
|
457
457
|
linkConfig: page.linkConfig || page.link_config || null,
|
|
458
458
|
afterThisPage: page.afterThisPage || page.after_this_page || null,
|
|
459
|
+
thankYouConfig: page.thankYouConfig || page.thank_you_config || null,
|
|
459
460
|
}))
|
|
460
461
|
.sort((a, b) => a.position - b.position);
|
|
461
462
|
}
|
package/src/styles/survey.js
CHANGED
|
@@ -508,6 +508,12 @@ export const surveyStyles = `
|
|
|
508
508
|
}
|
|
509
509
|
|
|
510
510
|
.feedback-survey-page-choice-btn.selected::after {
|
|
511
|
+
content: '✓';
|
|
512
|
+
color: #ffffff;
|
|
513
|
+
font-size: 11px;
|
|
514
|
+
font-weight: 700;
|
|
515
|
+
line-height: 18px;
|
|
516
|
+
text-align: center;
|
|
511
517
|
border-color: var(--color-primary);
|
|
512
518
|
background-color: var(--color-primary);
|
|
513
519
|
}
|
|
@@ -912,28 +912,18 @@ export class SurveyWidget extends BaseWidget {
|
|
|
912
912
|
this._setSubmitLoading(true);
|
|
913
913
|
|
|
914
914
|
const respondent = this._getRespondentContext();
|
|
915
|
-
const normalizedPageAnswers = this._normalizePageAnswersForSubmit();
|
|
916
|
-
const mergedAnswers = {
|
|
917
|
-
...this.surveyState.customAnswers,
|
|
918
|
-
...(Object.keys(normalizedPageAnswers).length > 0 && {
|
|
919
|
-
page_answers: normalizedPageAnswers,
|
|
920
|
-
}),
|
|
921
|
-
};
|
|
922
915
|
|
|
923
916
|
const responseData = {
|
|
924
|
-
|
|
925
|
-
feedback: this.surveyState.feedback,
|
|
926
|
-
answers: mergedAnswers,
|
|
917
|
+
answers: this._normalizePageAnswersForSubmit(),
|
|
918
|
+
...(this.surveyState.feedback && { feedback: this.surveyState.feedback }),
|
|
927
919
|
...(respondent.respondentId && { respondentId: respondent.respondentId }),
|
|
928
920
|
...(respondent.email && { email: respondent.email }),
|
|
929
921
|
};
|
|
930
922
|
|
|
931
923
|
const response = {
|
|
932
924
|
type: type,
|
|
933
|
-
|
|
925
|
+
answers: responseData.answers,
|
|
934
926
|
feedback: this.surveyState.feedback,
|
|
935
|
-
customAnswers: mergedAnswers,
|
|
936
|
-
pageAnswers: normalizedPageAnswers,
|
|
937
927
|
timestamp: new Date().toISOString(),
|
|
938
928
|
};
|
|
939
929
|
|
|
@@ -1117,27 +1107,58 @@ export class SurveyWidget extends BaseWidget {
|
|
|
1117
1107
|
}
|
|
1118
1108
|
|
|
1119
1109
|
_normalizePageAnswersForSubmit() {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
this.surveyState.
|
|
1123
|
-
|
|
1124
|
-
if (answer == null) continue;
|
|
1125
|
-
if (Array.isArray(answer.values) && answer.values.length > 0) {
|
|
1126
|
-
output[pageId] = answer.values;
|
|
1127
|
-
continue;
|
|
1128
|
-
}
|
|
1129
|
-
if (answer.value != null && answer.value !== '') {
|
|
1130
|
-
output[pageId] = answer.value;
|
|
1131
|
-
continue;
|
|
1110
|
+
// Single-rating surveys (NPS / CSAT / CES / star / emoji) have no pages
|
|
1111
|
+
if (!this._isMultiPageSurvey()) {
|
|
1112
|
+
if (typeof this.surveyState.score === 'number') {
|
|
1113
|
+
return [{ page_id: 'p1', value: this.surveyState.score }];
|
|
1132
1114
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1115
|
+
return [];
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
const output = [];
|
|
1119
|
+
|
|
1120
|
+
for (const page of this.surveyOptions.pages) {
|
|
1121
|
+
const pageId =
|
|
1122
|
+
page.id || `page_${this.surveyOptions.pages.indexOf(page)}`;
|
|
1123
|
+
const answer = this.surveyState.pageAnswers[pageId];
|
|
1124
|
+
if (answer == null) continue;
|
|
1125
|
+
|
|
1126
|
+
let value = null;
|
|
1127
|
+
|
|
1128
|
+
if (page.type === 'rating' && typeof answer.rating === 'number') {
|
|
1129
|
+
value = answer.rating;
|
|
1130
|
+
} else if (page.type === 'multiple_choice') {
|
|
1131
|
+
const config =
|
|
1132
|
+
page.multipleChoiceConfig || page.multiple_choice_config || {};
|
|
1133
|
+
const allowMultiple =
|
|
1134
|
+
config.allow_multiple === true ||
|
|
1135
|
+
config.multiple === true ||
|
|
1136
|
+
config.allow_multiple_selection === true;
|
|
1137
|
+
|
|
1138
|
+
if (
|
|
1139
|
+
allowMultiple &&
|
|
1140
|
+
Array.isArray(answer.values) &&
|
|
1141
|
+
answer.values.length > 0
|
|
1142
|
+
) {
|
|
1143
|
+
value = answer.values;
|
|
1144
|
+
} else if (answer.value != null && answer.value !== '') {
|
|
1145
|
+
value = answer.value;
|
|
1146
|
+
}
|
|
1147
|
+
} else if (
|
|
1148
|
+
page.type === 'text' &&
|
|
1149
|
+
typeof answer.text === 'string' &&
|
|
1150
|
+
answer.text.trim()
|
|
1151
|
+
) {
|
|
1152
|
+
value = answer.text.trim();
|
|
1153
|
+
} else if (page.type === 'link' && typeof answer.clicked === 'boolean') {
|
|
1154
|
+
value = answer.clicked;
|
|
1136
1155
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1156
|
+
|
|
1157
|
+
if (value !== null) {
|
|
1158
|
+
output.push({ page_id: pageId, value });
|
|
1139
1159
|
}
|
|
1140
1160
|
}
|
|
1161
|
+
|
|
1141
1162
|
return output;
|
|
1142
1163
|
}
|
|
1143
1164
|
|
|
@@ -1200,7 +1221,17 @@ export class SurveyWidget extends BaseWidget {
|
|
|
1200
1221
|
_showThankYouScreen(onAfterClose) {
|
|
1201
1222
|
if (!this.surveyElement) return;
|
|
1202
1223
|
|
|
1203
|
-
const
|
|
1224
|
+
const pages = this.surveyOptions.pages || [];
|
|
1225
|
+
const currentPage =
|
|
1226
|
+
pages[this.surveyState.currentPageIndex] ||
|
|
1227
|
+
pages[pages.length - 1] ||
|
|
1228
|
+
null;
|
|
1229
|
+
const pageConfig = currentPage?.thankYouConfig || null;
|
|
1230
|
+
const surveyConfig = this.surveyOptions.thankYouConfig || null;
|
|
1231
|
+
const config =
|
|
1232
|
+
(pageConfig?.title ? pageConfig : null) ||
|
|
1233
|
+
(surveyConfig?.title ? surveyConfig : null) ||
|
|
1234
|
+
{};
|
|
1204
1235
|
const title = config.title || 'Thanks for your feedback!';
|
|
1205
1236
|
const buttonText = config.button_text || null;
|
|
1206
1237
|
const buttonUrl = config.button_url || '#';
|