### Event Handling: Load Marketing Cookies on Accept Source: https://www.cookiebot.com/us/developer An example of how to listen for the 'CookiebotOnAccept' event and conditionally load marketing cookies if the user has accepted them. ```APIDOC ## Event Handling: Load Marketing Cookies on Accept ### Description Listen for the `CookiebotOnAccept` event and execute code to set marketing cookies only if the user has explicitly accepted marketing consent. ### Method JavaScript event listener ### Endpoint ```html ``` ### Parameters None. ### Request Example ```html ``` ### Response Not applicable. ### Notes This script should be placed in your website's HTML. ``` -------------------------------- ### Script Tag Data Attributes: Force Dialog Culture Source: https://www.cookiebot.com/us/developer Shows how to use the `data-culture` attribute within the script tag to force the consent dialog to display in a specific language, using English (EN) as an example. ```APIDOC ## Script Tag Data Attributes: Force Dialog Culture ### Description Use the `data-culture` attribute in the Cookiebot CMP script tag to specify the language for the consent dialog. This example forces the dialog to display in English (EN). ### Method Script tag attribute ### Endpoint ```html ``` ### Parameters #### Request Body - **data-culture** (string) - Required - The culture code for the desired language (e.g., "EN" for English). - **data-cbid** (string) - Required - Your domain group ID. ### Request Example ```html ``` ### Response Not applicable. ### Notes Ensure you replace `00000000-0000-0000-0000-000000000000` with your actual domain group ID. ``` -------------------------------- ### Renew or Change Cookie Consent Source: https://www.cookiebot.com/us/developer Provides an example of creating a custom link to allow users to renew or change their cookie consent, bypassing the default Privacy Trigger. ```APIDOC ## Renew or Change Cookie Consent ### Description Create a custom link that allows users to renew or change their cookie consent. This is an alternative to using the default Cookiebot CMP Privacy Trigger. ### Method JavaScript invocation ### Endpoint ```html Renew or change your cookie consent ``` ### Parameters None. ### Request Example ```html Renew or change your cookie consent ``` ### Response Not applicable. ### Notes While this provides a custom link option, using the Cookiebot CMP Privacy Trigger is recommended for the best user experience. ``` -------------------------------- ### Callback: Load Statistics Cookies on Opt-in Source: https://www.cookiebot.com/us/developer Demonstrates how to use the `CookiebotCallback_OnAccept` function to load statistics cookies if the user has opted in to statistics cookies. This is relevant when `data-blockingmode` is not 'auto'. ```APIDOC ## Callback: Load Statistics Cookies on Opt-in ### Description Implement the `CookiebotCallback_OnAccept` function to enable statistics cookies if the user has opted in to statistics. This is applicable when `data-blockingmode` is not set to "auto" and scripts are not marked for control with `data-cookieconsent`. ### Method JavaScript callback function ### Endpoint ```html ``` ### Parameters None. ### Request Example ```html ``` ### Response Not applicable. ### Notes This example assumes you have a function `enableStatisticsCookies()` defined elsewhere to handle the actual setting of statistics cookies. ``` -------------------------------- ### Loading the Cookiebot CMP Script Source: https://www.cookiebot.com/us/developer Instructions on how to implement the Cookiebot CMP script on your website, either directly or with a data-cbid attribute. ```APIDOC ## Loading the Cookiebot CMP Script ### Description Implement the Cookiebot CMP script on your website using one of the following methods. ### Method Link tag ### Endpoint ```html ``` Or: ```html ``` ### Parameters #### Query Parameters - **cbid** (string) - Required - Your domain group ID. #### Request Body Not applicable. ### Request Example Not applicable. ### Response Not applicable. ### Notes Replace `00000000-0000-0000-0000-000000000000` with your actual domain group ID. ``` -------------------------------- ### Handle Cookiebot OnAccept Event Source: https://www.cookiebot.com/us/developer This JavaScript code listens for the 'CookiebotOnAccept' event. If marketing cookies are accepted, it executes custom code to set those cookies. This is useful for dynamically loading content based on user consent. ```javascript window.addEventListener('CookiebotOnAccept', function (e) { if (Cookiebot.consent.marketing) { //Execute code that sets marketing cookies } }, false); ``` -------------------------------- ### Implement CookiebotCallback_OnAccept for Statistics Cookies Source: https://www.cookiebot.com/us/developer This JavaScript function is a callback that executes when a user accepts cookies. It checks if statistics cookies are opted in and then calls a function to enable them. This is relevant if data-blockingmode is not 'auto' and scripts are not marked for control. ```javascript function CookiebotCallback_OnAccept() { if (Cookiebot.consent.statistics) { enableStatisticsCookies(); } } function enableStatisticsCookies() { //Execute code that sets statistics cookies } ``` -------------------------------- ### Load Cookiebot CMP Script Source: https://www.cookiebot.com/us/developer Implement the Cookiebot CMP script on your website by including one of these script URLs. Ensure you replace the placeholder domain group ID with your actual ID. ```html https://consent.cookiebot.com/uc.js?cbid=00000000-0000-0000-0000-00000000000 ``` ```html https://consent.cookiebot.com/uc.js ``` -------------------------------- ### Force Consent Dialog Language using data-culture Source: https://www.cookiebot.com/us/developer Configure the Cookiebot CMP script to display the consent dialog in a specific language by setting the 'data-culture' attribute on the script tag. Replace 'EN' with the desired culture code. ```html ``` -------------------------------- ### Check User Consent in PHP Source: https://www.cookiebot.com/us/developer Parse the 'CookieConsent' cookie value in PHP to check user consent for different cookie categories. Includes logic for handling opted-out users and specific category acceptances. ```php if (isset($_COOKIE["CookieConsent"])) { switch ($_COOKIE["CookieConsent"]) { case "-1": //The user is not within a region that requires consent - all cookies are accepted break; default: //The user has given their consent //Read current user consent in encoded JavaScript format $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"])))); $CookieConsent = json_decode($valid_php_json); if (!filter_var($CookieConsent->preferences, FILTER_VALIDATE_BOOLEAN) && !filter_var($CookieConsent->statistics, FILTER_VALIDATE_BOOLEAN) && ! filter_var($CookieConsent->marketing, FILTER_VALIDATE_BOOLEAN)) { //The user has opted out of cookies, set strictly necessary cookies only } else { if (filter_var($CookieConsent->preferences, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts preference cookies } else { //Current user does NOT accept preference cookies } if (filter_var($CookieConsent->statistics, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts statistics cookies } else { //Current user does NOT accept statistics cookies } if (filter_var($CookieConsent->marketing, FILTER_VALIDATE_BOOLEAN)) { //Current user accepts marketing cookies } else { //Current user does NOT accept marketing cookies } } } } else { //The user has not accepted cookies - set strictly necessary cookies only } ``` -------------------------------- ### Check User Consent in VB.NET Source: https://www.cookiebot.com/us/developer Retrieve and check the 'CookieConsent' cookie value in VB.NET to manage server-side cookie settings based on user consent. ```vbnet Imports System.Web.Script.Serialization ... Dim CurrentUserConsent As HttpCookie = Request.Cookies("CookieConsent") If CurrentUserConsent IsNot Nothing Then Select Case CurrentUserConsent.Value Case "-1" ``` -------------------------------- ### Check User Consent in C# Source: https://www.cookiebot.com/us/developer Read user consent state from the 'CookieConsent' cookie to determine which cookie categories are accepted. Handles cases where consent is not required, given, or opted out. ```csharp using System.Web.Script.Serialization; ... HttpCookie CurrentUserConsent = Request.Cookies["CookieConsent"]; if (CurrentUserConsent != null) { switch (CurrentUserConsent.Value) { case "-1": //The user is not within a region that requires consent - all cookies are accepted break; default: //The user has given their consent //Read current user consent in encoded JavaScript format JavaScriptSerializer CookieConsentSerializer = new JavaScriptSerializer(); dynamic CookieConsent = CookieConsentSerializer.Deserialize(HttpUtility.UrlDecode(CurrentUserConsent.Value)); if (!CookieConsent["preferences"] && !CookieConsent["statistics"] && !CookieConsent["marketing"]) { //The user has opted out of cookies, set strictly necessary cookies only } else { if (CookieConsent["preferences"]) { //Current user accepts preference cookies } else { //Current user does NOT accept preference cookies } if (CookieConsent["statistics"]) { //Current user accepts statistics cookies } else { //Current user does NOT accept statistics cookies } if (CookieConsent["marketing"]) { //Current user accepts marketing cookies } else { //Current user does NOT accept marketing cookies } } } } else { //The user has not accepted cookies - set strictly necessary cookies only } ``` -------------------------------- ### Read User Consent Server-Side Source: https://www.cookiebot.com/us/developer Deserialize user consent from JavaScript format to check individual cookie preferences. This code should be used when you need to make server-side decisions based on user consent. ```vb.net REM The user is not within a region that requires consent - all cookies are accepted Exit Select Case Else REM The user has given their consent REM Read current user consent in encoded JavaScript format Dim CookieConsentSerializer As New JavaScriptSerializer() Dim CookieConsent As dynamic = CookieConsentSerializer.Deserialize(Of Object)(HttpUtility.UrlDecode(CurrentUserConsent.Value)) If Not CookieConsent("preferences") And Not CookieConsent("statistics") And Not CookieConsent("marketing") Then REM The user has opted out of cookies, set strictly necessary cookies only Else If CookieConsent("preferences") Then REM Current user accepts preference cookies Else REM Current user does NOT accept preference cookies End If If CookieConsent("statistics") Then REM Current user accepts statistics cookies Else REM Current user does NOT accept statistics cookies End If If CookieConsent("marketing") Then REM Current user accepts marketing cookies Else REM Current user does NOT accept marketing cookies End If End If End Select Else REM The user has not accepted cookies - set strictly necessary cookies only End If ``` -------------------------------- ### Create Custom Link for Cookie Consent Source: https://www.cookiebot.com/us/developer Use this HTML link to allow users to renew or change their cookie consent without using the default Cookiebot CMP Privacy Trigger. This is an alternative to the recommended trigger for user experience. ```html Renew or change your cookie consent ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.