Hi there,

I have the code as described in http://drupal.org/node/1603622#comment-6098646 and the cookie isn't saved when not accepted, but the cookie doesn't get saved if accepted either.

I tried everything, but somehow nog cookies from Google Analytics!

Any ideas?

Comments

Miszel’s picture

Assigned: Unassigned » Miszel

Are you expecting the cookie to be set right after clicking the accept button or another page (after page reload)?

paardje’s picture

After clicking the accept button (thats the law for a Dutch site)

Miszel’s picture

So you need to use the onclick event:

<script type="text/javascript">
$(document).ready(function() {
  $('.agree-button').click(function() {
    alert("Just accepted.");
  });
  if (Drupal.eu_cookie_compliance.hasAgreed()){
    alert("Accepted earlier");
  }
});
</script>

Let me know if you need any further help.

paardje’s picture

I tried this and just tested it.

After clicking the acceptbutton, no cookies for google Anayltics are set. Although the alert works, but also worked in the other example!

Miszel’s picture

I need to see your code to be bale to help you.

paardje’s picture

The code is exactly as above (or in the other example), but where you have the alert, i have de Google analytics code.

Miszel’s picture

Then it should work. I am not sure how else I can help you without seeing the code.

paardje’s picture

As i said, i tried everything, GA doesn't work.

The latest i even tried

<script type="text/javascript">
  $(document).ready(function() {  
   $('.agree-button').click(function() {
   		        var _gaq = _gaq || [];
     _gaq.push(['_setAccount', 'UA-XXXXX]);
     _gaq.push(['_trackPageview']);

     (function() {
       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
       ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     })();
     });
   if (Drupal.eu_cookie_compliance.hasAgreed()){
     //alert("Yes");
     var _gaq = _gaq || [];
     _gaq.push(['_setAccount', 'UA-XXXXX]);
     _gaq.push(['_trackPageview']);

     (function() {
       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
       ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     })();
   }
 });
</script>
Miszel’s picture

Please try to disable GA as describe at the bottom of this page: https://developers.google.com/analytics/devguides/collection/gajs/

paardje’s picture

Ok i'll try that in the next few days.

Do you know if there is something like this for Google Adsense?

Miszel’s picture

No, I don't but I am sure you can enable/disable adsense conditionally somehow. A couple of google results that may help you:

http://www.mobilefish.com/tutorials/adprograms/adprograms_quickguide_goo...
http://stackoverflow.com/questions/10876924/can-i-make-a-google-ad-displ...

Miszel’s picture

Status: Active » Closed (fixed)
Miszel’s picture

Issue summary: View changes

New info

thestevelavigne’s picture

Issue summary: View changes

When I use:

if (Drupal.eu_cookie_compliance.hasAgreed()){
alert("Accepted earlier");
}

It gets triggered multiple times, almost with every page element load, and the alert shows 4, 5, 6 times.

Is there a way to prevent this?

svenryen’s picture

Hi @Nugg!

Where did you place the script in question?
We have no code calling your scripts, so I have a hard time seeing how we can help :)

rop’s picture

jbjb’s picture

Hi Marcin,

I hope you're well.

I'm having an issue with a client site, on Drupal, and their Google Analytics config. I'm going through a process of elimination to try and determine the cause.

For each page load a new Google Analytics sessions begins / clientID is reset. This breaks all tracking within the site and renders attribution for paid traffic useless.

The client is using the EU Cookie Compliance tool. Is this expected behaviour if the user opts out or ignores the pop up? If the Google Analytics cookie is being deleted, it could cause issues as described above. Is there any case where the tool can be misconfigured and prevent GA from tracking regardless of the option selected in the popup (note, I've tested by ignoring the popup, opting in and opting out but I see the same issue).

Many thanks

J