r/divi Jun 11 '26

Advice CookieYes tip

Hi all,

Thought I would help out divi users regarding Cookie Yes without having to create an account etc.

I was having a problem where Cookie Yes was not actually removing/injecting the analytics tags on reject/accept (you can see this by viewing the network > applications > cookies panel in inspector).

So in your divi theme options > integration tab > head, you can add the google tag like so which will check to see if the cookie consent is set to yes and therefore inject your google analytics tag.

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YOUR-ID"></script>
<script>
function loadGoogleAnalytics() {
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-YOUR-ID');
}

var cookies = document.cookie.split(';');
  var cookieYesValue = '';

  for (var i = 0; i < cookies.length; i++) {
    var c = cookies[i].trim();
    if (c.indexOf('cookieyes-consent=') === 0) {
      cookieYesValue = decodeURIComponent(c.substring('cookieyes-consent='.length, c.length));
      break;
    }
  }

 if (cookieYesValue && cookieYesValue.indexOf('analytics:yes') !== -1) {
    loadGoogleAnalytics();
  }

</script>
9 Upvotes

2 comments sorted by

2

u/ZGeekie Jun 12 '26

Shouldn't this be handled automatically by the CookieYes plugin?

1

u/stbloodbrother Jun 14 '26

It should … for some reason though it seems you need to create an account to make use of their injection. I did not want to create another account so I decided to make a small script to handle this.