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?