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

docs: Add example for Google Tag Manager's consent mode #751

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

silenzium
Copy link

@silenzium silenzium commented Nov 8, 2024

The script in this example will result in a fine-grained consent experience for the user.

The following services can be toggled separately:

  • ad_storage
  • ad_user_data
  • ad_personalization
  • analytics_storage
  • functionality_storage
  • personalization_storage
  • security_storage

Preview: https://stackblitz.com/edit/stackblitz-starters-pybz8y?file=script.js

Closes #669
Related to #110

Lorenz Haase added 3 commits November 8, 2024 13:05
…ocs/google-consent-mode

# Conflicts:
#	docs/advanced/assets/google-consent-mode.png
#	docs/advanced/google-consent-mode.md
Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cookieconsent-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 14, 2024 10:40am

Copy link

netlify bot commented Nov 8, 2024

Deploy Preview for cookieconsentv3-playground canceled.

Name Link
🔨 Latest commit f99f2f8
🔍 Latest deploy log https://app.netlify.com/sites/cookieconsentv3-playground/deploys/6735d36f1977b000080e46fc

@orkun1675
Copy link

orkun1675 commented Nov 14, 2024

When testing with Google Tag Assistant I noticed two issues with this example:

  1. I believe we need brackets ([, ]) when setting default consent to denied:
// Set default consent to 'denied'
gtag('consent', 'default', {
    [SERVICE_AD_STORAGE]: 'denied',
    [SERVICE_AD_USER_DATA]: 'denied',
    [SERVICE_AD_PERSONALIZATION]: 'denied',
    [SERVICE_ANALYTICS_STORAGE]: 'denied',
    [SERVICE_FUNCTIONALITY_STORAGE]: 'denied',
    [SERVICE_PERSONALIZATION_STORAGE]: 'denied',
});
  1. I got the error "A tag read consent state before a default was set". Do you think the snippet above has to be executed before the following pre-existing code I had in the header?
gtag('js', new Date());	
gtag('config', '{{ site.google_analytics }}');

@silenzium
Copy link
Author

@orkun1675 thx, you are totally right, fixed it.
And point 2 makes sense, try to set defaults before any other dataLayer update. I do this and don't get any errors like you have (also updated the docs about it)

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

Successfully merging this pull request may close these issues.

[Docs]: how to configure google consent mode
2 participants