Wednesday 16 February 2022

Blogger EU Cookie Message Missing Problem & Solution

My EU Cookie Message Disappeared From My Site - How To Get It Back

By Strictly-Software

I had a bit of a weird experience recently, I found out, only from Google informing me, that for some reason one of my Blogger sites was not showing the EU Cookie Notice that should appear on all Blogger sites if in a European country where "Consent to use Cookies", is required by all website users.

It used to show, and my other blogger sites were still working and in fact, on my own PC, it was still showing the correct message e.g:

"This site uses cookies from Google to deliver its services and to analyse traffic. Your IP address and user agent are shared with Google, together with performance and security metrics, to ensure quality of service, generate usage statistics and to detect and address abuse."

However, when I viewed the site Google had told me about on another PC this was not appearing for some reason. 

I cleared all the cookies, path, domain, and session using the Web Extension called "Web Developer Toolbar", such as this Chrome version. After installing it, a grey cog appears in your toolbar if you fix it to. 

It is really helpful for turning password fields into text, if you want to see what you are typing, or need to see a Browser stored password in the field, or as needed in this instance, for deleting all kinds of Cookies. So after deleting all the Cookies, I refreshed the page and but the EU Cookie Message still didn't show.

Fixing Blogger Cookie Notice Not Showing

If you view the source of a blogger site that is showing the EU Cookie message, then you should find the following code in your source, not generated source, but the standard "View Source" options when you right-click on the page and view the context menu.

The following code should be just above the footer where all your widget scripts are loaded. Notice that I put some HTML comments above my version of the code so I could easily identify it from Bloggers version in the DOM when viewing the source. Why do this if Bloggers code is not in the source anyway? Wait and see.

