PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.7.4
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.7.4
4.7.4 4.7.5 4.7.3 4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 All 95 releases
cookiebot / assets / js / frontend / uc_frame / uc-wp-consent-level-api-integration.js

uc-wp-consent-level-api-integration.js in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 4.7.4, at assets/js/frontend/uc_frame/uc-wp-consent-level-api-integration.js

38 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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);