Hi

I did have CookieHub installed on the website but the latetst scan says it cannot detect an installation.

I can't remember how I installed it last time (2+ years ago?).

The code I need in the header is:
<script src="https://cdn.cookiehub.eu/c2/21a70f05.js"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
var cpm = {};
window.cookiehub.load(cpm);
});
</script>
 

Can someone point me in the right direction please?

 

Comments

Need to find a place where the code is located or place the code?

If the second,

create a custom block /admin/structure/block

paste the code into it,

place the block anywhere on the page /admin/structure/layouts/manage/default

(I think footer is more appropriate).

If the first, see the source code.

It would be nice to find the code if it still exists but I'm assuming it got overwritten by a system update.

Placement. CookieHub says:
Paste this code to your website above all other scripts in the <head> section.

I have created the block and placed it in the header section of the default layout (Harris Flexible) above the other blocks and saved the layout. Reloading the page and checking the page source, I cannot find the cookie script.

Perhaps I'm misunderstanding.?

 

 

If you used the Raw HTML format to enter the code, correct Layout, you may need to clear the cache

/admin/config/development/performance

and everything should be fine.

Use the browser developer tool (F12) to find your block on the page and check its content.

You can also insert scripts directly into the PHP page template, but in the case of custom blocks they are easier to manage, given that they do not have to be inserted into the HEAD, as the “vendor” insists.

I have a similar situation with web-stat, which requires a code snippet to be loaded by every page.  Let's use that as an example for you to follow:

A)  I created a new block called "Web Stat Block"
B)  I placed my Web-Stat code in the "Web Stat Block"
C)  I located the "Web Stat Block" on the page (Footer)
D)  I set the visibility for the "Web Stat Block"

How To Create a New Block Containing Tracking Code

In:

Home » Administration » Structure » Blocks

OR

/admin/structure/block

Click on "+ Add block":

 


1.  Give the block a title (optional)

2.  Give the block a description (compulsory)

3.  Make the Text format of the Block body "PHP code" (use dropdown)

4.  Paste the code for your provider into the Block body:

Here's my example (using Web-Stat):

5.  Set the location of the  block.  

My suggestion is your Footer because scripts prefer to be loaded as late as possible in the page load process, for technical reasons.

6.  Set the visibility of the block.  

My suggestion is all user pages, meaning you should screen out all of the Administration (/admin*) pages.  You may want to fine-tune this setting more.

 

7.  Clear Cache

YES - you should clear your cache after doing anything that affects the configuration of your site, just to be safe, at:

Home » Administration » Configuration » Development » Performance

Or:

/admin/config/development/performance

Cheers,

g.
----