Skip to main content

Cookiebot and tracking embedded YouTube videos in Google Tag Manager

Comments

2 comments

  • Domain Admin

    Hi! I'm having this same issue did you ever figure out a solution?

    0
  • Pam Hardy

    I submitted a support ticket, and Cookiebot support was able to come up with the following solution for me:

    We've found a way to re-trigger the GTM YouTube check, to make GTM also check the YouTube iframe(s) AFTER Cookiebot changes the 'data-src' to 'src', meaning that GTM will then identify the iframe as a valid YouTube iframe and therefore allow the YouTube trigger to work. 

    Can you try adding this script on your website?: 

       <script>
    window.addEventListener('CookiebotOnAccept', function () {
    var iframes = document.getElementsByTagName('iframe');
    for (var i of iframes)
    for (var a of i.attributes) {
    var t = /data-gtm-yt-inspected-\w+/.exec(a.name);
    if (t) i.removeAttribute(t[0]);
    }})
    </script>

    This will look for the inspection attribute added by GTM, and remove it once valid consent has been loaded from a Cookiebot cookie (either via an existing cookie or by your visitors accepting cookies, thus creating the Cookiebot cookie). This will trigger the GTM YT check to be done again, but this time it will be done after 'data-src' is changed to 'src', if the visitor has consented to the required cookie categories. 

    You should not have to change anything to your existing setup - only add the above code snippet anywhere in your source code (at least I've been able to get it to work both in the <head> section and in the bottom of the <body> section of your website, via local overrides). 

    0

Please sign in to leave a comment.