hasAgreed() is not working anymore as it fails to get cookie_name settings. Cookie consent is set to load in header so I can use hasAgreed() function for google analytic and with new update it is not working anymore. I guess that settings are loaded in Drupal.eu_cookie_compliance.execute function which is once document is ready.

Comments

MrMiso created an issue. See original summary.

svenryen’s picture

Hi @MrMiso. Which version did you upgrade from?

svenryen’s picture

I've added a fix here and I think this should it should fix the issue.

  • svenryen committed 40e7d32 on 7.x-1.x
    Issue #2952912 by svenryen, MrMiso: hasAgreed() not working
    
svenryen’s picture

Status: Active » Fixed
mrmiso’s picture

I was on 7.x-1.17 before update. This will work but it renders cookie name variable useless. If you set cookie name your consent will be saved under that name but hasAgreed() will check on 'cookie-agreed' name as settings aren't available if script is loaded in header. You need to load script in header if you want to use hasAgreed() for lets say google analytic check or any other script you don't want to load until user accept cookie consent.

The correct way would be to load cookie name settings from drupal immediately and not on document ready. With that you won't ever have undefined cookie_name. That is my reasoning but I don't know if it is 100% correct. I was looking into when are actual setting from drupal available/loaded and I think it happens in execute function that is called once and is attached to 'body'. How to load them immediately on script load is beyond my knowledge.

mrmiso’s picture

Status: Fixed » Needs review
svenryen’s picture

Issue summary: View changes
StatusFileSize
new25.78 KB

Hmm.. I see your problem.

When I run `Drupal.eu_cookie_compliance.hasAgreed()` right after the script has loaded, it does indeed fail at getting the cookie name, since Drupal.settings isn't available.

The correct way would be to load cookie name settings from drupal immediately and not on document ready

Do you have any example of how this can be done? EU Cookie Compliance is not reading these values from Drupal, they are output as part of the header, together with other Drupal settings. I might be able to bypass this though and output the cookie name in pure javascript, I'll look into that. Thanks for following up the issue.

svenryen’s picture

If I can recommend an interim solution for you, @MrMiso, can you name your cookie 'cookie-agreed', until we can get this sorted?

svenryen’s picture

Version: 7.x-1.20 » 7.x-1.22
StatusFileSize
new3.78 KB

This patch fixes the issue. Can you help me apply the patch and review, @MrMiso?

  • svenryen committed 393fc68 on 7.x-1.x
    Issue #2952912 by svenryen, MrMiso: hasAgreed() not working
    
svenryen’s picture

Status: Needs review » Fixed

  • svenryen committed 393fc68 on 7.x-2.x
    Issue #2952912 by svenryen, MrMiso: hasAgreed() not working
    
  • svenryen committed 40e7d32 on 7.x-2.x
    Issue #2952912 by svenryen, MrMiso: hasAgreed() not working
    
  • svenryen committed c3b7d25 on 7.x-2.x
    Merge branch '7.x-1.x' into 7.x-2.x
    
    * 7.x-1.x:
    Code style and spelling...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.