Last active
January 9, 2024 16:45
-
-
Save stefanatcroud/b25174c2a18052db13c912f9dcbce2ff to your computer and use it in GitHub Desktop.
Bespoke CoMo script for US versus non-US visitors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Google Consent Mode V2 --> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag() { dataLayer.push(arguments); } | |
gtag('consent', 'default', { | |
ad_storage: 'denied', | |
ad_user_data: 'denied', | |
ad_personalization: 'denied', | |
analytics_storage: 'denied', | |
wait_for_update: 500 | |
}); | |
gtag('consent', 'default', { | |
ad_storage: 'granted', | |
ad_user_data: 'granted', | |
ad_personalization: 'granted', | |
analytics_storage: 'granted', | |
region: ['US'], | |
wait_for_update: 500 | |
}); | |
gtag('set', 'url_passthrough', true); | |
</script> | |
<!-- End Google Consent Mode V2 --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script will set all relevant consent categories to "denied" for all users except those based in the US. US users will be considered as granting consent by default.
'url_passthrough' will mitigate potential loss of attribution data caused by users navigating the site prior to dismissing the consent banner.