a-digital / cookie-consent-banner

Add a configurable cookie consent banner to the website.
MIT License
11 stars 14 forks source link

Plugin No Longer Firing on Craft 3 Site #9

Closed ColinTravis closed 5 years ago

ColinTravis commented 5 years ago

The plugin is fully configured, the .min.js is loading in from a network call, but the banner doesn't appear. I've viewed in incognito and from another browser to test. Are there any logs I can give you to help troubleshooting?

mark-adigital commented 5 years ago

Hmm, that's a weird one. Is cookieconsent.min.css also being loaded? Also, if you do a find in the DOM inspector for 'cookieconsent', can you see the <div> tag and JS that should be initialising the banner?

I did some digging and found a registered script file can be overwritten if a key is not supplied, so I've just updated the plugin and published a new release in case this was the issue as even if it's not, it was probably worth doing!

ColinTravis commented 5 years ago

Looks like the cookieconsent.min.js is being loaded in, as well as the DOM global snippet. The CSS is being loaded in through that snippet, but it appears the snippet is commented out. I tried the version you dropped yesterday, but it hasn't improved. I wouldn't doubt that it might be some plugins clashing, but I'm not sure which one could be. If need be, I could drop a list of all the currently installed ones.

mark-adigital commented 5 years ago

It does sound like a plugin conflict - that was my thinking with adding the key too in case some other plugin was overwriting the snippet.

You can list the plugins and I'll take a look, but to be honest the cookie banner is really pretty simple, and if the code it generates is being commented out I'm inclined to say the issue may be in some other plugin so I may be limited as to what I can do about it.

ColinTravis commented 5 years ago

Interesting, so the way I noticed the bar being injected, it was intersecting a comment from the Google Tags manager global snippet. Because of the intersection, the cookie bar was commenting itself out. This is the comment I have in my main template layout:

  <!-- 
  Start of global snippet: Please do not remove
  Place this snippet between the <head> and </head> tags on every page of your site.
  -->

What seems to be happening is the cookie bar is injecting directly before the </ of the second, commented out head tag, thus being inside a comment. Removing the brackets (escaping the characters didn't work) displays the cookie bar again.

Admittedly, the comment isn't required, and is no longer included on the newer GTM tag but an interesting find.

mark-adigital commented 5 years ago

Ah - that makes sense because I'm using the register script method to include the snippet in the head, and I guess as your comment includes the text <head> and </head> it causes the detection of where to inject that snippet to be thrown off. I'll be honest - I'm not sure quite where Craft ends and underlying Yii code begins at this point, but it looks like the issue lies in the core renderHeadHtml() method.

It's a pretty niche problem, but would be an issue to open with them I guess. I could update the plugin to inject the snippet in the <body> instead, but that could cause similar issues if anyone happens to have a comment with a closing </body> tag in it! In the short term, are you happy to run with the amended comment and I can mark this issue closed?