You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@unomi.apache.org by jk...@apache.org on 2022/11/10 15:16:22 UTC

[unomi-tracker] 01/01: UNOMI-713: update control group usage by using new personalizationResults

This is an automated email from the ASF dual-hosted git repository.

jkevan pushed a commit to branch refacto-control-group-usage
in repository https://gitbox.apache.org/repos/asf/unomi-tracker.git

commit 095d8f8776cd68c879ff315536275ece4edc1c8d
Author: Kevan <ke...@jahia.com>
AuthorDate: Thu Nov 10 16:16:01 2022 +0100

    UNOMI-713: update control group usage by using new personalizationResults
---
 dist/apache-unomi-tracker.cjs.js     | 38 +++---------------------------------
 dist/apache-unomi-tracker.cjs.js.map |  2 +-
 dist/apache-unomi-tracker.esm.js     | 38 +++---------------------------------
 dist/apache-unomi-tracker.esm.js.map |  2 +-
 dist/apache-unomi-tracker.umd.js     | 38 +++---------------------------------
 dist/apache-unomi-tracker.umd.js.map |  2 +-
 src/apache-unomi-tracker.js          | 31 ++++++-----------------------
 7 files changed, 18 insertions(+), 133 deletions(-)

diff --git a/dist/apache-unomi-tracker.cjs.js b/dist/apache-unomi-tracker.cjs.js
index 606b3b5..622fbe8 100644
--- a/dist/apache-unomi-tracker.cjs.js
+++ b/dist/apache-unomi-tracker.cjs.js
@@ -189,12 +189,10 @@ var newTracker = function newTracker() {
     registerPersonalizationObject: function registerPersonalizationObject(personalization, variants, ajax, resultCallback) {
       var target = personalization.id;
 
-      wem._registerPersonalizationCallback(personalization, function (result) {
+      wem._registerPersonalizationCallback(personalization, function (result, advancedResult) {
         var selectedFilter = null;
         var successfulFilters = [];
-
-        var inControlGroup = wem._isInControlGroup(target); // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
-
+        var inControlGroup = advancedResult && advancedResult.additionalResultInfos && advancedResult.additionalResultInfos.inControlGroup; // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
 
         if (inControlGroup && personalization.strategyOptions && personalization.strategyOptions.fallback) {
           selectedFilter = variants[personalization.strategyOptions.fallback];
@@ -1279,7 +1277,7 @@ var newTracker = function newTracker() {
 
         if (wem.digitalData.personalizationCallback) {
           for (var j = 0; j < wem.digitalData.personalizationCallback.length; j++) {
-            wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+            wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id], wem.cxs.personalizationResults ? wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id] : undefined);
           }
         }
       }
@@ -1575,36 +1573,6 @@ var newTracker = function newTracker() {
      */
     _isObject: function _isObject(obj) {
       return obj && _typeof__default["default"](obj) === 'object';
-    },
-
-    /**
-     * Utility function used to check if the current id is contains in any Unomi control group
-     * @param {string} id the id to check
-     * @private
-     * @return {boolean} true if the id is found in a control group, false otherwise
-     */
-    _isInControlGroup: function _isInControlGroup(id) {
-      if (wem.cxs.profileProperties && wem.cxs.profileProperties.unomiControlGroups) {
-        var controlGroup = wem.cxs.profileProperties.unomiControlGroups.find(function (controlGroup) {
-          return controlGroup.id === id;
-        });
-
-        if (controlGroup) {
-          return true;
-        }
-      }
-
-      if (wem.cxs.sessionProperties && wem.cxs.sessionProperties.unomiControlGroups) {
-        var _controlGroup = wem.cxs.sessionProperties.unomiControlGroups.find(function (controlGroup) {
-          return controlGroup.id === id;
-        });
-
-        if (_controlGroup) {
-          return true;
-        }
-      }
-
-      return false;
     }
   };
   return wem;
diff --git a/dist/apache-unomi-tracker.cjs.js.map b/dist/apache-unomi-tracker.cjs.js.map
index e760806..feca98e 100644
--- a/dist/apache-unomi-tracker.cjs.js.map
+++ b/dist/apache-unomi-tracker.cjs.js.map
@@ -1 +1 @@
-{"version":3,"file":"apache-unomi-tracker.cjs.js","sources":["../src/apache-unomi-tracker.js","../src/index.js"],"sourcesContent":["/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compl [...]
\ No newline at end of file
+{"version":3,"file":"apache-unomi-tracker.cjs.js","sources":["../src/apache-unomi-tracker.js","../src/index.js"],"sourcesContent":["/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compl [...]
\ No newline at end of file
diff --git a/dist/apache-unomi-tracker.esm.js b/dist/apache-unomi-tracker.esm.js
index 932edc8..c906518 100644
--- a/dist/apache-unomi-tracker.esm.js
+++ b/dist/apache-unomi-tracker.esm.js
@@ -181,12 +181,10 @@ var newTracker = function newTracker() {
     registerPersonalizationObject: function registerPersonalizationObject(personalization, variants, ajax, resultCallback) {
       var target = personalization.id;
 
-      wem._registerPersonalizationCallback(personalization, function (result) {
+      wem._registerPersonalizationCallback(personalization, function (result, advancedResult) {
         var selectedFilter = null;
         var successfulFilters = [];
-
-        var inControlGroup = wem._isInControlGroup(target); // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
-
+        var inControlGroup = advancedResult && advancedResult.additionalResultInfos && advancedResult.additionalResultInfos.inControlGroup; // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
 
         if (inControlGroup && personalization.strategyOptions && personalization.strategyOptions.fallback) {
           selectedFilter = variants[personalization.strategyOptions.fallback];
@@ -1271,7 +1269,7 @@ var newTracker = function newTracker() {
 
         if (wem.digitalData.personalizationCallback) {
           for (var j = 0; j < wem.digitalData.personalizationCallback.length; j++) {
-            wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+            wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id], wem.cxs.personalizationResults ? wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id] : undefined);
           }
         }
       }
@@ -1567,36 +1565,6 @@ var newTracker = function newTracker() {
      */
     _isObject: function _isObject(obj) {
       return obj && _typeof(obj) === 'object';
-    },
-
-    /**
-     * Utility function used to check if the current id is contains in any Unomi control group
-     * @param {string} id the id to check
-     * @private
-     * @return {boolean} true if the id is found in a control group, false otherwise
-     */
-    _isInControlGroup: function _isInControlGroup(id) {
-      if (wem.cxs.profileProperties && wem.cxs.profileProperties.unomiControlGroups) {
-        var controlGroup = wem.cxs.profileProperties.unomiControlGroups.find(function (controlGroup) {
-          return controlGroup.id === id;
-        });
-
-        if (controlGroup) {
-          return true;
-        }
-      }
-
-      if (wem.cxs.sessionProperties && wem.cxs.sessionProperties.unomiControlGroups) {
-        var _controlGroup = wem.cxs.sessionProperties.unomiControlGroups.find(function (controlGroup) {
-          return controlGroup.id === id;
-        });
-
-        if (_controlGroup) {
-          return true;
-        }
-      }
-
-      return false;
     }
   };
   return wem;
diff --git a/dist/apache-unomi-tracker.esm.js.map b/dist/apache-unomi-tracker.esm.js.map
index e1a80e5..1b3942e 100644
--- a/dist/apache-unomi-tracker.esm.js.map
+++ b/dist/apache-unomi-tracker.esm.js.map
@@ -1 +1 @@
-{"version":3,"file":"apache-unomi-tracker.esm.js","sources":["../src/apache-unomi-tracker.js","../src/index.js"],"sourcesContent":["/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compl [...]
\ No newline at end of file
+{"version":3,"file":"apache-unomi-tracker.esm.js","sources":["../src/apache-unomi-tracker.js","../src/index.js"],"sourcesContent":["/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compl [...]
\ No newline at end of file
diff --git a/dist/apache-unomi-tracker.umd.js b/dist/apache-unomi-tracker.umd.js
index 327be82..8cd8be1 100644
--- a/dist/apache-unomi-tracker.umd.js
+++ b/dist/apache-unomi-tracker.umd.js
@@ -1836,12 +1836,10 @@
       registerPersonalizationObject: function registerPersonalizationObject(personalization, variants, ajax, resultCallback) {
         var target = personalization.id;
 
-        wem._registerPersonalizationCallback(personalization, function (result) {
+        wem._registerPersonalizationCallback(personalization, function (result, advancedResult) {
           var selectedFilter = null;
           var successfulFilters = [];
-
-          var inControlGroup = wem._isInControlGroup(target); // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
-
+          var inControlGroup = advancedResult && advancedResult.additionalResultInfos && advancedResult.additionalResultInfos.inControlGroup; // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
 
           if (inControlGroup && personalization.strategyOptions && personalization.strategyOptions.fallback) {
             selectedFilter = variants[personalization.strategyOptions.fallback];
@@ -2926,7 +2924,7 @@
 
           if (wem.digitalData.personalizationCallback) {
             for (var j = 0; j < wem.digitalData.personalizationCallback.length; j++) {
-              wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+              wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id], wem.cxs.personalizationResults ? wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id] : undefined);
             }
           }
         }
@@ -3222,36 +3220,6 @@
        */
       _isObject: function _isObject(obj) {
         return obj && _typeof(obj) === 'object';
-      },
-
-      /**
-       * Utility function used to check if the current id is contains in any Unomi control group
-       * @param {string} id the id to check
-       * @private
-       * @return {boolean} true if the id is found in a control group, false otherwise
-       */
-      _isInControlGroup: function _isInControlGroup(id) {
-        if (wem.cxs.profileProperties && wem.cxs.profileProperties.unomiControlGroups) {
-          var controlGroup = wem.cxs.profileProperties.unomiControlGroups.find(function (controlGroup) {
-            return controlGroup.id === id;
-          });
-
-          if (controlGroup) {
-            return true;
-          }
-        }
-
-        if (wem.cxs.sessionProperties && wem.cxs.sessionProperties.unomiControlGroups) {
-          var _controlGroup = wem.cxs.sessionProperties.unomiControlGroups.find(function (controlGroup) {
-            return controlGroup.id === id;
-          });
-
-          if (_controlGroup) {
-            return true;
-          }
-        }
-
-        return false;
       }
     };
     return wem;
diff --git a/dist/apache-unomi-tracker.umd.js.map b/dist/apache-unomi-tracker.umd.js.map
index cf38c25..035fdac 100644
--- a/dist/apache-unomi-tracker.umd.js.map
+++ b/dist/apache-unomi-tracker.umd.js.map
@@ -1 +1 @@
-{"version":3,"file":"apache-unomi-tracker.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/typeof.js","../node_modules/es6-crawler-detect/src/lib/crawler/provider.js","../node_modules/es6-crawler-detect/src/lib/crawler/crawlers.js","../node_modules/es6-crawler-detect/src/lib/crawler/exclusions.js","../node_modules/es6-crawler-detect/src/lib/crawler/headers.js","../node_modules/es6-crawler-detect/src/lib/crawler.js","../node_modules/es6-crawler-detect/src/index.js","../src/a [...]
\ No newline at end of file
+{"version":3,"file":"apache-unomi-tracker.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/typeof.js","../node_modules/es6-crawler-detect/src/lib/crawler/provider.js","../node_modules/es6-crawler-detect/src/lib/crawler/crawlers.js","../node_modules/es6-crawler-detect/src/lib/crawler/exclusions.js","../node_modules/es6-crawler-detect/src/lib/crawler/headers.js","../node_modules/es6-crawler-detect/src/lib/crawler.js","../node_modules/es6-crawler-detect/src/index.js","../src/a [...]
\ No newline at end of file
diff --git a/src/apache-unomi-tracker.js b/src/apache-unomi-tracker.js
index 614467d..ac19f62 100644
--- a/src/apache-unomi-tracker.js
+++ b/src/apache-unomi-tracker.js
@@ -168,11 +168,11 @@ export const newTracker = () => {
          */
         registerPersonalizationObject: function (personalization, variants, ajax, resultCallback) {
             var target = personalization.id;
-            wem._registerPersonalizationCallback(personalization, function (result) {
+            wem._registerPersonalizationCallback(personalization, function (result, advancedResult) {
                 var selectedFilter = null;
                 var successfulFilters = [];
 
-                var inControlGroup = wem._isInControlGroup(target);
+                var inControlGroup = advancedResult && advancedResult.additionalResultInfos && advancedResult.additionalResultInfos.inControlGroup;
                 // In case of control group Unomi is not resolving any strategy or fallback for us. So we have to do the fallback here.
                 if (inControlGroup && personalization.strategyOptions && personalization.strategyOptions.fallback) {
                     selectedFilter = variants[personalization.strategyOptions.fallback];
@@ -1141,7 +1141,10 @@ export const newTracker = () => {
 
                 if (wem.digitalData.personalizationCallback) {
                     for (var j = 0; j < wem.digitalData.personalizationCallback.length; j++) {
-                        wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+                        wem.digitalData.personalizationCallback[j].callback(
+                            wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id],
+                            wem.cxs.personalizationResults ? wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id] : undefined
+                        );
                     }
                 }
             }
@@ -1420,28 +1423,6 @@ export const newTracker = () => {
          */
         _isObject: function (obj) {
             return obj && typeof obj === 'object';
-        },
-
-        /**
-         * Utility function used to check if the current id is contains in any Unomi control group
-         * @param {string} id the id to check
-         * @private
-         * @return {boolean} true if the id is found in a control group, false otherwise
-         */
-        _isInControlGroup: function (id) {
-            if (wem.cxs.profileProperties && wem.cxs.profileProperties.unomiControlGroups) {
-                let controlGroup = wem.cxs.profileProperties.unomiControlGroups.find(controlGroup => controlGroup.id === id);
-                if (controlGroup) {
-                    return true;
-                }
-            }
-            if (wem.cxs.sessionProperties && wem.cxs.sessionProperties.unomiControlGroups) {
-                let controlGroup = wem.cxs.sessionProperties.unomiControlGroups.find(controlGroup => controlGroup.id === id);
-                if (controlGroup) {
-                    return true;
-                }
-            }
-            return false;
         }
     };