Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

o use GlowCookies with Google AdSense, you need to modify the GlowCookies configuration script to load the Google AdSense script only after the user has accepted cookies. Here's how to do it:

First, remove the default Google AdSense script from your HTML file if you've already added it. You will include it later within the GlowCookies configuration.

Update the GlowCookies configuration script with the customScript parameter. Add the Google AdSense script as a custom script that will only load after the user has accepted cookies.

<script src="https://cdn.jsdelivr.net/gh/manucaralmo/GlowCookies@3.1.7/src/glowCookies.min.js"></script>
<script>
    glowCookies.start('en', { 
        style: 1,
        analytics: 'G-FH87DE17XF', 
        facebookPixel: '990955817632355',
        policyLink: 'https://link-to-your-policy.com',
        customScript: [
            { 
                type: 'src', 
                position: 'head', 
                content: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-YOUR_PUBLISHER_ID', 
                crossorigin: 'anonymous' 
            },
            { 
                type: 'custom', 
                position: 'body', 
                content: `
                    (adsbygoogle = window.adsbygoogle || []).push({
                        google_ad_client: "ca-pub-YOUR_PUBLISHER_ID",
                        enable_page_level_ads: true
                    });
                ` 
            }
        ]
    });
</script>

Replace YOUR_PUBLISHER_ID with your actual Google AdSense publisher ID.

This configuration will load the Google AdSense script only after the user has accepted cookies. This way, you comply with the GDPR and other privacy regulations when using Google AdSense with GlowCookies.