CookieWall.NET

Cookies Settings
// See https://www.brainsum.com/modules/custom/nbs_cookie_consent/js/cookieconsent_config.js?v=1.1 for examples
class CookieWall {
    constructor() {
        this.getRemoteCookie();
    }
    getRemoteCookie() {
        var xhttp2 = new XMLHttpRequest();
        var self = this;
        xhttp2.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
                if (xhttp2.responseText.length > 10) {
                    self.setCookie("cconsent", xhttp2.responseText, 365);
                }
                self.initCookieConsent();
                self.addClickBinding();
            }
        };

        xhttp2.withCredentials = true;
        xhttp2.open("GET", "https://static.cookiewall.net/api/cookie/GetConsentCookie?domain=" + location.origin, true);
        xhttp2.send();
    }
    addClickBinding() {
        var self = this;
        document.getElementById("cconsent-modal").getElementsByTagName("button")[0].addEventListener("click", function () { self.updateRemoteCookie() })
        document.getElementById("cconsent-modal").getElementsByTagName("button")[1].addEventListener("click", function () { self.updateRemoteCookie() })
    }
    updateRemoteCookie() {
        console.log("update cookie");
        var xhttp = new XMLHttpRequest();
        var cval = this.getCookie("cconsent");
        xhttp.withCredentials = true;
        xhttp.open("GET", "https://static.cookiewall.net/api/cookie/UpdateConsentCookie?cookieValue=" + cval + "&domain=" + location.origin, true);
        xhttp.send();
    }
    getCookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }
    setCookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }
    initCookieConsent() {
        window.CookieConsent.init({
            // More link URL on bar
            modalMainTextMoreLink: null,
            // How lond to wait until bar comes up
            barTimeout: 1000,
            // Look and feel
            theme: {
                barColor: '#2C7CBF',
                barTextColor: '#FFF',
                barMainButtonColor: '#FFF',
                barMainButtonTextColor: '#2C7CBF',
                modalMainButtonColor: '#4285F4',
                modalMainButtonTextColor: '#FFF',
            },
            language: {
                // Current language
                current: 'nl',
                locale: {
                    nl: {
                        barMainText: 'Deze website gebruikt cookies, JavaScript en vergelijkbare technologie onder andere om je een ' +
                            'optimale gebruikerservaring te bieden.',
                        barLinkSetting: 'Cookie Instellingen',
                        barBtnAcceptAll: 'Ja, ik accepteer cookies',
                        modalMainTitle: 'Cookie instellingen',
                        modalMainText: 'Cookies kunnen worden gebruikt om deze website advertenties te tonen en artikelen aan te bevelen ' +
                            'die aansluiten bij uw interesses. Cookies kunnen ook worden gebruikt om op sites van derden relevante advertenties te tonen.',
                        modalBtnSave: 'Bewaar huidige instellingen',
                        modalBtnAcceptAll: 'Accepteer alle cookies en sluit',
                        modalAffectedSolutions: 'Website functies:',
                        learnMore: 'Lees meer',
                        on: 'Aan',
                        off: 'Uit',
                    }
                }
            },
            // List all the categories you want to display
            categories: {
                // Unique name
                // This probably will be the default category
                necessary: {
                    // The cookies here are necessary and category cant be turned off.
                    // Wanted config value  will be ignored.
                    needed: true,
                    // The cookies in this category will be let trough.
                    // This probably should be false if not necessary category
                    wanted: true,
                    // If the checkbox is on or off at first run.
                    checked: true,
                    // Language settings for categories
                    language: {
                        locale: {
                            en: {
                                name: 'Strictly Necessary Cookies',
                                description: 'Necessary cookies help make a website more usable by enabling basic functions such as page navigation,'
                                    + ' access to secure areas of the website. The website cannot function properly without these cookies.',
                            },
                            nl: {
                                name: 'Noodzakelijke cookies',
                                description: 'Noodzakelijke cookies helpen een website bruikbaarder te maken, door basisfuncties als paginanavigatie,' +
                                    ' toegang tot beveiligde gedeelten van de website mogelijk te maken. Zonder deze cookies kan de website niet naar behoren werken.',
                            }
                        }
                    }
                },
                preferences: {
                    needed: false,
                    wanted: true,
                    checked: true,
                    language: {
                        locale: {
                            en: {
                                name: 'Preferences',
                                description: 'Preference cookies enable a website to remember information that affects the behavior and design of the website,'
                                    + ' such as your preferred language or the region where you live.',
                            },
                            nl: {
                                name: 'Voorkeuren',
                                description: 'Voorkeurscookies zorgen ervoor dat een website informatie kan onthouden die van invloed is op het gedrag en de '
                                    + 'vormgeving van de website, zoals de taal van uw voorkeur of de regio waar u woont.',
                            }
                        }
                    }
                },
                analytics: {
                    needed: false,
                    wanted: true,
                    checked: true,
                    language: {
                        locale: {
                            en: {
                                name: 'Analytics',
                                description: 'Statistical cookies help website owners understand how visitors use their website by collecting and reporting data anonymously.',
                            },
                            nl: {
                                name: 'Statistieken',
                                description: 'Statistische cookies helpen eigenaren van websites begrijpen hoe bezoekers hun website gebruiken, door anoniem'
                                    + ' gegevens te verzamelen en te rapporteren.',
                            }
                        }
                    }
                },
                marketing: {
                    needed: false,
                    wanted: true,
                    checked: true,
                    language: {
                        locale: {
                            en: {
                                name: 'Marketing',
                                description: 'Marketing cookies are used to track visitors when they visit different websites. Their goal is to display '
                                    + 'advertisements that are tailored and relevant to the individual user. These ads thus become more valuable to '
                                    + 'publishers and third-party advertisers.',
                            },
                            nl: {
                                name: 'Marketing',
                                description: 'Marketingcookies worden gebruikt om bezoekers te volgen wanneer ze verschillende websites bezoeken. Hun '
                                    + 'doel is advertenties weergeven die zijn toegesneden op en relevant zijn voor de individuele gebruiker. Deze advertenties '
                                    + 'worden zo waardevoller voor uitgevers en externe adverteerders.',
                            }
                        }
                    }
                },

            },
            // List actual services here
            services: {
                advertising:
                {
                    category: 'marketing',
                    type: 'script-tag',
                    search: 'advertising',
                    language: {
                        locale:
                        {
                            en: { name: 'Advertising' },
                            nl: { name: 'Advertenties' }
                        }
                    }
                },
                // Unique name
                analytics: {
                    // Existing category Unique name
                    // This example shows how to block Google Analytics
                    category: 'analytics',
                    // Type of blocking to apply here.
                    // This depends on the type of script we are trying to block
                    // Can be: dynamic-script, script-tag, wrapped, localcookie
                    type: 'localcookie',
                    // Only needed if "type: dynamic-script"
                    // The filter will look for this keyword in inserted scipt tags
                    // and block if match found
                    search: 'analytics',
                    // List of known cookie names or Regular expressions matching
                    // cookie names placed by this service.
                    // These willbe removed from current domain and .domain.
                    cookies: [
                        {
                            // Known cookie name.
                            name: '_gid',
                            // Expected cookie domain.
                            domain: `.${window.location.hostname}`
                        },
                        {
                            // Regex matching cookie name.
                            name: /^_ga/,
                            domain: `${window.location.hostname}`
                        },
                        {
                            // Regex matching cookie name.
                            name: /__ut/g,
                            domain: `${window.location.hostname}`
                        }

                    ],
                    language: {
                        locale: {
                            en: {
                                name: 'Google Analytics'
                            },
                            nl: {
                                name: 'Google Analytics'
                            }
                        }
                    }
                }
            }
        });
    }
}

let cw = new CookieWall();