Enhanced Measurement Created Despite Disabled
Bug Description
While completing testing on the Singular Analytics Module, I noticed that when setting up Analytics, the user creates a new property/web data stream and disables Enhanced Measurement; when the new property is created, the Enhanced Measurement toggle is changed and enabled. This is not a regression, as it occurs on the latest release.
You can see it in action on this screencast.
https://github.com/google/site-kit-wp/assets/73545194/dfdff5f1-b82c-460b-a4e2-24602e958fe5
Steps to reproduce
- Activate Analytics Module.
- During setup, select and existing account but chose to create a New property.
- Toggle the enhanced measurement switch off.
- Continue setup.
- See that the enhance measurement for the newly created property/data stream is enabled anyways.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Creating a new property (or new measurement ID) during Analytics setup should honor the "Enable enhanced measurement toggle" and only enable enhanced measurement for the newly created web data stream associated with newly created property when the toggle is "On".
Implementation Brief
It seems we do not have an implementation for passing the enhanced measurement settings when new web data stream is created from settings, unlike how it is done in account create flow.
- [ ] Go to the
assets/js/modules/analytics-4/datastore/webdatastreams.jsand update thecreateWebDataStreamaction- Collect the value from the
CORE_FORMSwhere enhanced measurement switch component will store the current value https://github.com/google/site-kit-wp/blob/d6c58d6d644209b60469061c1b04a3008afc5b7c/assets/js/modules/analytics-4/components/common/EnhancedMeasurementSwitch.js#L55-L57 - Pass it as a third parameter to the
fetchCreateWebDataStreamfunction , asenhancedMeasurementStreamEnabledhttps://github.com/google/site-kit-wp/blob/d6c58d6d644209b60469061c1b04a3008afc5b7c/assets/js/modules/analytics-4/datastore/webdatastreams.js#L174-L177- And include it in https://github.com/google/site-kit-wp/blob/d6c58d6d644209b60469061c1b04a3008afc5b7c/assets/js/modules/analytics-4/datastore/webdatastreams.js#L114-L147
- Collect the value from the
- [ ] Update
Google\Site_Kit\Modules\Analytics_4class- [ ] Modify the
POST:create-webdatastreamendpoint increate_data_requestmethod https://github.com/google/site-kit-wp/blob/d6c58d6d644209b60469061c1b04a3008afc5b7c/includes/Modules/Analytics_4.php#L1041-L1055 to check for newly addedenhancedMeasurementStreamEnabledparameter, and pass it to thecreate_webdatastreammethod. Make it as an optional parameter - [ ] In
create_webdatastreammethod- Instead of returning the response straight, return it to a variable, and if
enhancedMeasurementStreamEnabledparameter is available send the request to theenhanced-measurement-settingsendpoint https://github.com/google/site-kit-wp/blob/d6c58d6d644209b60469061c1b04a3008afc5b7c/includes/Modules/Analytics_4.php#L838-L849 with the needed parameters. You can acquire web data stream ID from response’s_idproperty - Return the web data stream creation response.
- Instead of returning the response straight, return it to a variable, and if
- [ ] Modify the
Test Coverage
- No update needed
QA Brief
Changelog entry
I was doing release testing on main and created new everything (account, property, data steam) and disabled EM. All went well.
Even the EM banner showed up right after.
However, I can reproduce this by selecting an existing account and creating a new Property on it. Note that is only happens in setup, and not when creating a new property in Settings.
Moving this forward. :+1:
AC ✔️
IB ✅
QA Update: ✅
Verified:
Noted the need to grant the additional edit permission to create a new property/datastream to reproduce the issue:
- Went through OAuth and came back and the automatic creation afterward. See screencast.
- The enhanced measurement setting keeps the value selected while creating a new property/web data stream.
- On the setup module screen, the switch is enabled by default, even if on the selected property, you disabled enhanced measurement switch is enabled by default, as well as whenever you switch to different/new property or/and the web data stream switch is reset to on by default
- On the Settings page, the switch is less pushy. If the enhanced measurement for a selected property is disabled, it shows as off by default or when switching between the account/property/web data stream dropdown.
I ran through some testing of enhanced measurement in its entirety to ensure everything worked as expected. Including testing the banner on the dashboard when the feature is disabled. Enabling and disabling the feature within settings
Note: I did notice a bug, but not a regression related to the banner on the dashboard. I will create a ticket for this.
https://github.com/google/site-kit-wp/assets/73545194/f1d73e21-7b03-405d-95da-602060bdbcda
Screenshots