Skip to content

Google Consent Mode V2 #6

@Ciantic

Description

@Ciantic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions