cookiebot-wp-consent-level-api-integration.js
35 lines
| 1 | 'use strict'; |
| 2 | |
| 3 | window.wp_consent_type = 'optin'; |
| 4 | window.addEventListener('CookiebotOnAccept', cookiebot_update_consent_level, false); |
| 5 | window.addEventListener('CookiebotOnDecline', cookiebot_update_consent_level, false); |
| 6 | window.addEventListener('load', cookiebot_update_consent_level, false); |
| 7 | |
| 8 | |
| 9 | function cookiebot_update_consent_level(e) { |
| 10 | |
| 11 | wp_set_consent( 'functional', 'allow' ); //always allow functional cookies |
| 12 | |
| 13 | if ( typeof Cookiebot === 'undefined' ) { |
| 14 | var consentMappingKey = 'n=1;p=1;s=1;m=1'; |
| 15 | } |
| 16 | else { |
| 17 | var consentMappingKey = 'n=1;'; |
| 18 | consentMappingKey = consentMappingKey + 'p=' + ( ( Cookiebot.consent.preferences ) ? '1' : '0' ) + ';'; |
| 19 | consentMappingKey = consentMappingKey + 's=' + ( ( Cookiebot.consent.statistics ) ? '1' : '0' ) + ';'; |
| 20 | consentMappingKey = consentMappingKey + 'm=' + ( ( Cookiebot.consent.marketing ) ? '1' : '0' ); |
| 21 | } |
| 22 | |
| 23 | for( var key in cookiebot_category_mapping[consentMappingKey] ) { |
| 24 | |
| 25 | var strValue = cookiebot_category_mapping[consentMappingKey][key] ? 'allow' : 'deny'; |
| 26 | |
| 27 | if( ( wp_has_consent( key ) && strValue != 'allow' ) || ( !wp_has_consent(key) && strValue == 'allow' ) ) { |
| 28 | wp_set_consent( key, strValue ); |
| 29 | } |
| 30 | |
| 31 | } |
| 32 | |
| 33 | |
| 34 | } |
| 35 |