Jump to content

Cookie Consent with filter function and page cache


Daniel.de

Recommended Posts

Hi there,

I try to use the developement filter "Cookie Consent" from documentation:

function disable_cookie_consent_features($consent)
{
   $cookieName = 'cookieconsent_status';
 
   if ( !isset($_COOKIE[$cookieName]) || ( isset($_COOKIE[$cookieName]) && $_COOKIE[$cookieName] !== 'dismiss' ) )
   {
      $consent = false;
   }
 
   return $consent;
}
 
Clickfwd\Hook\Filter::add('cookie_consent', 'disable_cookie_consent_features', 10);

This works fine until I activate my page cache system. Is there a way to combine this php code with JQuery like:

<script>
  
 jQuery(function ($test) {
	 
	 var cookievalue = Cookies.get("cookie_consent");
	 var marketing_cookie = 'marketing":false';
	

if (cookievalue == null) {
	
     echo '<?php $consent = false;return $consent; ?>';
} else {
	
    console.log('Klaro existiert');
	if(cookievalue.indexOf(marketing_cookie) != -1) {
   echo '<?php $consent = false;return $consent; ?>';
} else {

  console.log('test2');
 
};
} 
	
 });
</script>

In this way the script could load if cache is activated, also, isn't it? Maybe someone has an idea.

Best regards,

Daniel

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...