Add Google Script always on all users, even before they have accepted any cookies:
<script>
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
With deny on all storages. Then Google can collect s### on users who haven't accepted anything.
When clicking a category from consent dialog we can call these functions:
<!-- Create one update function for each consent parameter -->
<script>
function consentGrantedAdStorage() {
gtag('consent', 'update', {
'ad_storage': 'granted'
});
}
</script>
Not a fan, but SEO-snakes are starting to sell this to customers.
Taken from Google's Consent Mode V2 documentation
It works like this:
With deny on all storages. Then Google can collect s### on users who haven't accepted anything.
Allowed properties:
ad_storage
,analytics_storage
,ad_user_data
,ad_personalization
Allowed values:granted
ordenied