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 filter to allow customisation of Consent Mode defaults. #8383

Closed
1 task
techanvil opened this issue Mar 12, 2024 · 5 comments
Closed
1 task

Add filter to allow customisation of Consent Mode defaults. #8383

techanvil opened this issue Mar 12, 2024 · 5 comments
Labels
P1 Medium priority Squad 2 (Team M) Issues for Squad 2 Type: Enhancement Improvement of an existing feature

Comments

@techanvil
Copy link
Collaborator

techanvil commented Mar 12, 2024

Feature Description

At present, we provide the googlesitekit_consent_category_map filter to allow the mapping of CMP consent categories to Consent Mode parameters.

However, we don't provide a filter to allow customising the default consent values that are set. It would be useful to provide a filter so as to allow these defaults to be modified, thus allowing users complete control over the consent mode parameters.

$consent_defaults = array(
'ad_personalization' => 'denied',
'ad_storage' => 'denied',
'ad_user_data' => 'denied',
'analytics_storage' => 'denied',
'regions' => $this->consent_mode_settings->get_regions(),
'wait_for_update' => 500, // Allow 500ms for Consent Management Platforms (CMPs) to update the consent status.
);
$consent_category_map = apply_filters(
'googlesitekit_consent_category_map',
array(
'statistics' => array( 'analytics_storage' ),
'marketing' => array( 'ad_storage', 'ad_user_data', 'ad_personalization' ),
)
);


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

Acceptance criteria

  • A filter named googlesitekit_consent_defaults should be added which allows the default consent parameters to be customised.

Implementation Brief

  • Add googlesitekit_consent_defaults filter for the default settings and pass current array as default value
    $consent_defaults = array(
    'ad_personalization' => 'denied',
    'ad_storage' => 'denied',
    'ad_user_data' => 'denied',
    'analytics_storage' => 'denied',
    'regions' => $this->consent_mode_settings->get_regions(),
    'wait_for_update' => 500, // Allow 500ms for Consent Management Platforms (CMPs) to update the consent status.
    );
    • $consent_defaults = apply_filters( 'googlesitekit_consent_defaults', array(...) );

Test Coverage

  • No updates needed

QA Brief

1. When no filter is added

  • This issue modifies the internal code which which provides the default values for consent mode.
  • Visit the homepage (or any front end page), there should be following snippet available on the page.
gtag( 
  'consent', 
  'default',
  {
    "ad_personalization": "denied",
    "ad_storage": "denied",
    "ad_user_data": "denied",
    "analytics_storage": "denied",
    "region": [
      "AT",
      "BE",
      "BG",
      "CY",
      "CZ",
      "DE",
      "DK",
      "EE",
      "ES",
      "FI",
      "FR",
      "GB",
      "GR",
      "HR",
      "HU",
      "IE",
      "IS",
      "IT",
      "LI",
      "LT",
      "LU",
      "LV",
      "MT",
      "NL",
      "NO",
      "PL",
      "PT",
      "RO",
      "SE",
      "SI",
      "SK"
    ],
    "wait_for_update": 500
  }
);

2. When filter is added

  • Create a file named consent-mode-defaults-filter.php inside wp-content/mu-plugins/ directory.
  • Add following code in file and save.
<?php
/**
 * Consent mode filtering.
 */

add_filter( 
    'googlesitekit_consent_defaults', 
    function( $defaults ) {
        $filtered['wait_for_update'] = 700;
        $filtered['ad_storage']      = 'granted';
        $filtered['ad_user_data']    = 'granted';

        return array_merge( $defaults, $filtered );
    }
);
  • Visit the homepage (or any front end page), there should be following snippet available on the page. Notice ad_storage, ad_user_data and wait_for_update.
gtag( 
  'consent', 
  'default',
  {
    "ad_personalization": "denied",
    "ad_storage": "granted",
    "ad_user_data": "granted",
    "analytics_storage": "denied",
    "region": [
      "AT",
      "BE",
      "BG",
      "CY",
      "CZ",
      "DE",
      "DK",
      "EE",
      "ES",
      "FI",
      "FR",
      "GB",
      "GR",
      "HR",
      "HU",
      "IE",
      "IS",
      "IT",
      "LI",
      "LT",
      "LU",
      "LV",
      "MT",
      "NL",
      "NO",
      "PL",
      "PT",
      "RO",
      "SE",
      "SI",
      "SK"
    ],
    "wait_for_update": 700
  }
);

Changelog entry

  • Add the googlesitekit_consent_defaults filter to allow customisation of Consent Mode defaults.
@techanvil techanvil added P1 Medium priority Type: Enhancement Improvement of an existing feature labels Mar 12, 2024
@eugene-manuilov eugene-manuilov self-assigned this Mar 12, 2024
@eugene-manuilov
Copy link
Collaborator

AC ✔️

@eugene-manuilov eugene-manuilov removed their assignment Mar 12, 2024
@zutigrm zutigrm assigned zutigrm and unassigned zutigrm Mar 19, 2024
@ivonac4 ivonac4 added the Next Up Issues to prioritize for definition label Mar 19, 2024
@tofumatt tofumatt self-assigned this Mar 21, 2024
@tofumatt
Copy link
Collaborator

IB ✅

@tofumatt tofumatt removed their assignment Mar 21, 2024
@tofumatt tofumatt removed the Next Up Issues to prioritize for definition label Mar 21, 2024
@ivonac4 ivonac4 added the Squad 2 (Team M) Issues for Squad 2 label Apr 3, 2024
@ankitrox ankitrox assigned ankitrox and unassigned ankitrox Apr 18, 2024
@techanvil techanvil assigned techanvil and ankitrox and unassigned techanvil and ankitrox Apr 18, 2024
@wpdarren wpdarren self-assigned this Apr 23, 2024
@wpdarren
Copy link
Collaborator

wpdarren commented Apr 23, 2024

QA Update: ⚠️

@ankitrox @techanvil this passes the QAB, but I have two questions:

  1. When the tiler is added I am assuming it should function with the WP Consent API plugin activated and disabled? I am sure it should but I do not want to assume.
  2. Should we do any testing with the third-party consent plugins, e.g. Complianz activated? i suspect these plugins should override the filter we've added?

@techanvil
Copy link
Collaborator Author

techanvil commented Apr 23, 2024

Hi @wpdarren, this filter is essentially independent of the WP Consent API plugin status and any existing third-party plugins.

It's purely there to allow modification of the default consent parameters that Site Kit sets when the Consent Mode feature is enabled. It's conceivable that some third party plugin may decide to integrate with it in future (I don't think this is particularly likely, but it's certainly possible), but in order to do so the plugin would need to write code to explicitly make use of the filter, which has obviously just been added and is not in a SK release yet so nobody outside of our team will have actually seen and used it as of yet.

@techanvil techanvil removed their assignment Apr 23, 2024
@wpdarren
Copy link
Collaborator

QA Update: ✅

@techanvil thank you for the clarification there. I did think that would be the case, but wanted to double check.

Verified:

When no filter is added

  • There is the snippet available on the page as per QAB.

image

When filter is added

  • There is the snippet available on the page as per QAB for Notice ad_storage, ad_user_data and wait_for_update based on the filter used in the MU plugin.

image

@wpdarren wpdarren removed their assignment Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Medium priority Squad 2 (Team M) Issues for Squad 2 Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

8 participants