I'm having difficulty configuring eu_cookie_compliance with multiple categories on a website with Google Analytics tracking. The GA tracking depends on selection of one of the categories.

When the category 'analytics' is enabled, google analytics cookies should be allowed and vice versa.

This comment in a thread for google_analytics shows how to implement the hasAgreed() check within the google_analytics module; in the 'Code Snippet (before)' field:

document.addEventListener('DOMContentLoaded', function(){
    if (!Drupal.eu_cookie_compliance.hasAgreed()) {
        window['ga-disable-UA-0000000-00'] = true;

and in the 'Code Snippet (after)' field:


several others in the thread have confirmed that this works for them. In my case however, google analytics is never triggered.

I added the following before the 'if' statement to debug it:

console.log("General: " + Drupal.eu_cookie_compliance.hasAgreed());
console.log("Analytics: " + Drupal.eu_cookie_compliance.hasAgreed('analytics'));

The console shows false for both of the above, no matter what I select, and the google analytics is never triggered.

What could I be doing wrong?


As far as I know, it is not yet possible to activate individual 3rd party services with the EU Cookie compliance module. An update is planned, the concept will be completely revised.

I would recommend using the module "COOKiES Consent Management" https://www.drupal.org/project/cookies, which supports various 3rd party integration modules out-of-the-box, such as https://www.drupal.org/project/google_analytics is supported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.