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

Add consent mode for Google Analytics registry script #243

Open
joachimhviid opened this issue Sep 4, 2024 · 3 comments
Open

Add consent mode for Google Analytics registry script #243

joachimhviid opened this issue Sep 4, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@joachimhviid
Copy link

🆒 Your use case

The current Google Analytics registry does not use consent mode. This is used for communicating the user's consent status to Google.

🆕 The solution you'd like

I would like to have it as part of the options for the registry script so I can easily define default consent settings as well as the option of opting into consent mode v2.

🔍 Alternatives you've considered

Currently I have opted to just copy the registry script and redefine it with an expanded clientInit property since the default consent needs to be set before gtag('js', ...) and gtag('config', ...) is called.

[...]
clientInit: import.meta.server
    ? undefined
    : () => {
        window.dataLayer = window.dataLayer || []
        window.gtag = function () {
          // eslint-disable-next-line prefer-rest-params
          window.dataLayer.push(arguments)
        }

        window.gtag('consent', 'default', {
          ad_user_data: 'denied',
          ad_personalization: 'denied',
          ad_storage: 'denied',
          analytics_storage: 'denied',
        })
        window.gtag('set', { ads_data_redaction: 'true' })

        window.gtag('js', new Date())
        window.gtag('config', website.analytics4Key)
      },
[...]

ℹ️ Additional info

No response

@joachimhviid joachimhviid added the enhancement New feature or request label Sep 4, 2024
@harlan-zw
Copy link
Collaborator

Thoughts @huang-julien, @flashdesignory ?

@flashdesignory
Copy link
Contributor

ah I see... it has to happen before the config gets send, otherwise it wouldn't be a problem.
Seems reasonable to include.

@huang-julien
Copy link
Member

Thanks for the issue ! This is a must have for EU users 😅

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

No branches or pull requests

4 participants