• Resolved Matt Lowe

    (@squelch)


    I’m writing a plugin which will set a whole bunch of arbitrary cookies. On the client side I want to be able to detect whether or not the user has consented to cookies or not before doing so. Is there a function provided by this plugin that I can call to find out whether consent has been given? I had a look at the CLI object exposed by the plugin, but couldn’t see anything in there to say whether cookie consent had been obtained.

Viewing 1 replies (of 1 total)
  • Plugin Author WebToffee

    (@webtoffee)

    Hi @squelch,

    You can use the function wt_cli_is_consent_given() to get the consent status. This function will return “true” if the user has given consent to cookies. Else it will return “false”.

    <script>
    	function wt_cli_is_consent_given() {
    		if (CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME) == 'yes' && CLI_Cookie.read("cookielawinfo-checkbox-non-necessary") == 'yes') {
    			return true;
    		}else {
    			return false;
    		}
    	}
    </script>
Viewing 1 replies (of 1 total)

The topic ‘Detect consent in JavaScript’ is closed to new replies.