diff --git a/extensions/cmp/cmp_interaction_tracking.js b/extensions/cmp/cmp_interaction_tracking.js index 7078bc74..d0869369 100644 --- a/extensions/cmp/cmp_interaction_tracking.js +++ b/extensions/cmp/cmp_interaction_tracking.js @@ -66,9 +66,30 @@ sendFirstPageViewEvent, hasUserAlreadyConsentGranted, isAfterCMP, - notPurUser + notPurUser, + getDomainNoConsent }; + function getDomainNoConsent() { + //domains where consent can be rejected + const domains = [ + 'fitbook-magazine.com', + 'myhomebook-magazine.com', + 'petbook-magazine.com', + 'stylebook-magazine.com', + 'techbook-magazine.com', + 'travelbook-magazine.com', + 'shop.welt.de', + 'bildplusshop.bild.de', + ]; + if ((window.utag.data['dom.domain']) && domains.indexOf(window.utag.data['dom.domain']) === -1){ + return false; + } else { + // all other domains are allowed + return true; + } + } + function getABTestingProperties() { if (cmp_ab_id || cmp_ab_desc || cmp_ab_bucket) { return cmp_ab_id + ' ' @@ -149,12 +170,13 @@ } function onUserConsent() { - if (window.cmp && window.cmp._scrollDepthObj) { + const consentCanNotRejected = getDomainNoConsent(); + if (consentCanNotRejected && window.s && window.s._scrollDepthObj) { // Calling setScrollDepthProperties() will make the current page trackable as the _ppvPreviousPage of the next page view. - window.cmp._scrollDepthObj.setScrollDepthProperties(window.cmp); + window.s._scrollDepthObj.setScrollDepthProperties(window.s); } - if (window.cmp && window.cmp._campaignObj) { - window.cmp._campaignObj.setCampaignVariables(window.cmp, true); + if (consentCanNotRejected && window.s && window.s._campaignObj) { + window.s._campaignObj.setCampaignVariables(window.s, true); } } diff --git a/extensions/doPlugins/doPlugins_global.js b/extensions/doPlugins/doPlugins_global.js index 2d19fd9e..1c1fb159 100644 --- a/extensions/doPlugins/doPlugins_global.js +++ b/extensions/doPlugins/doPlugins_global.js @@ -4,19 +4,22 @@ function _getAdobeObject() { // Check if global variables contain the Adobe object or something else. if (window.s && window.s.version) { adobeObject = window.s; - } else if (window.cmp && window.cmp.version) { - adobeObject = window.cmp; - } + } return adobeObject; } const s = _getAdobeObject(); +window.hasConsentForAdobe = function () { + const status = window.utag && window.utag.data && window.utag.data.cmp_event_status; + return status !== 'cmpuishown' || typeof status !== 'undefined'; +}; + // START: Pre-defined Adobe Plugins /* eslint-disable */ /* istanbul ignore next */ /* Adobe Consulting Plugin: getPercentPageViewed v5.0.1 */ -s.getPercentPageViewed = function (pid, ch) { var n = pid, r = ch; function p() { if (window.ppvID) { var a = Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), Math.max(document.body.clientHeight, document.documentElement.clientHeight)), b = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, d = (window.pageYOffset || window.document.documentElement.scrollTop || window.document.body.scrollTop) + b, f = Math.min(Math.round(d / a * 100), 100), l = Math.floor(d / b); b = Math.floor(a / b); var c = ""; if (!window.cookieRead("s_tp") || decodeURIComponent(window.cookieRead("s_ppv").split(",")[0]) !== window.ppvID || window.p_fo(window.ppvID) || 1 == window.ppvChange && window.cookieRead("s_tp") && a != window.cookieRead("s_tp")) { (decodeURIComponent(window.cookieRead("s_ppv").split(",")[0]) !== window.ppvID || window.p_fo(window.ppvID + "1")) && window.cookieWrite("s_ips", d); if (window.cookieRead("s_tp") && decodeURIComponent(window.cookieRead("s_ppv").split(",")[0]) === window.ppvID) { window.cookieRead("s_tp"); c = window.cookieRead("s_ppv"); var h = -1 < c.indexOf(",") ? c.split(",") : []; c = h[0] ? h[0] : ""; h = h[3] ? h[3] : ""; var q = window.cookieRead("s_ips"); c = c + "," + Math.round(h / a * 100) + "," + Math.round(q / a * 100) + "," + h + "," + l } window.cookieWrite("s_tp", a) } else c = window.cookieRead("s_ppv"); var k = c && -1 < c.indexOf(",") ? c.split(",", 6) : []; a = 0 < k.length ? k[0] : encodeURIComponent(window.ppvID); h = 1 < k.length ? parseInt(k[1]) : f; q = 2 < k.length ? parseInt(k[2]) : f; var t = 3 < k.length ? parseInt(k[3]) : d, u = 4 < k.length ? parseInt(k[4]) : l; k = 5 < k.length ? parseInt(k[5]) : b; 0 < f && (c = a + "," + (f > h ? f : h) + "," + q + "," + (d > t ? d : t) + "," + (l > u ? l : u) + "," + (b > k ? b : k)); window.cookieWrite("s_ppv", c) } } if ("-v" === n) return { plugin: "getPercentPageViewed", version: "5.0.1" }; var m = function () { if ("undefined" !== typeof window.s_c_il) for (var a = 0, b; a < window.s_c_il.length; a++)if (b = window.s_c_il[a], b._c && "s_c" === b._c) return b }(); "undefined" !== typeof m && (m.contextData.getPercentPageViewed = "5.0.1"); window.pageName = "undefined" !== typeof m && m.pageName || ""; window.cookieWrite = window.cookieWrite || function (a, b, d) { if ("string" === typeof a) { var f = window.location.hostname, l = window.location.hostname.split(".").length - 1; if (f && !/^[0-9.]+$/.test(f)) { l = 2 < l ? l : 2; var c = f.lastIndexOf("."); if (0 <= c) { for (; 0 <= c && 1 < l;)c = f.lastIndexOf(".", c - 1), l--; c = 0 < c ? f.substring(c) : f } } g = c; b = "undefined" !== typeof b ? "" + b : ""; if (d || "" === b) if ("" === b && (d = -60), "number" === typeof d) { var h = new Date; h.setTime(h.getTime() + 6E4 * d) } else h = d; return a && (document.cookie = encodeURIComponent(a) + "=" + encodeURIComponent(b) + "; path=/;" + (d ? " expires=" + h.toUTCString() + ";" : "") + (g ? " domain=" + g + ";" : ""), "undefined" !== typeof window.cookieRead) ? window.cookieRead(a) === b : !1 } }; window.cookieRead = window.cookieRead || function (a) { if ("string" === typeof a) a = encodeURIComponent(a); else return ""; var b = " " + document.cookie, d = b.indexOf(" " + a + "="), f = 0 > d ? d : b.indexOf(";", d); return (a = 0 > d ? "" : decodeURIComponent(b.substring(d + 2 + a.length, 0 > f ? b.length : f))) ? a : "" }; window.p_fo = window.p_fo || function (a) { window.__fo || (window.__fo = {}); if (window.__fo[a]) return !1; window.__fo[a] = {}; return !0 }; var e = window.cookieRead("s_ppv"); e = -1 < e.indexOf(",") ? e.split(",") : []; n = n ? n : window.pageName ? window.pageName : document.location.href; e[0] = decodeURIComponent(e[0]); window.ppvChange = "undefined" === typeof r || 1 == r ? !0 : !1; "undefined" !== typeof m && m.linkType && "o" === m.linkType || (window.ppvID && window.ppvID === n || (window.ppvID = n, window.cookieWrite("s_ppv", ""), p()), window.p_fo("s_gppvLoad") && window.addEventListener && (window.addEventListener("load", p, !1), window.addEventListener("click", p, !1), window.addEventListener("scroll", p, !1)), this._ppvPreviousPage = e[0] ? e[0] : "", this._ppvHighestPercentViewed = e[1] ? e[1] : "", this._ppvInitialPercentViewed = e[2] ? e[2] : "", this._ppvHighestPixelsSeen = e[3] ? e[3] : "", this._ppvFoldsSeen = e[4] ? e[4] : "", this._ppvFoldsAvailable = e[5] ? e[5] : "") }; +s.getPercentPageViewed = function (pid, ch) { var n = pid, r = ch; function p() { if (window.ppvID) { var a = Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), Math.max(document.body.clientHeight, document.documentElement.clientHeight)), b = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, d = (window.pageYOffset || window.document.documentElement.scrollTop || window.document.body.scrollTop) + b, f = Math.min(Math.round(d / a * 100), 100), l = Math.floor(d / b); b = Math.floor(a / b); var c = ""; if (!window.cookieRead("s_tp") || decodeURIComponent(window.cookieRead("s_ppv").split(",")[0]) !== window.ppvID || window.p_fo(window.ppvID) || 1 == window.ppvChange && window.cookieRead("s_tp") && a != window.cookieRead("s_tp")) { (decodeURIComponent(window.cookieRead("s_ppv").split(",")[0]) !== window.ppvID || window.p_fo(window.ppvID + "1")) && window.cookieWrite("s_ips", d); if (window.cookieRead("s_tp") && decodeURIComponent(window.cookieRead("s_ppv").split(",")[0]) === window.ppvID) { window.cookieRead("s_tp"); c = window.cookieRead("s_ppv"); var h = -1 < c.indexOf(",") ? c.split(",") : []; c = h[0] ? h[0] : ""; h = h[3] ? h[3] : ""; var q = window.cookieRead("s_ips"); c = c + "," + Math.round(h / a * 100) + "," + Math.round(q / a * 100) + "," + h + "," + l } window.cookieWrite("s_tp", a) } else c = window.cookieRead("s_ppv"); var k = c && -1 < c.indexOf(",") ? c.split(",", 6) : []; a = 0 < k.length ? k[0] : encodeURIComponent(window.ppvID); h = 1 < k.length ? parseInt(k[1]) : f; q = 2 < k.length ? parseInt(k[2]) : f; var t = 3 < k.length ? parseInt(k[3]) : d, u = 4 < k.length ? parseInt(k[4]) : l; k = 5 < k.length ? parseInt(k[5]) : b; 0 < f && (c = a + "," + (f > h ? f : h) + "," + q + "," + (d > t ? d : t) + "," + (l > u ? l : u) + "," + (b > k ? b : k)); window.cookieWrite("s_ppv", c) } } if ("-v" === n) return { plugin: "getPercentPageViewed", version: "5.0.1" }; var m = function () { if ("undefined" !== typeof window.s_c_il) for (var a = 0, b; a < window.s_c_il.length; a++)if (b = window.s_c_il[a], b._c && "s_c" === b._c) return b }(); "undefined" !== typeof m && (m.contextData.getPercentPageViewed = "5.0.1"); window.pageName = "undefined" !== typeof m && m.pageName || ""; window.cookieWrite = window.cookieWrite || function (a, b, d) { if (!window.hasConsentForAdobe || !window.hasConsentForAdobe()) return; if ("string" === typeof a) { var f = window.location.hostname, l = window.location.hostname.split(".").length - 1; if (f && !/^[0-9.]+$/.test(f)) { l = 2 < l ? l : 2; var c = f.lastIndexOf("."); if (0 <= c) { for (; 0 <= c && 1 < l;)c = f.lastIndexOf(".", c - 1), l--; c = 0 < c ? f.substring(c) : f } } g = c; b = "undefined" !== typeof b ? "" + b : ""; if (d || "" === b) if ("" === b && (d = -60), "number" === typeof d) { var h = new Date; h.setTime(h.getTime() + 6E4 * d) } else h = d; return a && (document.cookie = encodeURIComponent(a) + "=" + encodeURIComponent(b) + "; path=/;" + (d ? " expires=" + h.toUTCString() + ";" : "") + (g ? " domain=" + g + ";" : ""), "undefined" !== typeof window.cookieRead) ? window.cookieRead(a) === b : !1 } }; window.cookieRead = window.cookieRead || function (a) { if ("string" === typeof a) a = encodeURIComponent(a); else return ""; var b = " " + document.cookie, d = b.indexOf(" " + a + "="), f = 0 > d ? d : b.indexOf(";", d); return (a = 0 > d ? "" : decodeURIComponent(b.substring(d + 2 + a.length, 0 > f ? b.length : f))) ? a : "" }; window.p_fo = window.p_fo || function (a) { window.__fo || (window.__fo = {}); if (window.__fo[a]) return !1; window.__fo[a] = {}; return !0 }; var e = window.cookieRead("s_ppv"); e = -1 < e.indexOf(",") ? e.split(",") : []; n = n ? n : window.pageName ? window.pageName : document.location.href; e[0] = decodeURIComponent(e[0]); window.ppvChange = "undefined" === typeof r || 1 == r ? !0 : !1; "undefined" !== typeof m && m.linkType && "o" === m.linkType || (window.ppvID && window.ppvID === n || (window.ppvID = n, window.cookieWrite("s_ppv", ""), p()), window.p_fo("s_gppvLoad") && window.addEventListener && (window.addEventListener("load", p, !1), window.addEventListener("click", p, !1), window.addEventListener("scroll", p, !1)), this._ppvPreviousPage = e[0] ? e[0] : "", this._ppvHighestPercentViewed = e[1] ? e[1] : "", this._ppvInitialPercentViewed = e[2] ? e[2] : "", this._ppvHighestPixelsSeen = e[3] ? e[3] : "", this._ppvFoldsSeen = e[4] ? e[4] : "", this._ppvFoldsAvailable = e[5] ? e[5] : "") }; /* istanbul ignore next */ /* Adobe Consulting Plugin: handlePPVevents helper function (for getPercentPageViewed v4.0 Plugin) */ s.handlePPVevents = function () { if ("undefined" !== typeof s_c_il) { for (var c = 0, g = s_c_il.length; c < g; c++)if (s_c_il[c] && (s_c_il[c].getPercentPageViewed || s_c_il[c].getPreviousPageActivity)) { var s = s_c_il[c]; break } if (s && s.ppvID) { var f = Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), Math.max(document.body.clientHeight, document.documentElement.clientHeight)), h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; c = (window.pageYOffset || window.document.documentElement.scrollTop || window.document.body.scrollTop) + h; g = Math.min(Math.round(c / f * 100), 100); var k = Math.floor(c / h); h = Math.floor(f / h); var d = ""; if (!s.c_r("s_tp") || s.unescape(s.c_r("s_ppv").split(",")[0]) !== s.ppvID || s.p_fo(s.ppvID) || 1 == s.ppvChange && s.c_r("s_tp") && f != s.c_r("s_tp")) { (s.unescape(s.c_r("s_ppv").split(",")[0]) !== s.ppvID || s.p_fo(s.ppvID + "1")) && s.c_w("s_ips", c); if (s.c_r("s_tp") && s.unescape(s.c_r("s_ppv").split(",")[0]) === s.ppvID) { s.c_r("s_tp"); d = s.c_r("s_ppv"); var e = -1 < d.indexOf(",") ? d.split(",") : []; d = e[0] ? e[0] : ""; e = e[3] ? e[3] : ""; var l = s.c_r("s_ips"); d = d + "," + Math.round(e / f * 100) + "," + Math.round(l / f * 100) + "," + e + "," + k } s.c_w("s_tp", f) } else d = s.c_r("s_ppv"); var b = d && -1 < d.indexOf(",") ? d.split(",", 6) : []; f = 0 < b.length ? b[0] : escape(s.ppvID); e = 1 < b.length ? parseInt(b[1]) : g; l = 2 < b.length ? parseInt(b[2]) : g; var m = 3 < b.length ? parseInt(b[3]) : c, n = 4 < b.length ? parseInt(b[4]) : k; b = 5 < b.length ? parseInt(b[5]) : h; 0 < g && (d = f + "," + (g > e ? g : e) + "," + l + "," + (c > m ? c : m) + "," + (k > n ? k : n) + "," + (h > b ? h : b)); s.c_w("s_ppv", d) } } }; @@ -104,7 +107,7 @@ s._utils = { return ARTICLE_TYPES.indexOf(pageType) !== -1; }, isFirstPageView: function () { - return window.utag.data.cmp_event_status == 'cmpuishown'; + return window.utag.data.cmp_event_status == 'cmpuishown' || typeof window.utag.data.cmp_event_status == 'undefined'; }, isValidURL: function (urlString) { try { diff --git a/tests/cmp/cmp_interaction_tracking.test.js b/tests/cmp/cmp_interaction_tracking.test.js index beb9685b..624fbdb4 100644 --- a/tests/cmp/cmp_interaction_tracking.test.js +++ b/tests/cmp/cmp_interaction_tracking.test.js @@ -297,21 +297,13 @@ describe('CMP Interaction Tracking', () => { }); describe('onUserConsent()', () => { - it('should call the scroll-depth feature of the doPlugins extension', function () { - window.cmp = { - _scrollDepthObj: { - setScrollDepthProperties: jest.fn() - }, - _campaignObj: { - setCampaignVariables: jest.fn() - } - }; - cmpInteractionTracking.onUserConsent(); - expect(window.cmp._scrollDepthObj.setScrollDepthProperties).toHaveBeenCalled(); + + beforeEach(() => { + jest.spyOn(cmpInteractionTracking, 'getDomainNoConsent').mockImplementation().mockReturnValue(true); }); it('should call _campaignObj.setCampaignVariables() of the doPlugins extension', function () { - window.cmp = { + window.s = { _scrollDepthObj: { setScrollDepthProperties: jest.fn() }, @@ -320,7 +312,7 @@ describe('CMP Interaction Tracking', () => { } }; cmpInteractionTracking.onUserConsent(); - expect(window.cmp._campaignObj.setCampaignVariables).toHaveBeenCalledWith(window.cmp, true); + expect(window.s._campaignObj.setCampaignVariables).toHaveBeenCalledWith(window.s, true); }); }); diff --git a/tests/doplugins/doplugins_utils.test.js b/tests/doplugins/doplugins_utils.test.js index b1c2ada0..8c6490cb 100644 --- a/tests/doplugins/doplugins_utils.test.js +++ b/tests/doplugins/doplugins_utils.test.js @@ -38,18 +38,6 @@ describe('s_utils', () => { expect(result).toEqual({}); }); - it('should return the Adobe object when it has the name \'cmp\'', () => { - window.cmp = validAdobeObject; - const result = s._utils.getAdobeObject(); - expect(result).toBe(validAdobeObject); - }); - - it('should return an empty object when something else is assigned to the global variable with name \'cmp\'', () => { - window.cmp = invalidAdobeObject; - const result = s._utils.getAdobeObject(); - expect(result).toEqual({}); - }); - it('should return an empty object when something else is assigned to the global variables \'s\' and \'cmp\' ', () => { window.s = invalidAdobeObject; window.cmp = invalidAdobeObject;