site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Add a Site Health section for consent mode

Open adamdunnage opened this issue 1 year ago • 1 comments

Add a section to the Site Kit Site Health to show if a user has enabled consent mode on their site. If possible, we could also display if Site Kit has detected the WP Consent API.

Sections to add:

  1. Consent mode: enabled/disabled
  2. WP Consent API: Detected/Not detected

Acceptance criteria

  • Site Kit Site Health should show a new field labelled "Consent Mode", with the text "Enabled" or "Disabled" based on whether or not the site has Consent Mode enabled.
  • Site Kit Site Health should show a new field labelled "WP Consent API", with the text "Detected" or "Not detected" based on whether or not the WP Consent API functionality is available on this site.

Implementation Brief

  • [ ] In includes/Core/Site_Health/Debug_Data.php:
    • [ ] Add a new get_consent_mode_fields method. In this method:
      • [ ] It should return an associative multidimensional array with the named keys: consent_mode array consent_api. Each key should have another associative array assigned as its value which should have the named keys: label, value, and debug. The structure should follow as described below:
        • [ ] consent_mode =>
          • [ ] label => Consent Mode (translatable).
          • [ ] value => This should either be Enabled or Disabled (translatable) based on whether Site Kit has Consent Mode enabled.
          • [ ] debug => This should either be enabled or disabled based on whether Site Kit has Consent Mode enabled.
        • [ ] consent_api =>
          • [ ] label => WP Consent API (translatable).
          • [ ] value => This should either be Detected or Not detected (translatable) based on whether WP Consent API functionality is available on the site.
          • [ ] debug => This should either be detected or not-detected based on whether WP Consent API functionality is available on the site.
      • [ ] In order to determine if Site Kit has Consent Mode enabled, instantiate a new instance of the Core\Consent_Mode\Consent_Mode_Settings class passing $this->options to its constructor, and call its is_consent_mode_enabled method.
      • [ ] In order to determine if WP Consent API functionality is available on the site, check if the wp_set_consent function exists (using function_exists).
    • [ ] Update the get_fields method:
      • [ ] Right after the definition of the $fields array, update it by merging the array returned by the get_consent_mode_fields method to it.

Test Coverage

  • [ ] In tests/phpunit/integration/Core/Site_Health/Debug_DataTest.php:
    • [ ] Add a new test case verifying that the debug fields include the new Consent Mode keys with appropriate values.

QA Brief

Changelog entry

adamdunnage avatar Mar 06 '24 08:03 adamdunnage

  • In order to determine if Site Kit has Consent Mode enabled, instantiate a new instance of the Core\Consent_Mode\Consent_Mode_Settings class passing $this->options to its constructor, and call its is_consent_mode_enabled method.

@nfmohit this is not really how it should be done. Instead of creating a new instance, we need to either add a new filter that will allow us to add new fields in the consent class or add a filter that will indicate wether needed settings are enabled.

eugene-manuilov avatar Mar 27 '24 18:03 eugene-manuilov

  • In order to determine if Site Kit has Consent Mode enabled, instantiate a new instance of the Core\Consent_Mode\Consent_Mode_Settings class passing $this->options to its constructor, and call its is_consent_mode_enabled method.

@nfmohit this is not really how it should be done. Instead of creating a new instance, we need to either add a new filter that will allow us to add new fields in the consent class or add a filter that will indicate wether needed settings are enabled.

I've updated the IB to add a new googlesitekit_is_consent_mode_enabled filter. Please let me know if it looks good now, thanks @eugene-manuilov!

nfmohit avatar Apr 02 '24 11:04 nfmohit

I've updated the IB to add a new googlesitekit_is_consent_mode_enabled filter. Please let me know if it looks good now,

Yes, that is better, thanks, @nfmohit. But let's rename it to be googlesitekit_consent_mode_state or googlesitekit_consent_mode_status and make it return either enabled or disabled values that we can use for the debug property.

eugene-manuilov avatar Apr 02 '24 13:04 eugene-manuilov

I've updated the IB to add a new googlesitekit_is_consent_mode_enabled filter. Please let me know if it looks good now,

Yes, that is better, thanks, @nfmohit. But let's rename it to be googlesitekit_consent_mode_state or googlesitekit_consent_mode_status and make it return either enabled or disabled values that we can use for the debug property.

Updated, thanks @eugene-manuilov!

nfmohit avatar Apr 02 '24 17:04 nfmohit

IB ✔️

eugene-manuilov avatar Apr 02 '24 17:04 eugene-manuilov

QA Update: ✅

Verified:

  • The Consent Mode fields appear in the Site health info list.
    • Tested turning on and off Consent Mode and the status changes.
    • Tested activating and deactivating the WP Consent API plugin and the API status changes.
Screenshots

image image image image

wpdarren avatar Apr 08 '24 13:04 wpdarren