This is an automated email from the ASF dual-hosted git repository. dgriffon pushed a commit to branch fix-variant-without-event in repository https://gitbox.apache.org/repos/asf/unomi-tracker.git
commit 1bbc023856fbe104265f8dc92168ffd0e184323a Author: David Griffon <dgrif...@jahia.com> AuthorDate: Thu Sep 7 17:48:46 2023 +0200 UNOMI-803 : allow empty event within a variant --- dist/apache-unomi-tracker.cjs.js | 53 ++++++++++++++++++++---------------- dist/apache-unomi-tracker.cjs.js.map | 2 +- dist/apache-unomi-tracker.esm.js | 53 ++++++++++++++++++++---------------- dist/apache-unomi-tracker.esm.js.map | 2 +- dist/apache-unomi-tracker.umd.js | 53 ++++++++++++++++++++---------------- dist/apache-unomi-tracker.umd.js.map | 2 +- src/apache-unomi-tracker.js | 42 +++++++++++++++------------- 7 files changed, 116 insertions(+), 91 deletions(-) diff --git a/dist/apache-unomi-tracker.cjs.js b/dist/apache-unomi-tracker.cjs.js index 18250e5..844826e 100644 --- a/dist/apache-unomi-tracker.cjs.js +++ b/dist/apache-unomi-tracker.cjs.js @@ -229,28 +229,30 @@ var newTracker = function newTracker() { if (filter) { filter.style.display = filter.id === selectedFilter.content ? '' : 'none'; } - } // we now add control group information to event if the user is in the control group. - + } - if (inControlGroup) { - console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); - selectedFilter.event.target.properties.inControlGroup = true; + if (selectedFilter.event) { + // we now add control group information to event if the user is in the control group. + if (inControlGroup) { + console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); + selectedFilter.event.target.properties.inControlGroup = true; - if (selectedFilter.event.target.properties.variants) { - selectedFilter.event.target.properties.variants.forEach(function (variant) { - return variant.inControlGroup = true; - }); - } - } // send event to unomi + if (selectedFilter.event.target.properties.variants) { + selectedFilter.event.target.properties.variants.forEach(function (variant) { + return variant.inControlGroup = true; + }); + } + } // send event to unomi - wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { - console.info('[WEM] Personalization event successfully collected.'); - }, function () { - console.error('[WEM] Could not send personalization event.'); - }); //Trigger variant display event for personalization + wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { + console.info('[WEM] Personalization event successfully collected.'); + }, function () { + console.error('[WEM] Could not send personalization event.'); + }); //Trigger variant display event for personalization - wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + } } else { var elements = document.getElementById(target).children; @@ -291,7 +293,9 @@ var newTracker = function newTracker() { } // select random variant and call unomi - if (!(selectedVariantId && variants[selectedVariantId])) { + var selectVariant = variants[selectedVariantId]; + + if (!(selectedVariantId && selectVariant)) { var keys = Object.keys(variants); if (variantsTraffic) { @@ -313,7 +317,9 @@ var newTracker = function newTracker() { } // spread event to unomi - wem._registerEvent(wem._completeEvent(variants[selectedVariantId].event)); + if (selectVariant.event) { + wem._registerEvent(wem._completeEvent(selectVariant.event)); + } } if (selectedVariantId) { @@ -323,7 +329,7 @@ var newTracker = function newTracker() { } // display the good variant - document.getElementById(variants[selectedVariantId].content).style.display = ''; + document.getElementById(selectVariant.content).style.display = ''; } }, @@ -634,7 +640,8 @@ var newTracker = function newTracker() { expires = '; expires=' + d.toUTCString(); } - document.cookie = cookieName + '=' + cookieValue + expires + '; path=/; SameSite=Strict'; + var secure = location.protocol === 'https:' ? '; secure' : ''; + document.cookie = cookieName + '=' + cookieValue + expires + '; path=/; SameSite=Strict' + secure; }, /** @@ -1520,8 +1527,8 @@ var newTracker = function newTracker() { if (!enable) { wem.cxs = {}; - document.cookie = wem.trackerProfileIdCookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; - document.cookie = wem.contextServerCookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + wem.removeCookie(wem.contextServerCookieName); + wem.removeCookie(wem.trackerProfileIdCookieName); delete wem.contextLoaded; } else { if (wem.DOMLoaded) { diff --git a/dist/apache-unomi-tracker.cjs.js.map b/dist/apache-unomi-tracker.cjs.js.map index 831e2f4..3fd2ca8 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 256537c..af9ea4f 100644 --- a/dist/apache-unomi-tracker.esm.js +++ b/dist/apache-unomi-tracker.esm.js @@ -221,28 +221,30 @@ var newTracker = function newTracker() { if (filter) { filter.style.display = filter.id === selectedFilter.content ? '' : 'none'; } - } // we now add control group information to event if the user is in the control group. - + } - if (inControlGroup) { - console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); - selectedFilter.event.target.properties.inControlGroup = true; + if (selectedFilter.event) { + // we now add control group information to event if the user is in the control group. + if (inControlGroup) { + console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); + selectedFilter.event.target.properties.inControlGroup = true; - if (selectedFilter.event.target.properties.variants) { - selectedFilter.event.target.properties.variants.forEach(function (variant) { - return variant.inControlGroup = true; - }); - } - } // send event to unomi + if (selectedFilter.event.target.properties.variants) { + selectedFilter.event.target.properties.variants.forEach(function (variant) { + return variant.inControlGroup = true; + }); + } + } // send event to unomi - wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { - console.info('[WEM] Personalization event successfully collected.'); - }, function () { - console.error('[WEM] Could not send personalization event.'); - }); //Trigger variant display event for personalization + wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { + console.info('[WEM] Personalization event successfully collected.'); + }, function () { + console.error('[WEM] Could not send personalization event.'); + }); //Trigger variant display event for personalization - wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + } } else { var elements = document.getElementById(target).children; @@ -283,7 +285,9 @@ var newTracker = function newTracker() { } // select random variant and call unomi - if (!(selectedVariantId && variants[selectedVariantId])) { + var selectVariant = variants[selectedVariantId]; + + if (!(selectedVariantId && selectVariant)) { var keys = Object.keys(variants); if (variantsTraffic) { @@ -305,7 +309,9 @@ var newTracker = function newTracker() { } // spread event to unomi - wem._registerEvent(wem._completeEvent(variants[selectedVariantId].event)); + if (selectVariant.event) { + wem._registerEvent(wem._completeEvent(selectVariant.event)); + } } if (selectedVariantId) { @@ -315,7 +321,7 @@ var newTracker = function newTracker() { } // display the good variant - document.getElementById(variants[selectedVariantId].content).style.display = ''; + document.getElementById(selectVariant.content).style.display = ''; } }, @@ -626,7 +632,8 @@ var newTracker = function newTracker() { expires = '; expires=' + d.toUTCString(); } - document.cookie = cookieName + '=' + cookieValue + expires + '; path=/; SameSite=Strict'; + var secure = location.protocol === 'https:' ? '; secure' : ''; + document.cookie = cookieName + '=' + cookieValue + expires + '; path=/; SameSite=Strict' + secure; }, /** @@ -1512,8 +1519,8 @@ var newTracker = function newTracker() { if (!enable) { wem.cxs = {}; - document.cookie = wem.trackerProfileIdCookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; - document.cookie = wem.contextServerCookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + wem.removeCookie(wem.contextServerCookieName); + wem.removeCookie(wem.trackerProfileIdCookieName); delete wem.contextLoaded; } else { if (wem.DOMLoaded) { diff --git a/dist/apache-unomi-tracker.esm.js.map b/dist/apache-unomi-tracker.esm.js.map index 7744392..befc813 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 de8d511..5014ca0 100644 --- a/dist/apache-unomi-tracker.umd.js +++ b/dist/apache-unomi-tracker.umd.js @@ -1876,28 +1876,30 @@ if (filter) { filter.style.display = filter.id === selectedFilter.content ? '' : 'none'; } - } // we now add control group information to event if the user is in the control group. - + } - if (inControlGroup) { - console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); - selectedFilter.event.target.properties.inControlGroup = true; + if (selectedFilter.event) { + // we now add control group information to event if the user is in the control group. + if (inControlGroup) { + console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); + selectedFilter.event.target.properties.inControlGroup = true; - if (selectedFilter.event.target.properties.variants) { - selectedFilter.event.target.properties.variants.forEach(function (variant) { - return variant.inControlGroup = true; - }); - } - } // send event to unomi + if (selectedFilter.event.target.properties.variants) { + selectedFilter.event.target.properties.variants.forEach(function (variant) { + return variant.inControlGroup = true; + }); + } + } // send event to unomi - wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { - console.info('[WEM] Personalization event successfully collected.'); - }, function () { - console.error('[WEM] Could not send personalization event.'); - }); //Trigger variant display event for personalization + wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { + console.info('[WEM] Personalization event successfully collected.'); + }, function () { + console.error('[WEM] Could not send personalization event.'); + }); //Trigger variant display event for personalization - wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + } } else { var elements = document.getElementById(target).children; @@ -1938,7 +1940,9 @@ } // select random variant and call unomi - if (!(selectedVariantId && variants[selectedVariantId])) { + var selectVariant = variants[selectedVariantId]; + + if (!(selectedVariantId && selectVariant)) { var keys = Object.keys(variants); if (variantsTraffic) { @@ -1960,7 +1964,9 @@ } // spread event to unomi - wem._registerEvent(wem._completeEvent(variants[selectedVariantId].event)); + if (selectVariant.event) { + wem._registerEvent(wem._completeEvent(selectVariant.event)); + } } if (selectedVariantId) { @@ -1970,7 +1976,7 @@ } // display the good variant - document.getElementById(variants[selectedVariantId].content).style.display = ''; + document.getElementById(selectVariant.content).style.display = ''; } }, @@ -2281,7 +2287,8 @@ expires = '; expires=' + d.toUTCString(); } - document.cookie = cookieName + '=' + cookieValue + expires + '; path=/; SameSite=Strict'; + var secure = location.protocol === 'https:' ? '; secure' : ''; + document.cookie = cookieName + '=' + cookieValue + expires + '; path=/; SameSite=Strict' + secure; }, /** @@ -3167,8 +3174,8 @@ if (!enable) { wem.cxs = {}; - document.cookie = wem.trackerProfileIdCookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; - document.cookie = wem.contextServerCookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + wem.removeCookie(wem.contextServerCookieName); + wem.removeCookie(wem.trackerProfileIdCookieName); delete wem.contextLoaded; } else { if (wem.DOMLoaded) { diff --git a/dist/apache-unomi-tracker.umd.js.map b/dist/apache-unomi-tracker.umd.js.map index efb77c4..f6719a7 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 3207722..6200dfd 100644 --- a/src/apache-unomi-tracker.js +++ b/src/apache-unomi-tracker.js @@ -207,25 +207,26 @@ export const newTracker = () => { filter.style.display = (filter.id === selectedFilter.content) ? '' : 'none'; } } - - // we now add control group information to event if the user is in the control group. - if (inControlGroup) { - console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); - selectedFilter.event.target.properties.inControlGroup = true; - if (selectedFilter.event.target.properties.variants) { - selectedFilter.event.target.properties.variants.forEach(variant => variant.inControlGroup = true); + if (selectedFilter.event) { + // we now add control group information to event if the user is in the control group. + if (inControlGroup) { + console.info('[WEM] Profile is in control group for target: ' + target + ', adding to personalization event...'); + selectedFilter.event.target.properties.inControlGroup = true; + if (selectedFilter.event.target.properties.variants) { + selectedFilter.event.target.properties.variants.forEach(variant => variant.inControlGroup = true); + } } - } - // send event to unomi - wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { - console.info('[WEM] Personalization event successfully collected.'); - }, function () { - console.error('[WEM] Could not send personalization event.'); - }); + // send event to unomi + wem.collectEvent(wem._completeEvent(selectedFilter.event), function () { + console.info('[WEM] Personalization event successfully collected.'); + }, function () { + console.error('[WEM] Could not send personalization event.'); + }); - //Trigger variant display event for personalization - wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + //Trigger variant display event for personalization + wem._dispatchJSExperienceDisplayedEvent(selectedFilter.event); + } } else { var elements = document.getElementById(target).children; for (var eIndex in elements) { @@ -266,7 +267,8 @@ export const newTracker = () => { } // select random variant and call unomi - if (!(selectedVariantId && variants[selectedVariantId])) { + let selectVariant = variants[selectedVariantId]; + if (!(selectedVariantId && selectVariant)) { var keys = Object.keys(variants); if (variantsTraffic) { var rand = 100 * Math.random() << 0; @@ -285,7 +287,9 @@ export const newTracker = () => { } // spread event to unomi - wem._registerEvent(wem._completeEvent(variants[selectedVariantId].event)); + if (selectVariant.event) { + wem._registerEvent(wem._completeEvent(selectVariant.event)); + } } if (selectedVariantId) { @@ -295,7 +299,7 @@ export const newTracker = () => { } // display the good variant - document.getElementById(variants[selectedVariantId].content).style.display = ''; + document.getElementById(selectVariant.content).style.display = ''; } },