Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Consent Mode V2 #6

Open
Ciantic opened this issue Jun 7, 2024 · 1 comment
Open

Google Consent Mode V2 #6

Ciantic opened this issue Jun 7, 2024 · 1 comment

Comments

@Ciantic
Copy link

Ciantic commented Jun 7, 2024

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:

  1. 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.

  1. 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>

Allowed properties: ad_storage, analytics_storage, ad_user_data, ad_personalization
Allowed values: granted or denied

@ronilaukkarinen
Copy link
Member

This is actually clever. Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants