/** * @file ro-ga4.js * @version 2.1.3 * @since 1.0.0 * @date 28 MAR 2024 * @author spencers */ ; 'use strict'; function rogaCheckConsent(){ let settings = {'ad_storage':'denied','analytics_storage':'denied','personalization_storage':'denied','functionality_storage':'denied','security_storage':'denied'}; const roga_GPC_signal = (typeof GPC_DataSharingOptIn == 'undefined' || typeof GPC_DataSharingOptIn != 'boolean') ? false : GPC_DataSharingOptIn; if ( typeof roWcpGetConsentValues == 'function' ) { const consentPreferences = roWcpGetConsentValues(); if ( consentPreferences ) { /* Both user prefs AND the GPC signal must allow for us to grant permission */ if (consentPreferences.Analytics === true) { settings.analytics_storage = 'granted'; } if (consentPreferences.Advertising === true) { settings.ad_storage = 'granted'; } } /* else if (roga_GPC_signal === true) { console.log('roga: using signal'); settings.analytics_storage = 'granted'; settings.ad_storage = 'granted'; } */ } else { let consentCookieName = 'MSCC', cookie = document.cookie.match('(^|;)\\s*' + consentCookieName + '\\s*=\\s*([^;]+)'), mscc = cookie ? cookie.pop() : ''; if (mscc) { /* Both user prefs AND the GPC signal must allow for us to grant permission */ if (mscc == 'NR') { settings.ad_storage = 'granted'; settings.analytics_storage = 'granted'; } else { /* process & honor ONLY affirmative mscc settings, ignoring anything from the overly permissive GPC_DataSharingOptIn bool */ const values = mscc.split('-'); if (values.indexOf('c1=2') > -1) { settings.analytics_storage = 'granted'; } if (values.indexOf('c2=2') > -1) { /* SOCIAL OK...but doesn't impact GA */ } if (values.indexOf('c3=2') > -1) { settings.ad_storage = 'granted'; } } } /* else if (roga_GPC_signal === true) { console.log('roga: no mscc - using signal') settings.analytics_storage = 'granted'; settings.ad_storage = 'granted'; } */ } return settings; } function rogaUpdateGA4Consent(vals=false) { if (!window.dataLayer) { console.log('ro-ga4: no datalayer'); return; } if (typeof gtag != 'function') { try { dataLayer.push('consent', 'default', rogaCheckConsent()); } catch (error) { console.log('ro-ga4: error while updating consent mode using fallback method'); } } else { gtag('consent', 'default', rogaCheckConsent() ); } }