@product7/feedback-sdk 1.5.0 → 1.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/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 () => {
|
|
@@ -7395,7 +7423,11 @@
|
|
|
7395
7423
|
|
|
7396
7424
|
try {
|
|
7397
7425
|
const result = await this.apiService.getActiveSurveys(context);
|
|
7398
|
-
|
|
7426
|
+
const surveys = result.data || [];
|
|
7427
|
+
if (context.includeIneligible) {
|
|
7428
|
+
return surveys;
|
|
7429
|
+
}
|
|
7430
|
+
return surveys.filter((survey) => this._isSurveyEligible(survey));
|
|
7399
7431
|
} catch (error) {
|
|
7400
7432
|
this.eventBus.emit('sdk:error', { error });
|
|
7401
7433
|
throw new SDKError(
|
|
@@ -7412,7 +7444,12 @@
|
|
|
7412
7444
|
);
|
|
7413
7445
|
}
|
|
7414
7446
|
|
|
7415
|
-
const
|
|
7447
|
+
const { context = {}, ...displayOptions } = options;
|
|
7448
|
+
const surveys = await this.getActiveSurveys({
|
|
7449
|
+
...context,
|
|
7450
|
+
includeEligibility: true,
|
|
7451
|
+
includeIneligible: true,
|
|
7452
|
+
});
|
|
7416
7453
|
const surveyConfig = surveys.find((s) => s.id === surveyId);
|
|
7417
7454
|
|
|
7418
7455
|
if (!surveyConfig) {
|
|
@@ -7421,6 +7458,15 @@
|
|
|
7421
7458
|
);
|
|
7422
7459
|
}
|
|
7423
7460
|
|
|
7461
|
+
if (!this._isSurveyEligible(surveyConfig)) {
|
|
7462
|
+
this.eventBus.emit('survey:suppressed', {
|
|
7463
|
+
surveyId,
|
|
7464
|
+
reason: this._getSurveyIneligibilityReason(surveyConfig),
|
|
7465
|
+
survey: surveyConfig,
|
|
7466
|
+
});
|
|
7467
|
+
return null;
|
|
7468
|
+
}
|
|
7469
|
+
|
|
7424
7470
|
return this.showSurvey({
|
|
7425
7471
|
surveyId: surveyConfig.id,
|
|
7426
7472
|
surveyType: surveyConfig.type,
|
|
@@ -7429,7 +7475,7 @@
|
|
|
7429
7475
|
lowLabel: surveyConfig.low_label,
|
|
7430
7476
|
highLabel: surveyConfig.high_label,
|
|
7431
7477
|
customQuestions: surveyConfig.questions,
|
|
7432
|
-
...
|
|
7478
|
+
...displayOptions,
|
|
7433
7479
|
});
|
|
7434
7480
|
}
|
|
7435
7481
|
|
|
@@ -7440,6 +7486,15 @@
|
|
|
7440
7486
|
);
|
|
7441
7487
|
}
|
|
7442
7488
|
|
|
7489
|
+
if (!this._isSurveyEligible(options)) {
|
|
7490
|
+
this.eventBus.emit('survey:suppressed', {
|
|
7491
|
+
surveyId: options.surveyId || options.id || null,
|
|
7492
|
+
reason: this._getSurveyIneligibilityReason(options),
|
|
7493
|
+
survey: options,
|
|
7494
|
+
});
|
|
7495
|
+
return null;
|
|
7496
|
+
}
|
|
7497
|
+
|
|
7443
7498
|
const surveyWidget = this.createWidget('survey', {
|
|
7444
7499
|
surveyId: options.surveyId,
|
|
7445
7500
|
surveyType: options.surveyType || options.type || 'nps',
|
|
@@ -7460,6 +7515,56 @@
|
|
|
7460
7515
|
return surveyWidget;
|
|
7461
7516
|
}
|
|
7462
7517
|
|
|
7518
|
+
_isSurveyEligible(survey = {}) {
|
|
7519
|
+
const shouldShow = this._getSurveyField(survey, ['shouldShow', 'should_show']);
|
|
7520
|
+
if (typeof shouldShow === 'boolean') {
|
|
7521
|
+
return shouldShow;
|
|
7522
|
+
}
|
|
7523
|
+
|
|
7524
|
+
const eligible = this._getSurveyField(survey, [
|
|
7525
|
+
'eligible',
|
|
7526
|
+
'isEligible',
|
|
7527
|
+
'is_eligible',
|
|
7528
|
+
]);
|
|
7529
|
+
if (typeof eligible === 'boolean') {
|
|
7530
|
+
return eligible;
|
|
7531
|
+
}
|
|
7532
|
+
|
|
7533
|
+
const isAnswered = this._getSurveyField(survey, ['isAnswered', 'is_answered']);
|
|
7534
|
+
if (typeof isAnswered === 'boolean') {
|
|
7535
|
+
return !isAnswered;
|
|
7536
|
+
}
|
|
7537
|
+
|
|
7538
|
+
return true;
|
|
7539
|
+
}
|
|
7540
|
+
|
|
7541
|
+
_getSurveyIneligibilityReason(survey = {}) {
|
|
7542
|
+
const explicitReason = this._getSurveyField(survey, [
|
|
7543
|
+
'reason',
|
|
7544
|
+
'suppressionReason',
|
|
7545
|
+
'suppression_reason',
|
|
7546
|
+
]);
|
|
7547
|
+
if (explicitReason) {
|
|
7548
|
+
return explicitReason;
|
|
7549
|
+
}
|
|
7550
|
+
|
|
7551
|
+
const isAnswered = this._getSurveyField(survey, ['isAnswered', 'is_answered']);
|
|
7552
|
+
if (isAnswered === true) {
|
|
7553
|
+
return 'already_answered';
|
|
7554
|
+
}
|
|
7555
|
+
|
|
7556
|
+
return 'ineligible';
|
|
7557
|
+
}
|
|
7558
|
+
|
|
7559
|
+
_getSurveyField(survey, fields) {
|
|
7560
|
+
for (const field of fields) {
|
|
7561
|
+
if (survey[field] !== undefined && survey[field] !== null) {
|
|
7562
|
+
return survey[field];
|
|
7563
|
+
}
|
|
7564
|
+
}
|
|
7565
|
+
return null;
|
|
7566
|
+
}
|
|
7567
|
+
|
|
7463
7568
|
showChangelog(options = {}) {
|
|
7464
7569
|
if (!this.initialized) {
|
|
7465
7570
|
throw new SDKError(
|