@uniformdev/optimize-tracker
Advanced tools
Comparing version 5.0.2-alpha.16 to 5.0.2-alpha.28
@@ -27,3 +27,3 @@ "use strict"; | ||
personalization: function (_a) { | ||
var matches = _a.matches, includedInTest = _a.includedInTest, intentScores = _a.intentScores; | ||
var matches = _a.matches, isInPersonalizationControlGroup = _a.isInPersonalizationControlGroup, intentScores = _a.intentScores; | ||
if (!tracker || !tracker.isInitialized()) { | ||
@@ -36,3 +36,3 @@ return false; | ||
label: description, | ||
value: includedInTest, | ||
value: isInPersonalizationControlGroup, | ||
intentScores: intentScores, | ||
@@ -39,0 +39,0 @@ }); |
@@ -124,10 +124,36 @@ "use strict"; | ||
var scoreFunc = scorer !== null && scorer !== void 0 ? scorer : exports.calculateScore; | ||
var allMatches = {}; | ||
var scoredItems = list.map(function (listItem) { | ||
var _a = scoreFunc({ intentTag: listItem.intentTag, intentScores: intentScores }), score = _a.score, isDefault = _a.isDefault, matches = _a.matches; | ||
if (matches) { | ||
matches.forEach(function (key) { | ||
allMatches[key] = true; | ||
// valid variations that have relevancies calculated | ||
var scoredItems = []; | ||
// stores the count of each intent threshold we've seen while processing variations | ||
// used to de-duplicate threshold variants to leave only the highest threshold remaining | ||
var thresholds = {}; | ||
// loop over variations and score/filter them into scoredItems | ||
list.forEach(function (listItem) { | ||
var _a; | ||
// reject items which match but have not reached their score thresholds | ||
if ((_a = listItem.intentTag) === null || _a === void 0 ? void 0 : _a.intents) { | ||
var intentMetThreshold_1 = true; | ||
var intents_1 = listItem.intentTag.intents; | ||
Object.keys(intents_1).forEach(function (taggedIntent) { | ||
var _a, _b, _c, _d; | ||
var intent = intents_1[taggedIntent]; | ||
if (intent.threshold) { | ||
var visitorIntentStrength = (_b = (_a = intentScores[taggedIntent]) === null || _a === void 0 ? void 0 : _a.str) !== null && _b !== void 0 ? _b : 0; | ||
if (intent.threshold > visitorIntentStrength) { | ||
intentMetThreshold_1 = false; | ||
} | ||
} | ||
var thresholdMetadata = (thresholds[taggedIntent] = (_c = thresholds[taggedIntent]) !== null && _c !== void 0 ? _c : { | ||
count: 0, | ||
max: 0, | ||
}); | ||
thresholdMetadata.count++; | ||
thresholdMetadata.max = Math.max((_d = intent.threshold) !== null && _d !== void 0 ? _d : 0, 0); | ||
}); | ||
if (!intentMetThreshold_1) { | ||
return; | ||
} | ||
} | ||
// calculate relevancy score to visitor intents | ||
var _b = scoreFunc({ intentTag: listItem.intentTag, intentScores: intentScores }), score = _b.score, isDefault = _b.isDefault, matches = _b.matches; | ||
if (typeof score !== 'undefined' && score !== Number.POSITIVE_INFINITY) { | ||
@@ -142,4 +168,29 @@ wasAnythingScored = true; | ||
}; | ||
return result; | ||
if (personalizedOnly && (result.isDefault || result.relevancy === Infinity)) { | ||
// reject defaults and irrelevant variants if personalizedOnly is on | ||
return; | ||
} | ||
scoredItems.push(result); | ||
}); | ||
// if we have more than one match on score-thresholded intents, we want to pluck out only the highest thresholded match | ||
// (i.e. if we have a match on dev - threshold 50, and dev - no threshold, we want to leave only dev - threshold 50) | ||
scoredItems = scoredItems.filter(function (scoredItem) { | ||
var _a; | ||
var intentTag = (_a = scoredItem.item.intentTag) === null || _a === void 0 ? void 0 : _a.intents; | ||
// keep untagged (default) variations | ||
if (!intentTag) | ||
return true; | ||
return Object.keys(intentTag).every(function (tag) { | ||
var _a; | ||
var tagData = intentTag[tag]; | ||
var thresholdData = thresholds[tag]; | ||
// threshold is met, keep the variation | ||
if (thresholdData.count === 1 || thresholdData.max === 0) { | ||
return true; | ||
} | ||
var currentThreshold = (_a = tagData.threshold) !== null && _a !== void 0 ? _a : 0; | ||
// cull the variation if it isn't the max threshold we saw | ||
return currentThreshold === thresholdData.max; | ||
}); | ||
}); | ||
if (wasAnythingScored && !isInPersonalizationControlGroup) { | ||
@@ -168,13 +219,3 @@ // sort by relevancy ASC (lower relevancy numbers are more relevant since relevancy is a distance) | ||
} | ||
var matches = Object.keys(allMatches); | ||
analyticsEmitter === null || analyticsEmitter === void 0 ? void 0 : analyticsEmitter.personalization({ | ||
matches: matches, | ||
isInPersonalizationControlGroup: isInPersonalizationControlGroup, | ||
intentScores: intentScores, | ||
}); | ||
var result = scoredItems; | ||
// if `personalizedOnly` is true, filter out non-personalized items | ||
if (personalizedOnly) { | ||
result = result.filter(function (v) { return !v.isDefault && v.relevancy !== Infinity; }); | ||
} | ||
// take first x results if `count` is specified | ||
@@ -184,2 +225,11 @@ if (typeof count === 'number' && count > 0) { | ||
} | ||
if (analyticsEmitter) { | ||
// used to calculate analytics emissions | ||
var allMatches = new Set(result.flatMap(function (res) { var _a; return (_a = res.matches) !== null && _a !== void 0 ? _a : []; })); | ||
analyticsEmitter === null || analyticsEmitter === void 0 ? void 0 : analyticsEmitter.personalization({ | ||
matches: Array.from(allMatches), | ||
isInPersonalizationControlGroup: isInPersonalizationControlGroup !== null && isInPersonalizationControlGroup !== void 0 ? isInPersonalizationControlGroup : false, | ||
intentScores: intentScores, | ||
}); | ||
} | ||
return { | ||
@@ -186,0 +236,0 @@ result: result, |
@@ -22,3 +22,3 @@ export var resolveAnalyticsEmitter = function (_a) { | ||
personalization: function (_a) { | ||
var matches = _a.matches, includedInTest = _a.includedInTest, intentScores = _a.intentScores; | ||
var matches = _a.matches, isInPersonalizationControlGroup = _a.isInPersonalizationControlGroup, intentScores = _a.intentScores; | ||
if (!tracker || !tracker.isInitialized()) { | ||
@@ -31,3 +31,3 @@ return false; | ||
label: description, | ||
value: includedInTest, | ||
value: isInPersonalizationControlGroup, | ||
intentScores: intentScores, | ||
@@ -34,0 +34,0 @@ }); |
@@ -118,10 +118,36 @@ var __assign = (this && this.__assign) || function () { | ||
var scoreFunc = scorer !== null && scorer !== void 0 ? scorer : calculateScore; | ||
var allMatches = {}; | ||
var scoredItems = list.map(function (listItem) { | ||
var _a = scoreFunc({ intentTag: listItem.intentTag, intentScores: intentScores }), score = _a.score, isDefault = _a.isDefault, matches = _a.matches; | ||
if (matches) { | ||
matches.forEach(function (key) { | ||
allMatches[key] = true; | ||
// valid variations that have relevancies calculated | ||
var scoredItems = []; | ||
// stores the count of each intent threshold we've seen while processing variations | ||
// used to de-duplicate threshold variants to leave only the highest threshold remaining | ||
var thresholds = {}; | ||
// loop over variations and score/filter them into scoredItems | ||
list.forEach(function (listItem) { | ||
var _a; | ||
// reject items which match but have not reached their score thresholds | ||
if ((_a = listItem.intentTag) === null || _a === void 0 ? void 0 : _a.intents) { | ||
var intentMetThreshold_1 = true; | ||
var intents_1 = listItem.intentTag.intents; | ||
Object.keys(intents_1).forEach(function (taggedIntent) { | ||
var _a, _b, _c, _d; | ||
var intent = intents_1[taggedIntent]; | ||
if (intent.threshold) { | ||
var visitorIntentStrength = (_b = (_a = intentScores[taggedIntent]) === null || _a === void 0 ? void 0 : _a.str) !== null && _b !== void 0 ? _b : 0; | ||
if (intent.threshold > visitorIntentStrength) { | ||
intentMetThreshold_1 = false; | ||
} | ||
} | ||
var thresholdMetadata = (thresholds[taggedIntent] = (_c = thresholds[taggedIntent]) !== null && _c !== void 0 ? _c : { | ||
count: 0, | ||
max: 0, | ||
}); | ||
thresholdMetadata.count++; | ||
thresholdMetadata.max = Math.max((_d = intent.threshold) !== null && _d !== void 0 ? _d : 0, 0); | ||
}); | ||
if (!intentMetThreshold_1) { | ||
return; | ||
} | ||
} | ||
// calculate relevancy score to visitor intents | ||
var _b = scoreFunc({ intentTag: listItem.intentTag, intentScores: intentScores }), score = _b.score, isDefault = _b.isDefault, matches = _b.matches; | ||
if (typeof score !== 'undefined' && score !== Number.POSITIVE_INFINITY) { | ||
@@ -136,4 +162,29 @@ wasAnythingScored = true; | ||
}; | ||
return result; | ||
if (personalizedOnly && (result.isDefault || result.relevancy === Infinity)) { | ||
// reject defaults and irrelevant variants if personalizedOnly is on | ||
return; | ||
} | ||
scoredItems.push(result); | ||
}); | ||
// if we have more than one match on score-thresholded intents, we want to pluck out only the highest thresholded match | ||
// (i.e. if we have a match on dev - threshold 50, and dev - no threshold, we want to leave only dev - threshold 50) | ||
scoredItems = scoredItems.filter(function (scoredItem) { | ||
var _a; | ||
var intentTag = (_a = scoredItem.item.intentTag) === null || _a === void 0 ? void 0 : _a.intents; | ||
// keep untagged (default) variations | ||
if (!intentTag) | ||
return true; | ||
return Object.keys(intentTag).every(function (tag) { | ||
var _a; | ||
var tagData = intentTag[tag]; | ||
var thresholdData = thresholds[tag]; | ||
// threshold is met, keep the variation | ||
if (thresholdData.count === 1 || thresholdData.max === 0) { | ||
return true; | ||
} | ||
var currentThreshold = (_a = tagData.threshold) !== null && _a !== void 0 ? _a : 0; | ||
// cull the variation if it isn't the max threshold we saw | ||
return currentThreshold === thresholdData.max; | ||
}); | ||
}); | ||
if (wasAnythingScored && !isInPersonalizationControlGroup) { | ||
@@ -162,13 +213,3 @@ // sort by relevancy ASC (lower relevancy numbers are more relevant since relevancy is a distance) | ||
} | ||
var matches = Object.keys(allMatches); | ||
analyticsEmitter === null || analyticsEmitter === void 0 ? void 0 : analyticsEmitter.personalization({ | ||
matches: matches, | ||
isInPersonalizationControlGroup: isInPersonalizationControlGroup, | ||
intentScores: intentScores, | ||
}); | ||
var result = scoredItems; | ||
// if `personalizedOnly` is true, filter out non-personalized items | ||
if (personalizedOnly) { | ||
result = result.filter(function (v) { return !v.isDefault && v.relevancy !== Infinity; }); | ||
} | ||
// take first x results if `count` is specified | ||
@@ -178,2 +219,11 @@ if (typeof count === 'number' && count > 0) { | ||
} | ||
if (analyticsEmitter) { | ||
// used to calculate analytics emissions | ||
var allMatches = new Set(result.flatMap(function (res) { var _a; return (_a = res.matches) !== null && _a !== void 0 ? _a : []; })); | ||
analyticsEmitter === null || analyticsEmitter === void 0 ? void 0 : analyticsEmitter.personalization({ | ||
matches: Array.from(allMatches), | ||
isInPersonalizationControlGroup: isInPersonalizationControlGroup !== null && isInPersonalizationControlGroup !== void 0 ? isInPersonalizationControlGroup : false, | ||
intentScores: intentScores, | ||
}); | ||
} | ||
return { | ||
@@ -180,0 +230,0 @@ result: result, |
{ | ||
"name": "@uniformdev/optimize-tracker", | ||
"version": "5.0.2-alpha.16+89b88a1", | ||
"version": "5.0.2-alpha.28+4de4f7e", | ||
"description": "Uniform Optimize tracker", | ||
@@ -33,4 +33,4 @@ "repository": { | ||
"dependencies": { | ||
"@uniformdev/optimize-common": "^5.0.2-alpha.16+89b88a1", | ||
"@uniformdev/optimize-tracker-common": "^5.0.2-alpha.16+89b88a1", | ||
"@uniformdev/optimize-common": "^5.0.2-alpha.28+4de4f7e", | ||
"@uniformdev/optimize-tracker-common": "^5.0.2-alpha.28+4de4f7e", | ||
"parse5": "^6.0.1", | ||
@@ -62,3 +62,3 @@ "uuid": ">=7.0.0" | ||
}, | ||
"gitHead": "89b88a15396ae3c4524e3d7a91e2cc61f762b968" | ||
"gitHead": "4de4f7e86dc94aa9229749c719f02c827deab609" | ||
} |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
422390
8384