site-kit-wp: Deprecate non-AMP block on consent API

Feature Description

In https://github.com/google/site-kit-wp/issues/2087 we introduced a simple API for implementing manual disabling of tags based for web and AMP. AMP has built-in support for blocking elements based on consent, so a manual approach was adopted for web tags.

With consent mode, this should be deprecated to encourage site owners to use consent mode instead.

This should only take effect when the consentMode feature is enabled.


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

Acceptance criteria

  • ~The existent manual disabling of the web tag should be retained for Analytics but only activated when Consent Mode is disabled.~

Please note that the AC for this issue has been updated as follows:

  • Usage of the googlesitekit_analytics-4_tag_block_on_consent filter should be deprecated.
  • When a hook is run for this filter, a deprecation warning should be logged to the debug log.
  • Aside from the deprecation warning, the legacy manual disabling of the web tag should still function as usual.

Implementation Brief

Test Coverage

  • Provide PHPUnit test coverage for the above changes.

QA Brief

QA:Eng

  • Copy the following PHP snippet to a new .php file in wp-content/mu-plugins/ to enable legacy tag blocking:
<?php
add_filter( 'googlesitekit_analytics-4_tag_block_on_consent', '__return_true' );
  • Look for the type="text/plain" data-block-on-consent attributes on the GTag script to confirm legacy tag blocking is enabled:
<!-- Google Analytics snippet added by Site Kit -->
<script type="text/plain" data-block-on-consent src='https://www.googletagmanager.com/gtag/js?id=GT-ABC123' id='google_gtagjs-js' async></script>
  • Verify that a warning is raised when the deprecated filter googlesitekit_analytics-4_tag_block_on_consent is used, while other googlesitekit_{module_slug}_tag_block_on_consent filters don’t raise a warning.
  • Ensure the behaviour related to the above filters still works as expected.

Changelog entry

  • Deprecate legacy web tag block_on_consent for Analytics when Consent Mode is enabled.

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 17

Most upvoted comments

QA ✅

  • Connected Analytics:

image

  • Verified the debug log was empty:

image

  • Enabled the block_on_consent filter for analytics-4:
    • Note, for some reason mu-plugins wasn’t working on my InstaWP test site so I added the filter in functions.php instead.

image

  • Verified the type="text/plain" and data-block-on-consent attributes appeared as expected:

image

  • Verified the deprecated hook error appeared in the debug log:

image

  • Connected AdSense to verify the non-Analytics path:

image

  • Enabled the block_on_consent filter for analytics-4:

image

  • Verified the type="text/plain" and data-block-on-consent attributes appeared as expected:

image

  • Verified that a deprecated hook error did not appear for adsense in the debug log:

image

  • I ran through this with Consent Mode both disabled and enabled with the same result.

Thanks @aaemnnosttv - yes, I got a bit confused as to the intended approach here. Your POC LGTM, I have merged it, although I didn’t notice we still needed to remove the _deprecated_function() call, so have raised a quick followup for that.

FAO the code reviewer for this followup, as mentioned on Slack I was in the middle of doing a QA:Eng test to verify the deprecated filter behaviour when I realised this additional followup was needed, so please assign it back to me in QA so I can finish this off.

As noted on the call earlier, we need to update the deprecation warning to be specific to the filter rather than our internal function call. This shouldn’t invalidate the QA that’s been done so far but let’s confirm once updated.

QA Update ✅

Thank you @techanvil ! I’m getting expected results for all the scenarios.

  • Tested on dev environmet.
  • Verified tag blocking is only enabled when - Enabled via the PHP snippet AND - The consentMode feature flag is disabled OR the consentMode feature flag is enabled while the Consent Mode enabled setting is false.
  • Also, verified that Tag blocking is not enabled via PHP then type="text/plain" data-block-on-consent `attributes on the GTag script is not showing.

image

Also, verified below listed scenarios -

Scenario 1

  • Enabled via the PHP snippet AND
  • the consentMode feature flag is enabled while the Consent Mode enabled setting is true.

Result - Tag blocking is not enabled.

Scenario 2

  • Enabled via the PHP snippet AND
  • the consentMode feature flag is disabled while the Consent Mode enabled setting is true.

Result - Tag blocking is enabled.

image

image

One Deprecated error is still appearing so moving this back to execution as per Slack conversation.

@bethanylang thanks for spotting that, this issue is no longer blocked by #8273 and I’ve removed the dependency.