Skip to main content

Event order

Comments

5 comments

  • Hey Webmaster,

    As you said the deployment code from Qualtircs Site Intercept is asynchronous. Normally it is sufficient to mark up a script tag with

    <script type="text/plain" data-cookieconsent="marketing">

    however, in the case with Qualtircs Site Intercept it won't work, because the script is executed after the site has loaded (window.onload) - the problem is, that Cookiebot executes after the event, which means we need to use a callback function. Try something like this:

    <script type="text/javascript">

        function CookiebotCallback_OnLoad() {
            if (Cookiebot.consent.statistics) //you can change this to .marketing .preferences or .necessary depending on what cookies the Qualtircs is loading
            {
                enableQualtircsSiteIntercept();
            }
        }

        function enableQualtircsSiteIntercept() {
           //actual deployment code from Qualtircs Site Intercept
        }

    </script>

    You can check the developer's guide for more info as well.

    Regards,
    Martin

    0
  • Webmaster

    In the developers guide, it says the CookiebotCallback_OnLoad() callback happens when the banner is loaded. However we have it set in Cookiebot to only load the banner for EU countries, so I don't believe this callback is happening for countries outside the EU because the banner is never loaded. I did still try the code you posted, didn't work though. I also tried the CookiebotCallback_OnAccept().

     

    Code in question is below.

    <pre><script type="text/javascript">
    (function () {
    var g = function (e, h, f, g) {
    this.get = function (a) { for (var a = a + "=", c = document.cookie.split(";"), b = 0, e = c.length; b < e; b++) { for (var d = c[b]; " " == d.charAt(0) ;) d = d.substring(1, d.length); if (0 == d.indexOf(a)) return d.substring(a.length, d.length) } return null };
    this.set = function (a, c) { var b = "", b = new Date; b.setTime(b.getTime() + 6048E5); b = "; expires=" + b.toGMTString(); document.cookie = a + "=" + c + b + "; path=/; " };
    this.check = function () { var a = this.get(f); if (a) a = a.split(":"); else if (100 != e) "v" == h && (e = Math.random() >= e / 100 ? 0 : 100), a = [h, e, 0], this.set(f, a.join(":")); else return !0; var c = a[1]; if (100 == c) return !0; switch (a[0]) { case "v": return !1; case "r": return c = a[2] % Math.floor(100 / c), a[2]++, this.set(f, a.join(":")), !c } return !0 };
    this.go = function () { if (this.check()) { var a = document.createElement("script"); a.type = "text/javascript"; a.src = g + "&t=" + (new Date()).getTime(); document.body && document.body.appendChild(a) } };
    this.start = function () { var a = this; window.addEventListener ? window.addEventListener("load", function () { a.go() }, !1) : window.attachEvent && window.attachEvent("onload", function () { a.go() }) }
    };
    try {
    (new g(100, "r", "<ID>", "<URL>" + encodeURIComponent(window.location.href))).start()
    } catch (i) { }
    })();
    </script></pre>

     

    0
  • Kenan

    Hi Webmaster,

     

    Non-EU users are treated as having opted in to everything, and the OnAccept callback is called for non-EU users. However, the CookiebotCallback_OnLoad may not be called for these users, as the banner is not loaded. 

     

    You could try something like this:

     

    <script type="text/javascript">

        function CookiebotCallback_OnAccept() {
            if (Cookiebot.consent.statistics) //you can change this to .marketing .preferences or .necessary depending on what cookies the Qualtircs is loading
            {
                enableQualtircsSiteIntercept();
            }
        }

        function enableQualtircsSiteIntercept() {
          
    (function () {
    var g = function (e, h, f, g) {
    this.get = function (a) { for (var a = a + "=", c = document.cookie.split(";"), b = 0, e = c.length; b < e; b++) { for (var d = c[b]; " " == d.charAt(0) ;) d = d.substring(1, d.length); if (0 == d.indexOf(a)) return d.substring(a.length, d.length) } return null };
    this.set = function (a, c) { var b = "", b = new Date; b.setTime(b.getTime() + 6048E5); b = "; expires=" + b.toGMTString(); document.cookie = a + "=" + c + b + "; path=/; " };
    this.check = function () { var a = this.get(f); if (a) a = a.split(":"); else if (100 != e) "v" == h && (e = Math.random() >= e / 100 ? 0 : 100), a = [h, e, 0], this.set(f, a.join(":")); else return !0; var c = a[1]; if (100 == c) return !0; switch (a[0]) { case "v": return !1; case "r": return c = a[2] % Math.floor(100 / c), a[2]++, this.set(f, a.join(":")), !c } return !0 };
    this.go = function () { if (this.check()) { var a = document.createElement("script"); a.type = "text/javascript"; a.src = g + "&t=" + (new Date()).getTime(); document.body && document.body.appendChild(a) } };
    this.start = function () { var a = this; window.addEventListener ? window.addEventListener("load", function () { a.go() }, !1) : window.attachEvent && window.attachEvent("onload", function () { a.go() }) }
    };
    try {
    (new g(100, "r", "<ID>", "<URL>" + encodeURIComponent(window.location.href))).start()
    } catch (i) { }
    })();

        }

    </script>

     

     

     

    0
  • Webmaster

    I've added this code, but it is not working, and I'm not able to hit the break point inside of the callback function, so it seems like its not getting called. Does it matter if the cookiebot script is implemented with Google Tag Manager. Also, does the order of the scripts matter?

    0
  • Kenan

    It does not matter if Cookiebot is implemented with GTM or directly in the template. 

    Can you execute the callback directly from "Developer Tools", e.g. by executing CookiebotCallback_OnAccept manually? Maybe put a console.log("test"); in there.

    Regards

    0

Please sign in to leave a comment.