0

So I have google analytics module and eu-cookie-compliance module, both working fine. Now I'm trying to disable google analytics if user didn't give permission for cookies on eu-cokie-compliance. I know that cookie module has javascript function

Drupal.eu_cookie_compliance.hasAgreed()

But I have to check that from php code in google analytics. So when page first load google analytics will be disabled.

Any ideas how to make it work?

<?php 
$cookie=$_COOKIE['cookie-agreed-sl'];
if($cookie==1 || $cookie==2)return true;
else return false;

?>

So i added that code to google analytics code but it always returnss false so google analytics cookie is newer set. I tried that code in some php file and there it works. How to fix it?

4

1 回答 1

1

The eu_cookie_compliance logic can be found in the javascript file: js/eu_cookie_compliance.js contains eu_cookie_compliance_get_settings:

Drupal.eu_cookie_compliance.setStatus = function(status) {
    var date = new Date();
    date.setDate(date.getDate() + 100);
    document.cookie = "cookie-agreed-"+Drupal.settings.eu_cookie_compliance.popup_language + "="+status+";expires=" + date.toUTCString() + ";path=" + Drupal.settings.basePath;
}

So you have to get this cookie using php.

于 2013-05-15T10:22:29.463 回答