<!-- this is my code as bloggers only appear in the source sometimes -->
<script defer='' src='/js/cookienotice.js'></script>
 document.addEventListener('DOMContentLoaded', function(event) {
      window.cookieChoices && cookieChoices.showCookieConsentBar && cookieChoices.showCookieConsentBar(
          (window.cookieOptions && cookieOptions.msg) || 'This site uses cookies from Google to deliver its services and to analyse traffic. Your IP address and user agent are shared with Google, together with performance and security metrics, to ensure quality of service, generate usage statistics and to detect and address abuse.',
          (window.cookieOptions && cookieOptions.close) || 'Ok',
          (window.cookieOptions && cookieOptions.learn) || 'Learn more',
          (window.cookieOptions && || '');

So to fix the issue, copy the code out of the page and then go to your layout tool in Blogger. Add a widget at the bottom if no JavaScript/Text widget already exists and copy the code into it.

Now the odd thing is that as soon as I saved the widget and then my blogger site. I went to the website having issues and viewed the source code. When I did I saw that not only was my version of the code was in the HTML, but somehow this had put Bloggers own version back into the HTML as well!

Why this would do that I have no idea. However, it meant that I now had two lots of the same script being loaded and 2 lots of the EU Cookie code that shows the DIV and the options for wording appearing in my HTML.

The good thing though, is that this did not cause a problem for my site. I found by adding that code into a widget at the bottom of my page above Bloggers magically re-appearing code, that it did NOT cause the message to appear twice, but also that when I removed my own version of the code, the Blogger version remained.

Also even though I have put in a version of the Blogger code that uses English sentences into the HTML when I use a Proxy or VPN to visit a European country such as Germany, the wording appears in German.

I suspect that my code runs first as it's first in the DOM, then the Google code runs, overwriting my DIV with their DIV and of course the correct wording for the country we are in.

So as I thought everything was working, I removed my own code and saved the site. I then went to it, deleted path, domain, and session cookies, and then refreshed the page again and saw the blogger cookie code running okay. When viewing the source I could see that my code had gone but the blogger code was now still in the HTML, whereas it wasn't before.


After a few hours when I came back to the computer which had not been showing the message and I re-checked by clearing all cookies (path, domain and session), and saw that Bloggers code had disappeared again, and the message was now not showing again!

Why this has happened I do not know as I had not re-saved the Blogger site in question during the time away so I have no idea what caused the Blogger EU Code to disappear again

There really should be an option in settings to force the Cookie compliance code to be inserted but as there isn't the answer seems to be to just leave your version of the cookie code in the HTML source in a widget at the bottom of the layout.

Why this works without causing issues I have no idea and it sounds like a bodge which it is, but as I cannot find any real answers to this problem online, or in Googles KB, I had to come up with a solution that worked to comply with Google's request and this seems to do it.

So the fact that when you have two lots of the same code in your HTML does NOT cause the message to appear twice is a good thing. This means that even if the original code re-appears then you are okay, and if it doesn't then your own code, which is a direct copy of the blogger code, runs instead. 

Also as your code runs first, if it is causing Bloggers code to also re-appear in the HTML then that will run afterwards ensuring the correct European language is shown in the message.

You can view the JavaScript which is loaded in by Blogger by just appending /js/cookienotice.js to any blogger site e.g this one, You can then see the functions and HTML they use to show the DIV. You can also see at the top the ID's and Classes they put on the Cookie Message DIV.

So if you want to check which version of the EU Cookie code is running when both sets of JavaScript exist, you could add a bit of code underneath that checks for the Cookie DIV on display, and add some CSS to target cookieChoicesInfo, which is the ID of the DIV that is shown and you could change the background colour of the DIV to see if it is your DIV or Bloggers DIV that appears.

For example, you could put this under your JavaScript code to change the background colour of the DIV with the following code.

	background-color: green !important;

Obviously green is a horrible colour for a background, but it easily stands out. When I did this I saw a Green DIV appear with the message in the correct language displayed, despite my EU options having English as the language for all the wording. 

This is because our code to load the script, and the cookie options into the page runs first, before any Blogger code that appears lower down in the HTML / DOM. When that Blogger code does run, it overwrites the DIV and the wording in the correct European language.

If you right-click on the DIV and choose "inspect" then the Developer Console will appear and you will be able to see that your style to change the background colour is being used on the Cookie message DIV. 

As it's a CSS style block with !important after the style, when the Blogger code overwrites the DIV and wording, the style for the background colour of the DIV is still being determined by our CSS Style block.

So the answer if your EU Cookie Compliance Message disappears is to add your own copy of their code into the site through a widget. 

This shouldn't cause any problems due to any duplicate DIV overwriting your DIV and if it disappears again then at least your version remains.

I just don't understand two things.

1. Why did the Cookie code disappear in the first place?

2. Why did the Blogger code re-appear when I added my own version of Bloggers own EU Cookie message code into the HTML and then why did it dissapear again a couple of hours? 

If anyone can answer these questions then please let me know. A search inside Googles Adsense site does not reveal any useful answers at all.

People just suggest adding query strings to your URL to force it to appear which is no good if your site is linked to from various Search Engines and other sites. Or to just delete all the cookies and refresh the page. 

These are two useless suggestions, and the only thing that seems to work for me is the solution I came up with above. So if you have the same problem try this solution.

By Strictly-Software


John said...

Thanks for this, I had the same problem and could not find any help online or in Google apart from "clear your cookies and refresh the page", which obviously I did and it didn't help. So thanks!

Dave said...

Thanks, I needed this, would still like to know why the EU cookie message disappeared in the first place and also why adding duplicate code in brings it back. Very odd server logic that outputs the DOM if you ask me,

Danny Steel said...

That's a very weird issue, Blogger should be controlling the HTML that you can't with the Layout Editor, and putting the Cookie JavaScript into the HTML automatically, I can't think without seeing their server side code why it would be there sometimes and not others. Surely now that you have added their code in yourself their BOT will just be able to search the HTML source for the /js/cookienotice.js SCRIPT and see that you have added the cookie object settings yourself, even if it appears alongsisde another copy, and everything should be okay?

Rob Reid said...

I don't know either and to further complicate things, this morning I had another email from Google saying that I was not complying with their GDPR (Cookie Consent), message for the same site on the 18th, 2 days after I thought I had fixed it and wrote this article.

I sent them a link to this post and said that I had copied their own code into a widget but as it was a GOOGLE BLOGGER site, surely it was up to them to ensure that the cookie consent code was inserted into the HTML by the webserver and not me.

I have no control over their server-side code and have no idea why their BOT cannot see in the HTML source that I have inserted a SCRIPT reference to that /js/cookienotice.js file as well as the object that sets the message and button wording.

Therefore I have no idea what is going on as every time I clear the cookies the message appears, and when my own code is in the DOM, their code also appears in it which means the correct language is used when viewing the page from another country.

So I really hope they can come up with a reason why this is happening and if I get one I will definitely pass it on as it seems that it is not just me that has had this problem from searching the web and Googles own Adsense Knowledge Base.

Danny Steel said...

Tes definitley let me know what Google says.

In fact it's amazing just the fact that you actually got a response from a real human being from Google as usually all you get are useless KB pages that don't help. To get a real life human from Google to respond to your email is beyond words, in fact I cannot believe it. I have tried and tried for years to speak to a real person from Google with no luck for various issues.

I think you should ask whoever it was to pass one of their own "I'm not a robot" tests just to prove they are real LOL!!!!

Rob Reid said...

LOL You don't have to tell me, I've wanted to speak to a real person at Google so many times in the past and just been fobbed off with auto-response emails or KB articles that were NOT helpful or sent to a Google community for help with a situation when all I wanted was a quick 5 minutes with a real human being. I would pay a mint for a direct phone no to the nearest Google tech support centre - if anyone knows it please post it here!!!

Danny Steel said...

Have Google got back to you about the magically disappearing and reappearing code that they control to show the EU Cookie message yet?

Rob Reid said...

No not yet, hopefully, they will, and that email wasn't just sent from an automated account pretending to be from a human, you never know nowadays. Would be easy enough to do.

I hope they find out why Blogger is removing the code OR why they cannot see that I am putting their code into the DOM in a widget which is acting as a replacement for when their code is not in the DOM.

Also, I hope that when both my code and their code is BOTH in the DOM, it doesn't matter as my code runs 1st, then their code runs and if the user is in a different country then the language of the message gets changed with no-one noticing anything as they are just overwriting my message instantly with the correct language for the user.

I could write them a BOT if they needed one just to go round Blogger sites and check whether the cookie message is in the HTML it wouldn't take much to do, and it should be all the non-blogger sites using AdSense that is the problem, not Blogger sites, as they control the server-side code!

Maybe there is a bug in their code that removes the message sometimes, but if it is inserted by the server as it looks to be (e.g not JavaScript adding another piece of JavaScript client-side), then a simple BOT would just need to read in the HTML Source and look for that /js/cookienotice.js fule and mention of the properties that need to be set.

So if they need to hire someone :) Just ask for my digits...