cookiebot
Last commit date
addons
6 years ago
assets
6 years ago
css
6 years ago
documentation
6 years ago
langs
8 years ago
widgets
6 years ago
CookiebotAPI.md
6 years ago
LICENSE.txt
8 years ago
README.md
6 years ago
cookiebot-logo.png
8 years ago
cookiebot.php
6 years ago
phpunit.xml
6 years ago
readme.txt
6 years ago
CookiebotAPI.md
93 lines
| 1 | # How do I make my plugin support Cookiebot? |
| 2 | If you favourite plugins doesn’t support Cookiebot you are always welcome to ask the author to add support for Cookiebot. |
| 3 | Cookiebot provides a helper function to check if there is an active, working version of Cookiebot on the website. |
| 4 | The easiest way for at developer to implement Cookiebot support is to add a check for Cookiebot where tags are outputted to the visitor. |
| 5 | |
| 6 | This can be done following way: |
| 7 | |
| 8 | ```php |
| 9 | $scriptTag = "; |
| 10 | if(function_exists('cookiebot_active') && cookiebot_active()) { |
| 11 | $scriptTag = '<script'.cookiebot_assist('statistics').'>'; |
| 12 | } |
| 13 | ``` |
| 14 | |
| 15 | A users consent state can be be aquired through Cookiebots JS API. |
| 16 | |
| 17 | The following properties are available on the Cookiebot object: |
| 18 | |
| 19 | | Name | Type | Default | Description | |
| 20 | |---------------------|:----:|:-------:|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| |
| 21 | | consent.necessary | bool | true | True if current user has accepted necessary cookies. <br> The property is read only. | |
| 22 | | consent.preferences | bool | false | True if current user has accepted preference cookies. <br> The property is read only. | |
| 23 | | consent.statistics | bool | false | True if current user has accepted statistics cookies. <br> The property is read only. | |
| 24 | | consent.marketing | bool | false | True if current user has accepted marketing cookies. <br> The property is read only. | |
| 25 | | consented | bool | false | True if the user has accepted cookies. <br> The property is read only. | |
| 26 | | declined | bool | false | True if the user has declined the use of cookies. <br> The property is read only. | |
| 27 | | hasResponse | bool | false | True if the user has responded to the dialog with either 'accept' or 'decline'. | |
| 28 | | doNotTrack | bool | false | True if the user has enabled the web browser's 'Do not track' (DNT) setting. <br> If DNT is enabled Cookiebot will not set the third party cookie CookieConsentBulkTicket used for bulk consent. <br> The property is read only. | |
| 29 | |
| 30 | Callbacks |
| 31 | |
| 32 | | Name | Description | |
| 33 | |-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| |
| 34 | | CookiebotCallback_OnLoad | The asynchronous callback is triggered when the cookie banner has loaded to get the user's consent. | |
| 35 | | CookiebotCallback_OnAccept | The asynchronous callback is triggered when the user clicks the accept-button of the cookie consent dialog and whenever a consented user loads a page. | | |
| 36 | | CookiebotCallback_OnDecline | The asynchronous callback is triggered when the user declines the use of cookies by clicking the decline-button in the cookie consent dialog. The callback is also triggered whenever a user that has declined the use of cookies loads a page. | | |
| 37 | |
| 38 | |
| 39 | And through PHP: |
| 40 | |
| 41 | ```php |
| 42 | if (isset($_COOKIE["CookieConsent"])) |
| 43 | { |
| 44 | switch ($_COOKIE["CookieConsent"]) |
| 45 | { |
| 46 | case "0": |
| 47 | //The user has not accepted cookies - set strictly necessary cookies only |
| 48 | break; |
| 49 | |
| 50 | case "-1": |
| 51 | //The user is not within a region that requires consent - all cookies are accepted |
| 52 | break; |
| 53 | |
| 54 | default: //The user has accepted one or more type of cookies |
| 55 | |
| 56 | //Read current user consent in encoded JavaScript format |
| 57 | $valid_php_json = preg_replace('/\s*:\s*([a-zA-Z0-9_]+?)([}\[,])/', ':"$1"$2', preg_replace('/([{\[,])\s*([a-zA-Z0-9_]+?):/', '$1"$2":', str_replace("'", '"',stripslashes($_COOKIE["CookieConsent"])))); |
| 58 | $CookieConsent = json_decode($valid_php_json); |
| 59 | |
| 60 | if (filter_var($CookieConsent->preferences, FILTER_VALIDATE_BOOLEAN)) |
| 61 | { |
| 62 | //Current user accepts preference cookies |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | //Current user does NOT accept preference cookies |
| 67 | } |
| 68 | |
| 69 | if (filter_var($CookieConsent->statistics, FILTER_VALIDATE_BOOLEAN)) |
| 70 | { |
| 71 | //Current user accepts statistics cookies |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | //Current user does NOT accept statistics cookies |
| 76 | } |
| 77 | |
| 78 | if (filter_var($CookieConsent->marketing, FILTER_VALIDATE_BOOLEAN)) |
| 79 | { |
| 80 | //Current user accepts marketing cookies |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | //Current user does NOT accept marketing cookies |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | //The user has not accepted cookies - set strictly necessary cookies only |
| 91 | } |
| 92 | ``` |
| 93 | More details are available at https://www.cookiebot.com/goto/developer/ |