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?

 

Accepted answer

Use format "Raw HTML" (without CKEditor) to enter the code.
(/admin/config/content/formats)

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.

Found the first issue: The homepage is a different layout to the default layout.

Edited the block to insert the code in Raw HTML format. Saved block.

Cleared cache.

Reload homepage. Get this:

Looking at page source:

    <p>
   document.addEventListener("DOMContentLoaded", function(event) { var cpm = {}; window.cookiehub.load(cpm); });
</p> 

Seems to have converted it to HTML rather than insert it as Script??

 

Use format "Raw HTML" (without CKEditor) to enter the code.
(/admin/config/content/formats)

Ta Dah!

CookieHub is working again.

Many thanks.

Hi Mike

There are a couple of modules that can do cookie consent support:

The other thing to consider is whether you actually need cookie consent.  I had a quick look at your site but couldn't see anything that actually needs it.  On most of my sites, I make it so that cookie consent is not needed, which is a much better user experience than asking for it when it isn't needed.

Thanks. I'll have a look a bit later. 

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.
----

You are misleading people by giving advice about Drupal 7. This is a Backdrop CMS forum.

I'm in agreement with @Enthusiast here. "PHP code" does not exist as a format in Backdrop and use of a PHP filter is not supported or encouraged in any way.

However, "Raw HTML" is available out of the box and would be perfectly adequate for this purpose. 

Please stick to Backdrop mostly.  I can think of a few scenarios in the forum where referring to Drupal 7 methods will be relevant:

  • Porting site from D7 to Backdrop and comparing behaviour
  • Porting module/theme from D7 to Backdrop and comparing behaviour/appearance
  • Referring to Drupal 7 guides for how to do stuff, but ideally adapting where needed

There may well be others, but please don't include screenshots or guidance from D7 without making it clear that it is from D7.

Confusion indeed. That'll be why I'm not seeing the screenshots that Graham is showing.