-
Notifications
You must be signed in to change notification settings - Fork 286
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
Avoid enqueuing duplicate consent
update
commands on page load.
#8387
Labels
Comments
techanvil
added
P2
Low priority
Type: Enhancement
Improvement of an existing feature
labels
Mar 12, 2024
AC ✔️ |
IB ✔️, but the estimate is too high, i'll update it to 3. |
7 tasks
18 tasks
QA Update ✅
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Feature Description
At present, when using Complianz for the cookie banner, two duplicate
consent
update
commands are enqueued on page load:This is because we enqueue the
update
command in response to thewp_consent_type_defined
event as well as conditionally on page load viaDOMContentLoaded
ifwindow.waitfor_consent_hook
is not set. This approach roughly follows the example of the WP Consent API integration example plugin.site-kit-wp/includes/Core/Consent_Mode/Consent_Mode.php
Lines 157 to 165 in fe57e17
Complianz always fires the
wp_consent_type_defined
event, but it only defineswaitfor_consent_hook
when Geo IP is enabled (which is only available in the paid version).It's possible the same could apply to other CMPs too, although Complianz is the only one we've seen so far which dispatches the
wp_consent_type_defined
event.We should consider whether to avoid allowing duplicate
consent
update
commands to be queued in this manner; it's essentially harmless, but it would be nice to reduce clutter in thedataLayer
array.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
consent
update
command should be queued regardless of if thewp_consent_type_defined
event is called.Implementation Brief
The goal here is to only trigger the consent update if any of the consent settings have changed.
includes/Core/Consent_Mode/Consent_Mode.php
:window._googlesitekitConsents
.updateGrantedConsent
function:Object.find
to comparewindow._googlesitekitConsents
withconsentParameters
, if any keys are found to mismatch, then continue to call gtag, if all keys match, do not call gtag.window._googlesitekitConsents
to the value ofconsentParameters
.Test Coverage
assets/js/consent-mode/consent-mode.test.js
to confirm the update command will not be send twice in the above case.QA Brief
Changelog entry
The text was updated successfully, but these errors were encountered: