Only load the banner on user interaction

Have more questions? Submit a request

Some users complain regarding the cookie banner making issues in Pagespeed dev for example, one way might be to fix it is to only execute the banner when the user interacts with the website. You do need to make sure the banner still loads when the scanner visits the site.

Here is the javascript, don't forget to put <script> tags when using it:

 (function() {
    var scriptLoaded = false;

    function loadScript() {
        if (scriptLoaded) return;
        scriptLoaded = true;

        var script = document.createElement('script');
        script.src = 'Add your CookieFirst consent.js url here';

    // Check user agent
    if (navigator.userAgent.indexOf('CookieCheck') !== -1) {
    } else {
        // Setup event listeners for user interactions
        document.addEventListener('click', loadScript, { once: true });
        document.addEventListener('scroll', loadScript, { once: true, passive: true });

Articles in this section

Was this article helpful?
0 out of 0 found this helpful