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.
The last approach completely disables the ad-display in case the user clicks on reject. Alternatively, it is possible to show non-personalized ads while disabling ad personalization and tracking. To achieve this, you need to modify the GlowCookies configuration script to control the ad loading behavior based on user consent. Here's the correct approach:
Load the Google AdSense script only after the user has interacted with the GlowCookies banner.
Update the GlowCookies configuration script to load a custom script based on the user's consent. This custom script will configure adsbygoogle to request non-personalized ads if the user rejects cookies and personalized ads if the user accepts cookies.
<script src="https://cdn.jsdelivr.net/gh/manucaralmo/GlowCookies@3.1.7/src/glowCookies.min.js"></script>
<script>
function loadAdSenseScript() {
var script = document.createElement('script');
script.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-YOUR_PUBLISHER_ID';
script.setAttribute('crossorigin', 'anonymous');
script.async = true;
document.head.appendChild(script);
}
function setNonPersonalizedAds() {
loadAdSenseScript();
(adsbygoogle = window.adsbygoogle || []).requestNonPersonalizedAds = 1;
}
function setPersonalizedAds() {
loadAdSenseScript();
(adsbygoogle = window.adsbygoogle || []).requestNonPersonalizedAds = 0;
}
glowCookies.start('en', {
style: 1,
analytics: 'G-FH87DE17XF',
facebookPixel: '990955817632355',
policyLink: 'https://link-to-your-policy.com',
acceptedCallback: setPersonalizedAds,
rejectedCallback: setNonPersonalizedAds
});
</script>
Replace YOUR_PUBLISHER_ID
with your actual Google AdSense publisher ID.
With this setup, ads will not be displayed until the user interacts with the GlowCookies banner. If the user rejects cookies, only non-personalized ads will be shown without tracking. If the user accepts cookies, personalized ads and tracking scripts will be activated.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-04-24 01:01:08 +0000
Seen: 7 times
Last updated: Apr 24
Can I change the message from the GlowCookies banner in the Configuration?
How can cookies be set in Next.js while using Node.js (Express) as the backend?
How can we bring googlesheets data into a pyspark dataframe?
When running a dataset, Google Collab indicates that the RunTime is disconnected.
Why does the app shut down when switching to the Google Maps section in a Flutter application?
Can you rephrase this query: Google Search Console - Error in locating (404)?
What does "Read timed out" mean in relation to a Batch Request in the Google Calendar API?
What should I do if I have forgotten my account to create a Google cloud bucket?