Solution Parker_SQSP Posted February 28 Solution Share Posted February 28 If you’re using Google Ads on your site, and targeting users in the EEA, you might have received an email from Google suggesting that you implement their consent mode feature. Here is some example code, that I’ve added to my website to integrate consent mode. This enables me to collect a consent choice from my visitor via the website cookie banner, and then send that consent choice to Google. Before you begin: First, you need to enable the website cookie banner, and ensure you’ve selected the “Opt In & Out” banner type. Code: Next, you would go to Website > Website Tools > Code Injection. You could add the following code to your header code injection (removing any existing Google Ads code first): <script async src="https://www.googletagmanager.com/gtag/js?id=AW-{AW-ID}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('consent', 'default', { 'ad_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied' }); gtag('js', new Date()); gtag('config', 'AW-{AW-ID}'); let squarespaceCookies = {}; if (window.getSquarespaceCookies) { squarespaceCookies = window.getSquarespaceCookies(); } const consentValue = squarespaceCookies.marketing === 'accepted' ? 'granted' : 'denied'; const consentObj = { 'ad_storage': consentValue, 'ad_user_data': consentValue, 'ad_personalization': consentValue }; gtag('consent', 'update', consentObj); window.onCookieBannerInteraction = () => { let squarespaceCookies = {}; if (window.getSquarespaceCookies) { squarespaceCookies = window.getSquarespaceCookies(); } const consentValue = squarespaceCookies.marketing === 'accepted' ? 'granted' : 'denied'; const consentObj = { 'ad_storage': consentValue, 'ad_user_data': consentValue, 'ad_personalization': consentValue }; gtag('consent', 'update', consentObj); } </script> Consent mode is a service provided by Google, so for any questions, verification, or testing support, you can reach out to their support team. markjhonson, Aligency, Agsapa and 1 other 3 1 Link to comment
Lisadoessegger Posted March 7 Share Posted March 7 Thank you for this example. I have added not only Google Ads but our entire Google Tag Manager using custom code, could you please also give an example code on how to integrate consent mode with that? Thanks! markjhonson and KIAE 2 Link to comment
KIAE Posted March 13 Share Posted March 13 I have the same enquiry as Lisadoessegger, when using google tag manager what values must be changed? Thank you markjhonson 1 Link to comment
HMTppc Posted March 29 Share Posted March 29 Do I have to update this code to be specific to my Tag Manager? Sorry if sounds like stupid question KIAE and markjhonson 1 1 Link to comment
Alisonsmith12 Posted April 15 Share Posted April 15 <!-- Add this script to your HTML --> <script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('consent', 'default', { ad_storage: 'denied', // Set default consent to deny ad storage analytics_storage: 'denied' // Set default consent to deny analytics storage }); gtag('set', 'ads_data_redaction', true); // Enable ads data redaction gtag('js', new Date()); gtag('config', 'GA_MEASUREMENT_ID'); </script> Replace GA_MEASUREMENT_ID with your actual Google Analytics Measurement ID. This code sets the default consent for ad storage and analytics storage to denied and enables ads data redaction. It integrates with Google Ads by ensuring that ads data is not stored or used for users who have not provided consent. KIAE 1 Link to comment
KIAE Posted April 16 Share Posted April 16 Thank you @Alisonsmith12 for helping us to configure google tag manager with google consent mode. Excuse my ignorance, but why should we use The google Analytics measurement ID (G-XXXXXX) instead of the google tag manager (GTM-XXXX). Should this code replace the goggle tag manager code injection or it should go above or beneath. <!-- Google Tag Manager --> <script>(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> <!-- End Google Tag Manager --> Thank you Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment