1/** 2 * Dynatrace Cookie Consent Handler (Common) 3 * Version: 3 4 * 5 * Integrates Dynatrace RUM with TrustArc consent manager. 6 * Enables/disables Dynatrace tracking based on user's Performance cookie consent. 7 * Uses separate TrustArc identifiers for cookie parsing and API-based consent checks. 8 * 9 * Shared across all MSI storefronts: 10 * - Classic (OCC Storefront) 11 * - B2P/B2B (OSF - Oracle Storefront Framework) 12 * - B2C (OSF - Oracle Storefront Framework) 13 */ 14 15(function () { 16 var PERFORMANCE_COOKIE_ID = 1; 17 var PERFORMANCE_API_ID = 2; 18 var TRUSTARC_COOKIE_NAME = 'notice_gdpr_prefs'; 19 var SITE_DOMAIN = window.location.hostname; 20 21 function enableDynatrace() { 22 if (window.dtrum && typeof window.dtrum.enable === 'function') { 23 window.dtrum.enable(); 24 console.log('ð Dynatrace RUM: Enabled'); 25 } 26 } 27 28 function disableDynatrace() { 29 if (window.dtrum && typeof window.dtrum.disable === 'function') { 30 window.dtrum.disable(); 31 console.log('ð Dynatrace RUM: Disabled'); 32 } 33 } 34 35 function checkConsentViaAPI() { 36 try { 37 if (window.truste && window.truste.cma && typeof window.truste.cma.callApi === 'function') { 38 var result = window.truste.cma.callApi('getGDPRConsentDecision', SITE_DOMAIN); 39 40 if (result && result.consentDecision && Array.isArray(result.consentDecision)) { 41 console.log('â TrustArc API detected. Decisions:', result.consentDecision); 42 return result.consentDecision.indexOf(PERFORMANCE_API_ID) !== -1; 43 } 44 } 45 } catch (e) { 46 console.warn('â ï¸ TrustArc API Error (fallback to cookie):', e); 47 } 48 return null; // Null means "don't know, check cookies" 49 } 50 51 function checkConsentViaCookie() { 52 var match = document.cookie.match(new RegExp('(^| )' + TRUSTARC_COOKIE_NAME + '=([^;]+)')); 53 if (match) { 54 var prefs = decodeURIComponent(match[2]); 55 return prefs.indexOf(String(PERFORMANCE_COOKIE_ID)) !== -1; 56 } 57 return false; // ZTL by default 58 } 59 60 function evaluateConsent() { 61 var apiResult = checkConsentViaAPI(); 62 var hasConsent = false; 63 64 if (apiResult !== null) { 65 hasConsent = apiResult; 66 } else { 67 console.log('ðª TrustArc API unavailable. Falling back to Cookie check.'); 68 hasConsent = checkConsentViaCookie(); 69 } 70 71 if (hasConsent) { 72 enableDynatrace(); 73 } else { 74 console.log('ð¤ Dynatrace RUM: Waiting for consent (Passive Mode)'); 75 } 76 } 77 78 function handleTrustArcMessage(e) { 79 if (typeof e.data !== 'string' && typeof e.data !== 'object') return; 80 81 var data = e.data; 82 if (typeof data === 'string') { 83 try { 84 data = JSON.parse(data); 85 } catch (err) { 86 return; 87 } 88 } 89 90 if (data && data.source === 'preference_manager' && data.message === 'submit_preferences') { 91 var isGranted = data.data && data.data.indexOf(String(PERFORMANCE_COOKIE_ID)) !== -1; 92 93 if (isGranted) { 94 enableDynatrace(); 95 } else { 96 disableDynatrace(); 97 } 98 } 99 } 100 101 evaluateConsent(); 102 window.dtsreEvaluateConsent = evaluateConsent; 103 window.addEventListener('message', handleTrustArcMessage); 104})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.