From e09116f869607b2444246cdc476d2240ee81f485 Mon Sep 17 00:00:00 2001 From: Danilo Grimm Date: Thu, 28 Sep 2023 22:50:06 +0200 Subject: [PATCH 1/5] Update cmp_interaction_tracking.js TRAC-1905 (unified SP script update) TRAC-1787 (Campaign issue) TRAC-SpoBi Relaunch to Lean --- extensions/cmp_interaction_tracking.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/extensions/cmp_interaction_tracking.js b/extensions/cmp_interaction_tracking.js index 6be00aed..10b9daf5 100644 --- a/extensions/cmp_interaction_tracking.js +++ b/extensions/cmp_interaction_tracking.js @@ -98,12 +98,15 @@ function isAfterCMP() { const hasCMPAfterCookie = window.utag.data['cp.utag_main_cmp_after'] ? (window.utag.data['cp.utag_main_cmp_after'] === 'true') : false; + const hasCMPAfterCookie_subdomain = window.utag.data['cp.utag_main_cmp_after_sub'] ? (window.utag.data['cp.utag_main_cmp_after_sub'] === 'true') : false; const defaultVendorList = 'adobe_cmp,'; const hasVendors = !!window.utag.data.consentedVendors && window.utag.data.consentedVendors !== defaultVendorList; + const hasVendors_subdomain = !!window.utag.data['cp.cm_cv_list'] && window.utag.data['cp.cm_cv_list'] !== defaultVendorList; // sportbild.bild.de needs special treatment because of sub-domain issues. const subdomains = [ 'sportbild.bild.de', + 'm.sportbild.bild.de', 'shop.bild.de', 'angebot.bild.de', 'shopping.welt.de', @@ -113,7 +116,7 @@ // sportbild.bild.de, shop.bild.de, offerpages needs special treatment because of sub-domain issues. if ((window.utag.data['dom.domain']) && subdomains.indexOf(window.utag.data['dom.domain']) !== -1){ // hasCMPAfterCookie cannot be used here because it shares cookie with base domain - return hasVendors; + return hasCMPAfterCookie_subdomain || hasVendors_subdomain; } else { return hasCMPAfterCookie || hasVendors; } @@ -142,7 +145,9 @@ // Calling setScrollDepthProperties() will make the current page trackable as the _ppvPreviousPage of the next page view. window.cmp._scrollDepthObj.setScrollDepthProperties(window.cmp); } + if (window.cmp && window.cmp._campaignObj) { window.cmp._campaignObj.setCampaignVariables(window.cmp, true); + } } function sendFirstPageViewEvent() { @@ -153,16 +158,20 @@ } } - function onMessageChoiceSelect(id, eventType) { + function onMessageChoiceSelect(messageType, id, eventType) { if (CONSENT_MESSAGE_EVENTS[eventType]) { window.utag.data['cmp_events'] = CONSENT_MESSAGE_EVENTS[eventType]; exportedFunctions.sendLinkEvent(CONSENT_MESSAGE_EVENTS[eventType]); - if (eventType === 11 || eventType === 13) { + if ((eventType === 11 && (utag.data['dom.domain'] && utag.data['dom.domain'].includes("sportbild.bild.de"))) || (eventType === 13 && (utag.data['dom.domain'] && utag.data['dom.domain'].includes("sportbild.bild.de")))) + { + window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); + window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; + } else{ window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); window.utag.data['cp.utag_main_cmp_after'] = 'true'; } - + if (eventType === 11) { exportedFunctions.onUserConsent(); } @@ -174,8 +183,13 @@ window.utag.data['cmp_events'] = eventType.purposeConsent ? (eventType.purposeConsent === 'all' ? PRIVACY_MANAGER_EVENTS.ACCEPT_ALL : PRIVACY_MANAGER_EVENTS.SAVE_AND_EXIT) : PRIVACY_MANAGER_EVENTS[eventType]; exportedFunctions.sendLinkEvent(window.utag.data['cmp_events']); // Set cookie for first page view tracking. + if (utag.data['dom.domain'] && utag.data['dom.domain'].includes("sportbild.bild.de")){ + window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); + window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; + }else{ window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); window.utag.data['cp.utag_main_cmp_after'] = 'true'; + } } } From 8482f4df1913e92c765cb4b81d6a68bb88decca4 Mon Sep 17 00:00:00 2001 From: Danilo Grimm Date: Thu, 28 Sep 2023 22:57:55 +0200 Subject: [PATCH 2/5] Update cmp_interaction_tracking.js --- extensions/cmp_interaction_tracking.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/cmp_interaction_tracking.js b/extensions/cmp_interaction_tracking.js index 10b9daf5..24dac3b4 100644 --- a/extensions/cmp_interaction_tracking.js +++ b/extensions/cmp_interaction_tracking.js @@ -116,7 +116,7 @@ // sportbild.bild.de, shop.bild.de, offerpages needs special treatment because of sub-domain issues. if ((window.utag.data['dom.domain']) && subdomains.indexOf(window.utag.data['dom.domain']) !== -1){ // hasCMPAfterCookie cannot be used here because it shares cookie with base domain - return hasCMPAfterCookie_subdomain || hasVendors_subdomain; + return hasCMPAfterCookie_subdomain || hasVendors_subdomain; } else { return hasCMPAfterCookie || hasVendors; } @@ -146,7 +146,7 @@ window.cmp._scrollDepthObj.setScrollDepthProperties(window.cmp); } if (window.cmp && window.cmp._campaignObj) { - window.cmp._campaignObj.setCampaignVariables(window.cmp, true); + window.cmp._campaignObj.setCampaignVariables(window.cmp, true); } } @@ -163,7 +163,7 @@ window.utag.data['cmp_events'] = CONSENT_MESSAGE_EVENTS[eventType]; exportedFunctions.sendLinkEvent(CONSENT_MESSAGE_EVENTS[eventType]); - if ((eventType === 11 && (utag.data['dom.domain'] && utag.data['dom.domain'].includes("sportbild.bild.de"))) || (eventType === 13 && (utag.data['dom.domain'] && utag.data['dom.domain'].includes("sportbild.bild.de")))) + if ((eventType === 11 && (window.utag.data['dom.domain'] && window.utag.data['dom.domain'].includes('sportbild.bild.de'))) || (eventType === 13 && (window.utag.data['dom.domain'] && window.utag.data['dom.domain'].includes('sportbild.bild.de')))) { window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; @@ -183,7 +183,7 @@ window.utag.data['cmp_events'] = eventType.purposeConsent ? (eventType.purposeConsent === 'all' ? PRIVACY_MANAGER_EVENTS.ACCEPT_ALL : PRIVACY_MANAGER_EVENTS.SAVE_AND_EXIT) : PRIVACY_MANAGER_EVENTS[eventType]; exportedFunctions.sendLinkEvent(window.utag.data['cmp_events']); // Set cookie for first page view tracking. - if (utag.data['dom.domain'] && utag.data['dom.domain'].includes("sportbild.bild.de")){ + if (window.utag.data['dom.domain'] && window.utag.data['dom.domain'].includes('sportbild.bild.de')){ window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; }else{ From 3954521583304e19841caf4b286592a011942b17 Mon Sep 17 00:00:00 2001 From: Danilo Grimm Date: Thu, 28 Sep 2023 23:00:01 +0200 Subject: [PATCH 3/5] Update cmp_interaction_tracking.js --- extensions/cmp_interaction_tracking.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/cmp_interaction_tracking.js b/extensions/cmp_interaction_tracking.js index 24dac3b4..017aa5c2 100644 --- a/extensions/cmp_interaction_tracking.js +++ b/extensions/cmp_interaction_tracking.js @@ -184,11 +184,11 @@ exportedFunctions.sendLinkEvent(window.utag.data['cmp_events']); // Set cookie for first page view tracking. if (window.utag.data['dom.domain'] && window.utag.data['dom.domain'].includes('sportbild.bild.de')){ - window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); - window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; + window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); + window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; }else{ - window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); - window.utag.data['cp.utag_main_cmp_after'] = 'true'; + window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); + window.utag.data['cp.utag_main_cmp_after'] = 'true'; } } } From ed3ccc8c2925683c5eea1f76cfb767480fc1a908 Mon Sep 17 00:00:00 2001 From: Mehak Raza Date: Tue, 24 Oct 2023 12:28:36 +0200 Subject: [PATCH 4/5] Fixed unit tests for cmp interaction tracking --- tests/cmp_interaction_tracking.test.js | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/cmp_interaction_tracking.test.js b/tests/cmp_interaction_tracking.test.js index 3f68a4bb..05b50333 100644 --- a/tests/cmp_interaction_tracking.test.js +++ b/tests/cmp_interaction_tracking.test.js @@ -322,14 +322,14 @@ describe('CMP Interaction Tracking', () => { }); }); - describe('onMessageChoiceSelect(id, eventType)', () => { + describe('onMessageChoiceSelect(messageType, id, eventType)', () => { beforeEach(() => { jest.spyOn(cmpInteractionTracking, 'sendLinkEvent').mockImplementation(); jest.spyOn(cmpInteractionTracking, 'onUserConsent').mockImplementation(); }); it('should set correct utag.data properties when user gives consent', () => { - cmpInteractionTracking.onMessageChoiceSelect('any-id', 11); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'any-id', 11); expect(window.utag.data).toEqual({ 'cmp_events': 'cm_accept_all', 'cp.utag_main_cmp_after': 'true' @@ -337,24 +337,22 @@ describe('CMP Interaction Tracking', () => { }); it('should call sendLinkEvent with correct argument when user gives consent', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 11); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 11); expect(cmpInteractionTracking.sendLinkEvent).toHaveBeenLastCalledWith('cm_accept_all'); }); it('should set correct utag.data properties when user opens privacy manager', () => { - cmpInteractionTracking.onMessageChoiceSelect('any-id', 12); - expect(window.utag.data).toEqual({ - 'cmp_events': 'cm_show_privacy_manager' - }); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'any-id', 12); + expect(window.utag.data.cmp_events).toBe('cm_show_privacy_manager'); }); it('should call sendLinkEvent with correct argument when user opens privacy manager', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 12); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 12); expect(cmpInteractionTracking.sendLinkEvent).toHaveBeenLastCalledWith('cm_show_privacy_manager'); }); it('should set correct utag.data properties when user declines consent', () => { - cmpInteractionTracking.onMessageChoiceSelect('any-id', 13); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'any-id', 13); expect(window.utag.data).toEqual({ 'cmp_events': 'cm_reject_all', 'cp.utag_main_cmp_after': 'true' @@ -362,40 +360,40 @@ describe('CMP Interaction Tracking', () => { }); it('should call sendLinkEvent with correct argument when user declines consent', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 13); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 13); expect(cmpInteractionTracking.sendLinkEvent).toHaveBeenLastCalledWith('cm_reject_all'); }); it('should NOT call sendLinkEvent when called with wrong event type', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 999); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 999); expect(cmpInteractionTracking.sendLinkEvent).not.toHaveBeenCalled(); }); it('should set utag_main_cmp_after cookie to true when user gives consent', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 11); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 11); expect(window.utag.loader.SC).toHaveBeenCalledWith('utag_main', {'cmp_after': 'true'}); expect(window.utag.data['cp.utag_main_cmp_after']).toBe('true'); }); it('should set utag_main_cmp_after cookie to true when user declines consent', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 13); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 13); expect(window.utag.loader.SC).toHaveBeenCalledWith('utag_main', {'cmp_after': 'true'}); expect(window.utag.data['cp.utag_main_cmp_after']).toBe('true'); }); it('should NOT set utag_main_cmp_after cookie when user opens privacy manager', () => { - cmpInteractionTracking.onMessageChoiceSelect('test', 12); - expect(window.utag.loader.SC).not.toHaveBeenCalledWith('utag_main', {'cmp_after': 'true'}); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'test', 12); + expect(window.utag.loader.SC).not.toHaveBeenCalledWith(['utag_main', expect.objectContaining({'cmp_after': 'true'})]); expect(window.utag.data['cp.utag_main_cmp_after']).toBeUndefined(); }); it('should call onUserConsent() when user has given consent', function () { - cmpInteractionTracking.onMessageChoiceSelect('any-id', 11); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'any-id', 11); expect(cmpInteractionTracking.onUserConsent).toHaveBeenCalled(); }); it('should not call onUserConsent() when user has NOT given consent', function () { - cmpInteractionTracking.onMessageChoiceSelect('any-id', 12); + cmpInteractionTracking.onMessageChoiceSelect('any-message', 'any-id', 12); expect(cmpInteractionTracking.onUserConsent).not.toHaveBeenCalled(); }); }); From ca2860f2fb27d59e8751287034c4105a22db6463 Mon Sep 17 00:00:00 2001 From: Nicole Emer Date: Wed, 8 Nov 2023 14:44:16 +0100 Subject: [PATCH 5/5] event12 excluded in onMessageChoiceSelect to solve failing unit test --- extensions/cmp_interaction_tracking.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/cmp_interaction_tracking.js b/extensions/cmp_interaction_tracking.js index 017aa5c2..76f05b96 100644 --- a/extensions/cmp_interaction_tracking.js +++ b/extensions/cmp_interaction_tracking.js @@ -167,7 +167,7 @@ { window.utag.loader.SC('utag_main', {'cmp_after_sub': 'true'}); window.utag.data['cp.utag_main_cmp_after_sub'] = 'true'; - } else{ + } else if (eventType !== 12 ) { window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); window.utag.data['cp.utag_main_cmp_after'] = 'true'; }