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

Avoid enqueuing duplicate consent update commands on page load. #8387

Closed
5 tasks
techanvil opened this issue Mar 12, 2024 · 3 comments
Closed
5 tasks

Avoid enqueuing duplicate consent update commands on page load. #8387

techanvil opened this issue Mar 12, 2024 · 3 comments
Labels
P2 Low priority Team S Issues for Squad 1 Type: Enhancement Improvement of an existing feature

Comments

@techanvil
Copy link
Collaborator

techanvil commented Mar 12, 2024

Feature Description

At present, when using Complianz for the cookie banner, two duplicate consent update commands are enqueued on page load:

image

This is because we enqueue the update command in response to the wp_consent_type_defined event as well as conditionally on page load via DOMContentLoaded if window.waitfor_consent_hook is not set. This approach roughly follows the example of the WP Consent API integration example plugin.

document.addEventListener(
'wp_consent_type_defined',
updateGrantedConsent
);
document.addEventListener( 'DOMContentLoaded', function () {
if ( ! window.waitfor_consent_hook ) {
updateGrantedConsent();
}
} );

Complianz always fires the wp_consent_type_defined event, but it only defines waitfor_consent_hook when Geo IP is enabled (which is only available in the paid version).

image

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 the dataLayer array.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Only one consent update command should be queued regardless of if the wp_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.

  • Update includes/Core/Consent_Mode/Consent_Mode.php:
    • Create a new window variable window._googlesitekitConsents.
    • Update updateGrantedConsent function:
      • Before the gtag call, use Object.find to compare window._googlesitekitConsents with consentParameters, if any keys are found to mismatch, then continue to call gtag, if all keys match, do not call gtag.
      • After the gtag update consent is called, set window._googlesitekitConsents to the value of consentParameters.

Test Coverage

  • Add test coverage to assets/js/consent-mode/consent-mode.test.js to confirm the update command will not be send twice in the above case.

QA Brief

  • Enable Consent Mode in the plugin Admin settings.
  • Install and Activate the WP Consent API plugin.
  • Install and Activate the Complianz plugin.
  • Setup a plugin like GA Debug so you can see events that are triggered.
  • Load a page in an incognito window to simulate a new user visiting the site.
  • Accept permissions in the consent banner.
  • Refresh the page - when the page loads this time, the page should only trigger consent update once.

Changelog entry

  • Update Consent Mode to prevent enqueuing duplicate consent commands on page load.
@techanvil techanvil added P2 Low priority Type: Enhancement Improvement of an existing feature labels Mar 12, 2024
@binnieshah binnieshah added the Next Up Issues to prioritize for definition label Jun 10, 2024
@benbowler benbowler assigned benbowler and unassigned benbowler Jun 10, 2024
@eugene-manuilov eugene-manuilov self-assigned this Jun 12, 2024
@eugene-manuilov
Copy link
Collaborator

AC ✔️

@eugene-manuilov eugene-manuilov removed their assignment Jun 12, 2024
@benbowler benbowler self-assigned this Jun 12, 2024
@binnieshah binnieshah added the Team S Issues for Squad 1 label Jun 14, 2024
@benbowler benbowler removed their assignment Jun 17, 2024
@eugene-manuilov eugene-manuilov self-assigned this Jun 17, 2024
@eugene-manuilov
Copy link
Collaborator

IB ✔️, but the estimate is too high, i'll update it to 3.

@eugene-manuilov eugene-manuilov removed their assignment Jun 17, 2024
@binnieshah binnieshah removed the Next Up Issues to prioritize for definition label Jun 25, 2024
@benbowler benbowler self-assigned this Jul 9, 2024
@benbowler benbowler removed their assignment Jul 10, 2024
@zutigrm zutigrm assigned zutigrm and unassigned zutigrm Jul 10, 2024
@tofumatt tofumatt assigned tofumatt and benbowler and unassigned tofumatt Jul 11, 2024
@benbowler benbowler assigned tofumatt and unassigned benbowler Jul 11, 2024
@tofumatt tofumatt removed their assignment Jul 11, 2024
@mohitwp
Copy link
Collaborator

mohitwp commented Jul 19, 2024

QA Update ✅

  • Tested on dev environment.
  • Verified that on latest environment duplicate consent update commands loads on page load and on dev environment now only one command gets load.
  • Tested using complianz plygin.
  • Tested for both Accept and deny actions.
  • Verified only one consent update command queued regardless of if the wp_consent_type_defined event is called.

Latest environment -

image

Dev environment -

image

image

When user accept the permissions

Recording.1190.mp4

When user deny the permissions

Recording.1191.mp4

@mohitwp mohitwp removed their assignment Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Low priority Team S Issues for Squad 1 Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

8 participants