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_consentfilter 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
- Extract this block of code that disables the web tag into a new method. https://github.com/google/site-kit-wp/blob/28780f2a4a3502573d513eb1a82a931284b874fd/includes/Modules/Analytics_4/Web_Tag.php#L161-L176
- Mark the new method as deprecated via a calls to
_deprecated_function(). - Conditionally invoke the method when the Consent Mode
enabledsetting isfalse.
Test Coverage
- Provide PHPUnit test coverage for the above changes.
QA Brief
QA:Eng
- Copy the following PHP snippet to a new
.phpfile inwp-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-consentattributes 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_consentis used, while othergooglesitekit_{module_slug}_tag_block_on_consentfilters 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
QA ✅
block_on_consentfilter foranalytics-4:mu-pluginswasn’t working on my InstaWP test site so I added the filter infunctions.phpinstead.type="text/plain"anddata-block-on-consentattributes appeared as expected:block_on_consentfilter foranalytics-4:type="text/plain"anddata-block-on-consentattributes appeared as expected:adsensein the debug log: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:Engtest 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.
type="text/plain" data-block-on-consent`attributes on the GTag script is not showing.Also, verified below listed scenarios -
Scenario 1
Result - Tag blocking is not enabled.
Scenario 2
Result - Tag blocking is enabled.
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.