diff --git a/extensions/cmp_interaction_tracking.js b/extensions/cmp_interaction_tracking.js index 6be00aed..76f05b96 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); } - window.cmp._campaignObj.setCampaignVariables(window.cmp, true); + 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 && (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'; + } else if (eventType !== 12 ) { 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. - window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); - window.utag.data['cp.utag_main_cmp_after'] = 'true'; + 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{ + window.utag.loader.SC('utag_main', {'cmp_after': 'true'}); + window.utag.data['cp.utag_main_cmp_after'] = 'true'; + } } } 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(); }); });