Adding a Script to the Beginning of the Page Header
SchweizerSchoggi is trying to add a script for a cookie consent solution provided by consentmanager.net to the beginning of the page header. Despite trying different options in the admin tool, such as HEAD, HEADER, AFTER HEAD, and BODY, the script is not being published in the desired location.
Cocococosti suggests using the script from the Semi-automatic blocking tab, which worked for them. However, SchweizerSchoggi is still experiencing issues with the script being inserted too late.
Cocococosti advises inserting the script in the Head section (Customize => Theme => Edit CSS/HTML => Head) or creating a theme component with the script. However, SchweizerSchoggi reports that neither section works for them.
Cocococosti offers to log into SchweizerSchoggi’s site to investigate further. After doing so, Cocococosti discovers that the issue is due to Content Security Policy blocking the script. Adding the necessary scripts to the content security policy script src site setting resolves the issue.
I need to add a script for an existing cookie consent solution (provided by consentmanager.net).
It has to be placed as the first overall element in the page header.
I’ve tried the different options in the admin tool, in HEAD, HEADER, AFTER HEAD, BODY.
But none of them did work.
Placed in HEAD the script is being published in the middle of the header items, below a bunch of discourse scripts and other stuff. It blocks other custom content (here: Font Awesome icons), no matter which cookie setting I choose, but that’s it.
Placed in HEADER there’s no functionality at all.
Placed n AFTER HEAD I can’t even find the script in the rendered source code.
Placed in BODY (there’s a different script for this location) it’s being published much too late, near the end of the page. But it should go first in the body, if it’s not possible to add the script in the header.
So no success at all implementing my little script.
Can anyone tell me if there is a chance to add a script at the beginning of the head section?
Hello @SchweizerSchoggi I just tested adding a cookie consent banner from consentmanager.net in my site, and it worked when using the script from the Semi-automatic blocking tab.
If you use the other code, it blocks the entire site. You may be able to solve it with some custom JS to insert the script, but it’s easier to just use the other code snippet.
but it’s being inserted too late then. It should be integrated directly after the opeing body tag, but in fact it has been inserted just before the closing body tag.
@SchweizerSchoggi Since you are a hosted customer, I can log into your site and take a look if you wish. Could you send me a PM with the script code please?
After adding the cookie consent script to the theme, I checked the browser’s console and saw multiple scripts from the Cookie consent manager were being blocked due to Content Security Policy. I added those to the content security policy script src site setting and the cookie consent banner is displayed correctly now.