Big thank you to @Parker_SQSP for the code above.
I've got absolutely no idea when it comes to Javascript but I've adjusted it slightly and could do with someone sense-checking what I've done...
1. Using GTM code instead of Google Ads Tag ID
I guess in @Parker_SQSP's code you're supposed to replace the two AW-{AW-ID}'s with a relevant Google Ads Tag ID? Instead I put my Google Tag Manager GTM container ID, and it still appears to work. Is that to be expected?
2. Adding "analytics_storage"
I noticed that using @Parker_SQSP's code would result in analytics_storage being granted on page load before consent had been given. So I added values for analytics_storage alongside the others in several places throughout the code. And this now appears to work too! Again, is this to be expected? And am I right to want the default behaviour of analytics_storage to be Denied until consent it is given via a cookie banner?
I've been testing it out in Tag Assistant and everything appears to be working correctly. Cookie Consent State (gcs) is set to G100 (No consent) on page load, and switches to G111 (Ads & Analytics have consent) after consent is given.
Here is the butchered code that I have produced...
<script async src="https://www.googletagmanager.com/gtag/js?id=GTM-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied'
});
gtag('js', new Date());
gtag('config', 'GTM-XXXXXXX');
let squarespaceCookies = {};
if (window.getSquarespaceCookies) {
squarespaceCookies = window.getSquarespaceCookies();
}
const consentValue = squarespaceCookies.marketing === 'accepted' ? 'granted' : 'denied';
const consentObj = {
'ad_storage': consentValue,
'analytics_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,
'analytics_storage': consentValue,
'ad_user_data': consentValue,
'ad_personalization': consentValue
};
gtag('consent', 'update', consentObj);
}
</script>
And I don't understand how @Alisonsmith12's code above integrates into this and what it does?