@ninetailed/experience.js 2.0.0-beta.19 → 2.0.0-beta.22
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/index.esm.js
CHANGED
|
@@ -3850,12 +3850,12 @@ const selectActiveExperiments = (experiments, profile) => {
|
|
|
3850
3850
|
};
|
|
3851
3851
|
|
|
3852
3852
|
/**
|
|
3853
|
-
* We can use any personalization as
|
|
3853
|
+
* We can use any personalization as eligible experience
|
|
3854
3854
|
* When going for an experiment we can only select a active experiment when 1 or more experiments are active
|
|
3855
3855
|
* If the profile is not in any active experiments, we can select any expermiment
|
|
3856
3856
|
*/
|
|
3857
3857
|
|
|
3858
|
-
const
|
|
3858
|
+
const selectEligibleExperiences = ({
|
|
3859
3859
|
experiences,
|
|
3860
3860
|
activeExperiments
|
|
3861
3861
|
}) => {
|
|
@@ -3878,29 +3878,39 @@ const getRandom = text => {
|
|
|
3878
3878
|
const getTrafficRandom = (profile, experience) => getRandom(`traffic-${experience.id}-${profile.id}`);
|
|
3879
3879
|
const getDistributionRandom = (profile, experience) => getRandom(`distribution-${experience.id}-${profile.id}`);
|
|
3880
3880
|
|
|
3881
|
+
const isExperienceMatch = ({
|
|
3882
|
+
experience,
|
|
3883
|
+
activeExperiments,
|
|
3884
|
+
profile
|
|
3885
|
+
}) => {
|
|
3886
|
+
const trafficRandom = getTrafficRandom(profile, experience);
|
|
3887
|
+
log(`The traffic random factor for experience ${experience.id} is ${trafficRandom}. It's traffic allocation is set to ${experience.trafficAllocation}.`);
|
|
3888
|
+
const isInTrafficRange = experience.trafficAllocation > trafficRandom;
|
|
3889
|
+
const matchesAudience = !experience.audience || includes(profile.audiences, experience.audience.id);
|
|
3890
|
+
const hasActiveExperiment = find(activeExperiments, {
|
|
3891
|
+
id: experience.id
|
|
3892
|
+
});
|
|
3893
|
+
log(`Is the profile in traffic allocation range? ${isInTrafficRange ? 'yes' : 'no'}.\n
|
|
3894
|
+
Does the profile match the audience of the experience? ${matchesAudience ? 'yes' : 'no'}.\n
|
|
3895
|
+
Is there an active experiment for this profile? ${hasActiveExperiment ? 'yes' : 'no'}.`);
|
|
3896
|
+
return isInTrafficRange && (matchesAudience || // if the expriment is active already then it's selectible without further contraints to be fullfilled
|
|
3897
|
+
hasActiveExperiment);
|
|
3898
|
+
};
|
|
3899
|
+
|
|
3881
3900
|
const selectExperience = ({
|
|
3882
3901
|
experiences,
|
|
3883
3902
|
activeExperiments,
|
|
3884
3903
|
profile
|
|
3885
3904
|
}) => {
|
|
3886
|
-
const
|
|
3905
|
+
const eligibleExperiences = selectEligibleExperiences({
|
|
3887
3906
|
experiences,
|
|
3888
3907
|
activeExperiments
|
|
3889
3908
|
});
|
|
3890
|
-
const selectedExperience =
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
const hasActiveExperiment = find(activeExperiments, {
|
|
3896
|
-
id: experience.id
|
|
3897
|
-
});
|
|
3898
|
-
log(`Is the profile in traffic allocation range? ${isInTrafficRange ? 'yes' : 'no'}.\n
|
|
3899
|
-
Does the profile match the audience of the experience? ${matchesAudience ? 'yes' : 'no'}.\n
|
|
3900
|
-
Is there an active experiment for this profile? ${hasActiveExperiment ? 'yes' : 'no'}.`);
|
|
3901
|
-
return isInTrafficRange && (matchesAudience || // if the expriment is active already then it's selectible without further contraints to be fullfilled
|
|
3902
|
-
hasActiveExperiment);
|
|
3903
|
-
});
|
|
3909
|
+
const selectedExperience = eligibleExperiences.find(experience => isExperienceMatch({
|
|
3910
|
+
experience,
|
|
3911
|
+
activeExperiments,
|
|
3912
|
+
profile
|
|
3913
|
+
}));
|
|
3904
3914
|
return selectedExperience;
|
|
3905
3915
|
};
|
|
3906
3916
|
|
|
@@ -3955,4 +3965,4 @@ const selectVariant = ({
|
|
|
3955
3965
|
return variant;
|
|
3956
3966
|
};
|
|
3957
3967
|
|
|
3958
|
-
export { NINETAILED_TRACKER_EVENTS, Ninetailed, PLUGIN_NAME, ninetailedPlugin, selectActiveExperiments,
|
|
3968
|
+
export { NINETAILED_TRACKER_EVENTS, Ninetailed, PLUGIN_NAME, isExperienceMatch, ninetailedPlugin, selectActiveExperiments, selectEligibleExperiences, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants, selectVariant$1 as selectVariant };
|
package/index.umd.js
CHANGED
|
@@ -3770,12 +3770,12 @@
|
|
|
3770
3770
|
};
|
|
3771
3771
|
|
|
3772
3772
|
/**
|
|
3773
|
-
* We can use any personalization as
|
|
3773
|
+
* We can use any personalization as eligible experience
|
|
3774
3774
|
* When going for an experiment we can only select a active experiment when 1 or more experiments are active
|
|
3775
3775
|
* If the profile is not in any active experiments, we can select any expermiment
|
|
3776
3776
|
*/
|
|
3777
3777
|
|
|
3778
|
-
var
|
|
3778
|
+
var selectEligibleExperiences = function selectEligibleExperiences(_a) {
|
|
3779
3779
|
var experiences = _a.experiences,
|
|
3780
3780
|
activeExperiments = _a.activeExperiments;
|
|
3781
3781
|
return experiences.filter(function (experience) {
|
|
@@ -3805,25 +3805,36 @@
|
|
|
3805
3805
|
return getRandom("distribution-".concat(experience.id, "-").concat(profile.id));
|
|
3806
3806
|
};
|
|
3807
3807
|
|
|
3808
|
+
var isExperienceMatch = function isExperienceMatch(_a) {
|
|
3809
|
+
var experience = _a.experience,
|
|
3810
|
+
activeExperiments = _a.activeExperiments,
|
|
3811
|
+
profile = _a.profile;
|
|
3812
|
+
var trafficRandom = getTrafficRandom(profile, experience);
|
|
3813
|
+
log("The traffic random factor for experience ".concat(experience.id, " is ").concat(trafficRandom, ". It's traffic allocation is set to ").concat(experience.trafficAllocation, "."));
|
|
3814
|
+
var isInTrafficRange = experience.trafficAllocation > trafficRandom;
|
|
3815
|
+
var matchesAudience = !experience.audience || includes__default["default"](profile.audiences, experience.audience.id);
|
|
3816
|
+
var hasActiveExperiment = find__default["default"](activeExperiments, {
|
|
3817
|
+
id: experience.id
|
|
3818
|
+
});
|
|
3819
|
+
log("Is the profile in traffic allocation range? ".concat(isInTrafficRange ? 'yes' : 'no', ".\n\n Does the profile match the audience of the experience? ").concat(matchesAudience ? 'yes' : 'no', ".\n\n Is there an active experiment for this profile? ").concat(hasActiveExperiment ? 'yes' : 'no', "."));
|
|
3820
|
+
return isInTrafficRange && (matchesAudience || // if the expriment is active already then it's selectible without further contraints to be fullfilled
|
|
3821
|
+
hasActiveExperiment);
|
|
3822
|
+
};
|
|
3823
|
+
|
|
3808
3824
|
var selectExperience = function selectExperience(_a) {
|
|
3809
3825
|
var experiences = _a.experiences,
|
|
3810
3826
|
activeExperiments = _a.activeExperiments,
|
|
3811
3827
|
profile = _a.profile;
|
|
3812
|
-
var
|
|
3828
|
+
var eligibleExperiences = selectEligibleExperiences({
|
|
3813
3829
|
experiences: experiences,
|
|
3814
3830
|
activeExperiments: activeExperiments
|
|
3815
3831
|
});
|
|
3816
|
-
var selectedExperience =
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
var hasActiveExperiment = find__default["default"](activeExperiments, {
|
|
3822
|
-
id: experience.id
|
|
3832
|
+
var selectedExperience = eligibleExperiences.find(function (experience) {
|
|
3833
|
+
return isExperienceMatch({
|
|
3834
|
+
experience: experience,
|
|
3835
|
+
activeExperiments: activeExperiments,
|
|
3836
|
+
profile: profile
|
|
3823
3837
|
});
|
|
3824
|
-
log("Is the profile in traffic allocation range? ".concat(isInTrafficRange ? 'yes' : 'no', ".\n\n Does the profile match the audience of the experience? ").concat(matchesAudience ? 'yes' : 'no', ".\n\n Is there an active experiment for this profile? ").concat(hasActiveExperiment ? 'yes' : 'no', "."));
|
|
3825
|
-
return isInTrafficRange && (matchesAudience || // if the expriment is active already then it's selectible without further contraints to be fullfilled
|
|
3826
|
-
hasActiveExperiment);
|
|
3827
3838
|
});
|
|
3828
3839
|
return selectedExperience;
|
|
3829
3840
|
};
|
|
@@ -3882,9 +3893,10 @@
|
|
|
3882
3893
|
exports.NINETAILED_TRACKER_EVENTS = NINETAILED_TRACKER_EVENTS;
|
|
3883
3894
|
exports.Ninetailed = Ninetailed;
|
|
3884
3895
|
exports.PLUGIN_NAME = PLUGIN_NAME;
|
|
3896
|
+
exports.isExperienceMatch = isExperienceMatch;
|
|
3885
3897
|
exports.ninetailedPlugin = ninetailedPlugin;
|
|
3886
3898
|
exports.selectActiveExperiments = selectActiveExperiments;
|
|
3887
|
-
exports.
|
|
3899
|
+
exports.selectEligibleExperiences = selectEligibleExperiences;
|
|
3888
3900
|
exports.selectExperience = selectExperience;
|
|
3889
3901
|
exports.selectExperienceBaselineWithVariants = selectBaselineWithVariants;
|
|
3890
3902
|
exports.selectExperienceVariant = selectVariant;
|
|
@@ -3,6 +3,7 @@ export { selectBaselineWithVariants as selectExperienceBaselineWithVariants } fr
|
|
|
3
3
|
export { selectVariants as selectExperienceVariants } from './selectVariants';
|
|
4
4
|
export { selectHasVariants as selectHasExperienceVariants } from './selectHasVariants';
|
|
5
5
|
export { selectActiveExperiments } from './selectActiveExperiments';
|
|
6
|
-
export {
|
|
6
|
+
export { selectEligibleExperiences } from './selectEligibleExperiences';
|
|
7
7
|
export { selectExperience } from './selectExperience';
|
|
8
8
|
export { selectVariant as selectExperienceVariant } from './selectVariant';
|
|
9
|
+
export { isExperienceMatch } from './isExperienceMatch';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Profile } from '@ninetailed/experience.js-shared';
|
|
2
|
+
import { ExperienceConfiguration } from './types';
|
|
3
|
+
declare type IsExperienceMatchArgs = {
|
|
4
|
+
experience: ExperienceConfiguration;
|
|
5
|
+
activeExperiments: ExperienceConfiguration[];
|
|
6
|
+
profile: Profile;
|
|
7
|
+
};
|
|
8
|
+
export declare const isExperienceMatch: ({ experience, activeExperiments, profile }: IsExperienceMatchArgs) => boolean | ExperienceConfiguration;
|
|
9
|
+
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ExperienceConfiguration } from './types';
|
|
2
|
-
declare type
|
|
2
|
+
declare type SelectEligibleExperiencesArgs = {
|
|
3
3
|
experiences: ExperienceConfiguration[];
|
|
4
4
|
activeExperiments: ExperienceConfiguration[];
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
|
-
* We can use any personalization as
|
|
7
|
+
* We can use any personalization as eligible experience
|
|
8
8
|
* When going for an experiment we can only select a active experiment when 1 or more experiments are active
|
|
9
9
|
* If the profile is not in any active experiments, we can select any expermiment
|
|
10
10
|
*/
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const selectEligibleExperiences: ({ experiences, activeExperiments, }: SelectEligibleExperiencesArgs) => ExperienceConfiguration[];
|
|
12
12
|
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.22",
|
|
4
4
|
"main": "./index.umd.js",
|
|
5
5
|
"module": "./index.esm.js",
|
|
6
6
|
"typings": "./index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"analytics": "^0.8.0",
|
|
9
|
-
"@ninetailed/experience.js-shared": "2.0.0-beta.
|
|
9
|
+
"@ninetailed/experience.js-shared": "2.0.0-beta.22",
|
|
10
10
|
"uuid": "^8.3.2",
|
|
11
11
|
"ts-toolbelt": "^9.6.0",
|
|
12
12
|
"locale-enum": "^1.1.1",
|