I have a NextJS site and recently implemented CookieBot. The CookieBot seems to be blocking the dynamically generated NextJs scripts before the cookies are accepted. When I add data-blockingmode=" manual" to the cookiebot script, it works fine. I want to add the data-cookieconsent='ignore' attribute to dynamically generated scripts so it doesn't block them.

I am not exactly sure how can I pass that attribute to dynamically Nextjs scripts. Also, if there is a fix that can be made from a CookieBot, happy to learn about that as well.

Also, I am not sure about the consequences of changing data-blockingmode="auto" to manual.

Below is the file _document.js


import React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';

class appDoc extends Document {
    static async getInitialProps(ctx) {
        const initialProps = await Document.getInitialProps(ctx);
        return { ...initialProps };
    }

    render() {
    
        return (
            <Html>
                <Head>
                    <script
                        id='Cookiebot'
                        src='https://consent.cookiebot.com/uc.js'
                        data-cbid='id'
                        data-blockingmode='auto'
                        type='text/javascript'
                    ></script>
                    <script
                        data-cookieconsent='ignore'
                        dangerouslySetInnerHTML={{
                            __html: `window.dataLayer = window.dataLayer || [];
                                            function gtag() {
                                                dataLayer.push(arguments)
                                            }
                                            gtag("consent", "default", {
                                                ad_storage: "denied",
                                                analytics_storage: "denied",
                                                wait_for_update: 500,
                                            });
                                            gtag("set", "ads_data_redaction", true);`
                        }}
                    ></script>
                    <script
                        data-cookieconsent='ignore'
                        dangerouslySetInnerHTML={{
                            __html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
                            new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
                            j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
                            'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
                        })(window,document,'script','dataLayer','GTM-XXXXX');`
                        }}
                    ></script>

            
                    <meta name='google-site-verification' content='XXXXXX' />
                </Head>
                
                <body>
                    <Main />
                    <NextScript />
            
                    {/* !-- Google Tag Manager (noscript) --> */}
                    <noscript>
                        <iframe
                            src='https://www.googletagmanager.com/ns.html?id=GTM-xxxxxx'
                            height='0'
                            width='0'
                            style={{ display: 'none', visibility: 'hidden' }}
                        ></iframe>
                    </noscript>
                    {/* <!-- End Google Tag Manager (noscript) --> */}
                </body>
            </Html>
        );
    }
}

export default appDoc;

0

There are 0 answers