site-kit-wp: The plugin should not send any data if the wp_get_environment_type() is detected as anything other than production
https://make.wordpress.org/core/2020/07/24/new-wp_get_environment_type-function-in-wordpress-5-5/ https://developer.wordpress.org/reference/functions/wp_get_environment_type/
No data should be sent to Google if the WP_ENVIRONMENT_TYPE system variable is not production.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- If the function
wp_get_environment_type()exists (we should not polyfill this one) and it it returns anything other than “production”, all Site Kit tags (Analytics, AdSense, Tag Manager) that collect data should not be rendered.
Implementation Brief
- create a new
Tag_Production_Guardcommon tag guard class similar toTag_Verify_Guardin the sameCore/Tags/Guardslocation - in the
can_activatemethod of the new class use the functionwp_get_environment_type()to returnTRUEif the environment isproductionand the function exists - also return
TRUEif the function does not exist - update the
register_tagmethods used by Adsense, Analytics, Analytics 4 and Tag Manager to include the newTag_Production_Guard. For example the Adsense code is inModules/Adsense.php. The additional code will be something like$tag->use_guard( new Tag_Production_Guard() );
Test Coverage
Add tests to a new Core/Tags/Guards/Tag_Product_GuardTest file.
- if the
wp_get_environment_type()function does not exist test thatTRUEis returned - if the functions does exist test what the tag guard returns based on whether
WP_ENVIRONMENT_TYPEis set toproductionor not. The environment variable can be set usingputenv:putenv( 'WP_ENVIRONMENT_TYPE=development' )sets it todevelopmentputenv( 'WP_ENVIRONMENT_TYPE' )unsets the variable
Visual Regression Changes
- n/a
QA Brief
- Take a look at
Setting the environment typehttps://make.wordpress.org/core/2020/07/24/new-wp_get_environment_type-function-in-wordpress-5-5/ - Enable any of the modules that enable tag guard (e.g. Adsense, Analytics, Analytics 4 and Tag Manager )
- Set your environment type to
localand save the page source for the home page of your site that end users see (e.g. http://sitekit.test) tolocal.txt - Change it back to
productionand save the page source for the home page toproduction.txt - Take a diff between the
local.txtandproduction.txt, ensure that the local doesn’t contain the tags in the page source, example screenshot:
Changelog entry
- Add a new tag guard that prevents rendering tags for non-production environments.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 19 (3 by maintainers)
Hi @andyblackwell 👋 just wanted to follow-up with you to let you know that the upcoming release (1.78.0) will include a new filter to control which environment types tags will be output for. See #4474 for details.
We do have environment specific configurations and safeguards as you eluded to that stem from the env that is set, so that isn’t an option.
@ivankruchkoff could you please add QAB?
@Hazlitte would it be possible to add an estimate here now the IB is completed please?
@felixarntz this sounds like a good idea and something we could probably implement as a common tag guard. What do you think?