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/14 09:08:55 UTC

[unomi-tracker] branch main updated: UNOMI-713: update control group usage by using new personalizationResults (#12)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 8237493  UNOMI-713: update control group usage by using new personalizationResults (#12)
8237493 is described below

commit 82374939255a0b6cbe8c44dce6a3f787b4fd53a7
Author: kevan Jahanshahi <jk...@apache.org>
AuthorDate: Mon Nov 14 10:08:50 2022 +0100

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

diff --git a/dist/apache-unomi-tracker.cjs.js b/dist/apache-unomi-tracker.cjs.js
index 606b3b5..3cc1855 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, additionalResultInfos) {
         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 = additionalResultInfos && 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,14 @@ 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]);
+            if (wem.cxs.personalizationResults) {
+              // Since Unomi 2.1.0 personalization results are available with more infos
+              var personalizationResult = wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id];
+              wem.digitalData.personalizationCallback[j].callback(personalizationResult.contentIds, personalizationResult.additionalResultInfos);
+            } else {
+              // probably a version older than Unomi 2.1.0, fallback to old personalization results
+              wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+            }
           }
         }
       }
@@ -1575,36 +1580,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..7e7b459 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..626a767 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, additionalResultInfos) {
         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 = additionalResultInfos && 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,14 @@ 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]);
+            if (wem.cxs.personalizationResults) {
+              // Since Unomi 2.1.0 personalization results are available with more infos
+              var personalizationResult = wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id];
+              wem.digitalData.personalizationCallback[j].callback(personalizationResult.contentIds, personalizationResult.additionalResultInfos);
+            } else {
+              // probably a version older than Unomi 2.1.0, fallback to old personalization results
+              wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+            }
           }
         }
       }
@@ -1567,36 +1572,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..d55132d 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..e601cdd 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, additionalResultInfos) {
           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 = additionalResultInfos && 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,14 @@
 
           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]);
+              if (wem.cxs.personalizationResults) {
+                // Since Unomi 2.1.0 personalization results are available with more infos
+                var personalizationResult = wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id];
+                wem.digitalData.personalizationCallback[j].callback(personalizationResult.contentIds, personalizationResult.additionalResultInfos);
+              } else {
+                // probably a version older than Unomi 2.1.0, fallback to old personalization results
+                wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+              }
             }
           }
         }
@@ -3222,36 +3227,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..3005aa3 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..95f1513 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, additionalResultInfos) {
                 var selectedFilter = null;
                 var successfulFilters = [];
 
-                var inControlGroup = wem._isInControlGroup(target);
+                var inControlGroup = additionalResultInfos && 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,14 @@ 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]);
+                        if (wem.cxs.personalizationResults) {
+                            // Since Unomi 2.1.0 personalization results are available with more infos
+                            var personalizationResult = wem.cxs.personalizationResults[wem.digitalData.personalizationCallback[j].personalization.id];
+                            wem.digitalData.personalizationCallback[j].callback(personalizationResult.contentIds, personalizationResult.additionalResultInfos);
+                        } else {
+                            // probably a version older than Unomi 2.1.0, fallback to old personalization results
+                            wem.digitalData.personalizationCallback[j].callback(wem.cxs.personalizations[wem.digitalData.personalizationCallback[j].personalization.id]);
+                        }
                     }
                 }
             }
@@ -1420,28 +1427,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;
         }
     };