@product7/feedback-sdk 1.5.0 → 1.5.2
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/feedback-sdk.js +144 -3
- package/dist/feedback-sdk.js.map +1 -1
- package/dist/feedback-sdk.min.js +1 -1
- package/dist/feedback-sdk.min.js.map +1 -1
- package/package.json +1 -1
- package/src/api/services/SurveyService.js +28 -0
- package/src/core/FeedbackSDK.js +82 -3
- package/src/widgets/SurveyWidget.js +34 -0
- package/types/index.d.ts +2 -0
package/dist/feedback-sdk.js
CHANGED
|
@@ -720,11 +720,20 @@
|
|
|
720
720
|
return { success: true, data: MOCK_SURVEYS };
|
|
721
721
|
}
|
|
722
722
|
|
|
723
|
+
const respondent = this._getRespondentContext(context);
|
|
724
|
+
|
|
723
725
|
const params = {
|
|
724
726
|
url:
|
|
725
727
|
context.url ||
|
|
726
728
|
(typeof window !== 'undefined' ? window.location.href : ''),
|
|
727
729
|
...getDeviceInfo(),
|
|
730
|
+
...(respondent.respondent_id && {
|
|
731
|
+
respondent_id: respondent.respondent_id,
|
|
732
|
+
}),
|
|
733
|
+
...(respondent.email && { email: respondent.email }),
|
|
734
|
+
...(context.includeEligibility !== undefined && {
|
|
735
|
+
include_eligibility: context.includeEligibility,
|
|
736
|
+
}),
|
|
728
737
|
...(context.userProperties && {
|
|
729
738
|
user_properties: context.userProperties,
|
|
730
739
|
}),
|
|
@@ -742,6 +751,19 @@
|
|
|
742
751
|
});
|
|
743
752
|
}
|
|
744
753
|
|
|
754
|
+
_getRespondentContext(context = {}) {
|
|
755
|
+
const userContext =
|
|
756
|
+
typeof this.api.getUserContext === 'function'
|
|
757
|
+
? this.api.getUserContext() || {}
|
|
758
|
+
: {};
|
|
759
|
+
|
|
760
|
+
return {
|
|
761
|
+
respondent_id:
|
|
762
|
+
context.respondentId || context.userId || userContext.user_id || null,
|
|
763
|
+
email: context.email || userContext.email || null,
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
|
|
745
767
|
async submitSurveyResponse(surveyId, responseData) {
|
|
746
768
|
if (!surveyId) throw new APIError$1(400, 'Survey ID is required');
|
|
747
769
|
|
|
@@ -760,10 +782,16 @@
|
|
|
760
782
|
};
|
|
761
783
|
}
|
|
762
784
|
|
|
785
|
+
const respondent = this._getRespondentContext(responseData);
|
|
786
|
+
|
|
763
787
|
const payload = {
|
|
764
788
|
rating: responseData.rating,
|
|
765
789
|
feedback: responseData.feedback || '',
|
|
766
790
|
answers: responseData.answers || {},
|
|
791
|
+
...(respondent.respondent_id && {
|
|
792
|
+
respondent_id: respondent.respondent_id,
|
|
793
|
+
}),
|
|
794
|
+
...(respondent.email && { email: respondent.email }),
|
|
767
795
|
};
|
|
768
796
|
|
|
769
797
|
return this.api._handleAuthRetry(async () => {
|
|
@@ -6701,6 +6729,8 @@
|
|
|
6701
6729
|
lowLabel: options.lowLabel || null,
|
|
6702
6730
|
highLabel: options.highLabel || null,
|
|
6703
6731
|
customQuestions: options.customQuestions || [],
|
|
6732
|
+
respondentId: options.respondentId || null,
|
|
6733
|
+
email: options.email || null,
|
|
6704
6734
|
onSubmit: options.onSubmit || null,
|
|
6705
6735
|
onDismiss: options.onDismiss || null,
|
|
6706
6736
|
};
|
|
@@ -7069,10 +7099,14 @@
|
|
|
7069
7099
|
return;
|
|
7070
7100
|
}
|
|
7071
7101
|
|
|
7102
|
+
const respondent = this._getRespondentContext();
|
|
7103
|
+
|
|
7072
7104
|
const responseData = {
|
|
7073
7105
|
rating: this.surveyState.score,
|
|
7074
7106
|
feedback: this.surveyState.feedback,
|
|
7075
7107
|
answers: this.surveyState.customAnswers,
|
|
7108
|
+
...(respondent.respondentId && { respondentId: respondent.respondentId }),
|
|
7109
|
+
...(respondent.email && { email: respondent.email }),
|
|
7076
7110
|
};
|
|
7077
7111
|
|
|
7078
7112
|
const response = {
|
|
@@ -7101,6 +7135,34 @@
|
|
|
7101
7135
|
this._showSuccessNotification();
|
|
7102
7136
|
}
|
|
7103
7137
|
|
|
7138
|
+
_getRespondentContext() {
|
|
7139
|
+
const sdkUserContext =
|
|
7140
|
+
typeof this.sdk.getUserContext === 'function'
|
|
7141
|
+
? this.sdk.getUserContext() || {}
|
|
7142
|
+
: {};
|
|
7143
|
+
const apiUserContext =
|
|
7144
|
+
this.apiService &&
|
|
7145
|
+
typeof this.apiService.getUserContext === 'function'
|
|
7146
|
+
? this.apiService.getUserContext() || {}
|
|
7147
|
+
: {};
|
|
7148
|
+
const localUserContext = this.options.userContext || {};
|
|
7149
|
+
|
|
7150
|
+
return {
|
|
7151
|
+
respondentId:
|
|
7152
|
+
this.surveyOptions.respondentId ||
|
|
7153
|
+
localUserContext.user_id ||
|
|
7154
|
+
sdkUserContext.user_id ||
|
|
7155
|
+
apiUserContext.user_id ||
|
|
7156
|
+
null,
|
|
7157
|
+
email:
|
|
7158
|
+
this.surveyOptions.email ||
|
|
7159
|
+
localUserContext.email ||
|
|
7160
|
+
sdkUserContext.email ||
|
|
7161
|
+
apiUserContext.email ||
|
|
7162
|
+
null,
|
|
7163
|
+
};
|
|
7164
|
+
}
|
|
7165
|
+
|
|
7104
7166
|
async _handleDismiss() {
|
|
7105
7167
|
if (this.surveyOptions.surveyId) {
|
|
7106
7168
|
try {
|
|
@@ -7395,7 +7457,11 @@
|
|
|
7395
7457
|
|
|
7396
7458
|
try {
|
|
7397
7459
|
const result = await this.apiService.getActiveSurveys(context);
|
|
7398
|
-
|
|
7460
|
+
const surveys = result.data || [];
|
|
7461
|
+
if (context.includeIneligible) {
|
|
7462
|
+
return surveys;
|
|
7463
|
+
}
|
|
7464
|
+
return surveys.filter((survey) => this._isSurveyEligible(survey));
|
|
7399
7465
|
} catch (error) {
|
|
7400
7466
|
this.eventBus.emit('sdk:error', { error });
|
|
7401
7467
|
throw new SDKError(
|
|
@@ -7412,7 +7478,12 @@
|
|
|
7412
7478
|
);
|
|
7413
7479
|
}
|
|
7414
7480
|
|
|
7415
|
-
const
|
|
7481
|
+
const { context = {}, ...displayOptions } = options;
|
|
7482
|
+
const surveys = await this.getActiveSurveys({
|
|
7483
|
+
...context,
|
|
7484
|
+
includeEligibility: true,
|
|
7485
|
+
includeIneligible: true,
|
|
7486
|
+
});
|
|
7416
7487
|
const surveyConfig = surveys.find((s) => s.id === surveyId);
|
|
7417
7488
|
|
|
7418
7489
|
if (!surveyConfig) {
|
|
@@ -7421,6 +7492,15 @@
|
|
|
7421
7492
|
);
|
|
7422
7493
|
}
|
|
7423
7494
|
|
|
7495
|
+
if (!this._isSurveyEligible(surveyConfig)) {
|
|
7496
|
+
this.eventBus.emit('survey:suppressed', {
|
|
7497
|
+
surveyId,
|
|
7498
|
+
reason: this._getSurveyIneligibilityReason(surveyConfig),
|
|
7499
|
+
survey: surveyConfig,
|
|
7500
|
+
});
|
|
7501
|
+
return null;
|
|
7502
|
+
}
|
|
7503
|
+
|
|
7424
7504
|
return this.showSurvey({
|
|
7425
7505
|
surveyId: surveyConfig.id,
|
|
7426
7506
|
surveyType: surveyConfig.type,
|
|
@@ -7429,7 +7509,7 @@
|
|
|
7429
7509
|
lowLabel: surveyConfig.low_label,
|
|
7430
7510
|
highLabel: surveyConfig.high_label,
|
|
7431
7511
|
customQuestions: surveyConfig.questions,
|
|
7432
|
-
...
|
|
7512
|
+
...displayOptions,
|
|
7433
7513
|
});
|
|
7434
7514
|
}
|
|
7435
7515
|
|
|
@@ -7440,6 +7520,15 @@
|
|
|
7440
7520
|
);
|
|
7441
7521
|
}
|
|
7442
7522
|
|
|
7523
|
+
if (!this._isSurveyEligible(options)) {
|
|
7524
|
+
this.eventBus.emit('survey:suppressed', {
|
|
7525
|
+
surveyId: options.surveyId || options.id || null,
|
|
7526
|
+
reason: this._getSurveyIneligibilityReason(options),
|
|
7527
|
+
survey: options,
|
|
7528
|
+
});
|
|
7529
|
+
return null;
|
|
7530
|
+
}
|
|
7531
|
+
|
|
7443
7532
|
const surveyWidget = this.createWidget('survey', {
|
|
7444
7533
|
surveyId: options.surveyId,
|
|
7445
7534
|
surveyType: options.surveyType || options.type || 'nps',
|
|
@@ -7450,6 +7539,8 @@
|
|
|
7450
7539
|
lowLabel: options.lowLabel,
|
|
7451
7540
|
highLabel: options.highLabel,
|
|
7452
7541
|
customQuestions: options.customQuestions,
|
|
7542
|
+
respondentId: options.respondentId,
|
|
7543
|
+
email: options.email,
|
|
7453
7544
|
onSubmit: options.onSubmit,
|
|
7454
7545
|
onDismiss: options.onDismiss,
|
|
7455
7546
|
});
|
|
@@ -7460,6 +7551,56 @@
|
|
|
7460
7551
|
return surveyWidget;
|
|
7461
7552
|
}
|
|
7462
7553
|
|
|
7554
|
+
_isSurveyEligible(survey = {}) {
|
|
7555
|
+
const shouldShow = this._getSurveyField(survey, ['shouldShow', 'should_show']);
|
|
7556
|
+
if (typeof shouldShow === 'boolean') {
|
|
7557
|
+
return shouldShow;
|
|
7558
|
+
}
|
|
7559
|
+
|
|
7560
|
+
const eligible = this._getSurveyField(survey, [
|
|
7561
|
+
'eligible',
|
|
7562
|
+
'isEligible',
|
|
7563
|
+
'is_eligible',
|
|
7564
|
+
]);
|
|
7565
|
+
if (typeof eligible === 'boolean') {
|
|
7566
|
+
return eligible;
|
|
7567
|
+
}
|
|
7568
|
+
|
|
7569
|
+
const isAnswered = this._getSurveyField(survey, ['isAnswered', 'is_answered']);
|
|
7570
|
+
if (typeof isAnswered === 'boolean') {
|
|
7571
|
+
return !isAnswered;
|
|
7572
|
+
}
|
|
7573
|
+
|
|
7574
|
+
return true;
|
|
7575
|
+
}
|
|
7576
|
+
|
|
7577
|
+
_getSurveyIneligibilityReason(survey = {}) {
|
|
7578
|
+
const explicitReason = this._getSurveyField(survey, [
|
|
7579
|
+
'reason',
|
|
7580
|
+
'suppressionReason',
|
|
7581
|
+
'suppression_reason',
|
|
7582
|
+
]);
|
|
7583
|
+
if (explicitReason) {
|
|
7584
|
+
return explicitReason;
|
|
7585
|
+
}
|
|
7586
|
+
|
|
7587
|
+
const isAnswered = this._getSurveyField(survey, ['isAnswered', 'is_answered']);
|
|
7588
|
+
if (isAnswered === true) {
|
|
7589
|
+
return 'already_answered';
|
|
7590
|
+
}
|
|
7591
|
+
|
|
7592
|
+
return 'ineligible';
|
|
7593
|
+
}
|
|
7594
|
+
|
|
7595
|
+
_getSurveyField(survey, fields) {
|
|
7596
|
+
for (const field of fields) {
|
|
7597
|
+
if (survey[field] !== undefined && survey[field] !== null) {
|
|
7598
|
+
return survey[field];
|
|
7599
|
+
}
|
|
7600
|
+
}
|
|
7601
|
+
return null;
|
|
7602
|
+
}
|
|
7603
|
+
|
|
7463
7604
|
showChangelog(options = {}) {
|
|
7464
7605
|
if (!this.initialized) {
|
|
7465
7606
|
throw new SDKError(
|