| 1 |
'use strict'; |
| 2 |
(window => { |
| 3 |
let ucConsentMappingKey = {}; |
| 4 |
window.addEventListener('UC_CONSENT', (event)=> {cookiebot_update_consent_level(event)}, false); |
| 5 |
window.addEventListener('load', set_wp_consent_status, false); |
| 6 |
|
| 7 |
function set_wp_consent_status(){ |
| 8 |
if (typeof wp_set_consent === 'function') { |
| 9 |
wp_set_consent('functional', 'allow'); //always allow functional cookies |
| 10 |
Object.values(cookiebot_category_mapping).forEach(category => { |
| 11 |
const strValue = ucConsentMappingKey[category.toString()]; |
| 12 |
wp_set_consent(category.toString(), strValue); |
| 13 |
}); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
function cookiebot_update_consent_level(event) { |
| 18 |
const ucConsentDetails = typeof event.detail !== 'undefined' ? event.detail.consent.setting.type : false; |
| 19 |
const ucConsentCategories = typeof event.detail !== 'undefined' ? event.detail.categories : false; |
| 20 |
window.wp_consent_type = ucConsentDetails === 'US' ? 'optout' : 'optin'; |
| 21 |
|
| 22 |
const consents = new Map([['preferences', 'allow'], ['marketing', 'allow']]); |
| 23 |
|
| 24 |
consents.set('preferences', check_category_state( ucConsentCategories.functional ) ); |
| 25 |
consents.set('marketing', check_category_state( ucConsentCategories.marketing ) ); |
| 26 |
|
| 27 |
Array.from(consents.entries()).map(([key, value]) => {ucConsentMappingKey[key] = value}); |
| 28 |
|
| 29 |
set_wp_consent_status() |
| 30 |
} |
| 31 |
|
| 32 |
function check_category_state(category) { |
| 33 |
if(!category) |
| 34 |
return window.wp_consent_type === 'optin' ? 'deny' : 'allow'; |
| 35 |
return category.state === 'ALL_DENIED' ? 'deny' : 'allow'; |
| 36 |
} |
| 37 |
|
| 38 |
})(window); |