From e430660aca134892d9d56f6e12ed8732b46b6798 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:25:13 +0000 Subject: [PATCH 01/44] Remove gaPropertyID from TagManager datastore. --- assets/js/modules/tagmanager/datastore/base.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/base.js b/assets/js/modules/tagmanager/datastore/base.js index 3e3b40089de..5995741eb22 100644 --- a/assets/js/modules/tagmanager/datastore/base.js +++ b/assets/js/modules/tagmanager/datastore/base.js @@ -40,7 +40,6 @@ let baseModuleStore = Modules.createModuleStore( 'tagmanager', { 'internalAMPContainerID', 'useSnippet', 'ownerID', - 'gaPropertyID', ], submitChanges, validateCanSubmitChanges, @@ -49,9 +48,9 @@ let baseModuleStore = Modules.createModuleStore( 'tagmanager', { // Rename generated pieces to adhere to our convention. baseModuleStore = ( ( { actions, selectors, ...store } ) => { // eslint-disable-next-line sitekit/acronym-case - const { setAmpContainerID, setGaPropertyID, ...restActions } = actions; + const { setAmpContainerID, ...restActions } = actions; // eslint-disable-next-line sitekit/acronym-case - const { getAmpContainerID, getGaPropertyID, ...restSelectors } = selectors; + const { getAmpContainerID, ...restSelectors } = selectors; return { ...store, @@ -59,15 +58,11 @@ baseModuleStore = ( ( { actions, selectors, ...store } ) => { ...restActions, // eslint-disable-next-line sitekit/acronym-case setAMPContainerID: setAmpContainerID, - // eslint-disable-next-line sitekit/acronym-case - setGAPropertyID: setGaPropertyID, }, selectors: { ...restSelectors, // eslint-disable-next-line sitekit/acronym-case getAMPContainerID: getAmpContainerID, - // eslint-disable-next-line sitekit/acronym-case - getGAPropertyID: getGaPropertyID, }, }; } )( baseModuleStore ); From c78d28e736a3b5108453a1b86424ba91b8147d46 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:27:52 +0000 Subject: [PATCH 02/44] Remove useGAPropertyIDEffect usage from SettingsEdit. --- .../js/modules/tagmanager/components/settings/SettingsEdit.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/assets/js/modules/tagmanager/components/settings/SettingsEdit.js b/assets/js/modules/tagmanager/components/settings/SettingsEdit.js index e87951c706f..79b882ae339 100644 --- a/assets/js/modules/tagmanager/components/settings/SettingsEdit.js +++ b/assets/js/modules/tagmanager/components/settings/SettingsEdit.js @@ -24,7 +24,6 @@ import { ProgressBar } from 'googlesitekit-components'; import { CORE_MODULES } from '../../../../googlesitekit/modules/datastore/constants'; import { MODULES_TAGMANAGER, ACCOUNT_CREATE } from '../../datastore/constants'; import useExistingTagEffect from '../../hooks/useExistingTagEffect'; -import useGAPropertyIDEffect from '../../hooks/useGAPropertyIDEffect'; import { AccountCreate } from '../common'; import SettingsForm from './SettingsForm'; const { useSelect } = Data; @@ -54,8 +53,6 @@ export default function SettingsEdit() { // Set useSnippet to `false` if there is an existing tag and it is the same as the selected container ID. useExistingTagEffect(); - // Synchronize the gaPropertyID setting with the singular GA property ID in selected containers. - useGAPropertyIDEffect(); let viewComponent; // Here we also check for `hasResolvedAccounts` to prevent showing a different case below From e060a7c0380e9dbde61bc4b35c284fe456b5ffa7 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:28:47 +0000 Subject: [PATCH 03/44] Remove useGAPropertyIDEffect usage from SetupMain. --- assets/js/modules/tagmanager/components/setup/SetupMain.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/assets/js/modules/tagmanager/components/setup/SetupMain.js b/assets/js/modules/tagmanager/components/setup/SetupMain.js index 71d29d315a6..3d21eccece4 100644 --- a/assets/js/modules/tagmanager/components/setup/SetupMain.js +++ b/assets/js/modules/tagmanager/components/setup/SetupMain.js @@ -36,7 +36,6 @@ import SetupForm from './SetupForm'; import { MODULES_TAGMANAGER, ACCOUNT_CREATE } from '../../datastore/constants'; import useExistingTagEffect from '../../hooks/useExistingTagEffect'; import { AccountCreate } from '../common'; -import useGAPropertyIDEffect from '../../hooks/useGAPropertyIDEffect'; const { useSelect } = Data; export default function SetupMain( { finishSetup } ) { @@ -56,8 +55,6 @@ export default function SetupMain( { finishSetup } ) { // Set useSnippet to `false` if there is an existing tag and it is the same as the selected container ID. useExistingTagEffect(); - // Synchronize the gaPropertyID setting with the singular GA property ID in selected containers. - useGAPropertyIDEffect(); let viewComponent; // Here we also check for `hasResolvedAccounts` to prevent showing a different case below From 495f735961bc61ff6263a8aac1f4a45d5a52f6d7 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:29:24 +0000 Subject: [PATCH 04/44] Remove useGAPropertyIDEffect. --- .../tagmanager/hooks/useGAPropertyIDEffect.js | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.js diff --git a/assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.js b/assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.js deleted file mode 100644 index a8a2a5b4ea5..00000000000 --- a/assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Tag Manager useGAPropertyIDEffect custom hook. - * - * Site Kit by Google, Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * WordPress dependencies - */ -import { useEffect } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import Data from 'googlesitekit-data'; -import { MODULES_TAGMANAGER } from '../datastore/constants'; -const { useSelect, useDispatch } = Data; - -export default function useGAPropertyIDEffect() { - const singleAnalyticsPropertyID = useSelect( ( select ) => - select( MODULES_TAGMANAGER ).getSingleAnalyticsPropertyID() - ); - const tagmanagerExistingSettings = useSelect( ( select ) => - select( MODULES_TAGMANAGER ).getSettings() - ); - const { setGAPropertyID } = useDispatch( MODULES_TAGMANAGER ); - - useEffect( () => { - if ( - tagmanagerExistingSettings !== undefined && - singleAnalyticsPropertyID !== undefined - ) { - setGAPropertyID( singleAnalyticsPropertyID || '' ); - } - }, [ - tagmanagerExistingSettings, - singleAnalyticsPropertyID, - setGAPropertyID, - ] ); -} From 895a001917419a6bf1fe83a8c08d0a3cecfb40f5 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:30:05 +0000 Subject: [PATCH 05/44] Remove the test for useGAPropertyIDEffect. --- .../hooks/useGAPropertyIDEffect.test.js | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.test.js diff --git a/assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.test.js b/assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.test.js deleted file mode 100644 index 13342f38db4..00000000000 --- a/assets/js/modules/tagmanager/hooks/useGAPropertyIDEffect.test.js +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Tag Manager useGAPropertyIDEffect hook tests. - * - * Site Kit by Google, Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * External dependencies - */ -import fetchMock from 'fetch-mock'; - -/** - * Internal dependencies - */ -import { renderHook, actHook as act } from '../../../../../tests/js/test-utils'; -import { - createTestRegistry, - waitForDefaultTimeouts, -} from '../../../../../tests/js/utils'; -import { MODULES_TAGMANAGER } from '../datastore/constants'; -import { createBuildAndReceivers } from '../datastore/__factories__/utils'; -import useGAPropertyIDEffect from './useGAPropertyIDEffect'; - -describe( 'useGAPropertyIDEffect', () => { - let registry; - - describe( 'with empty Tag Manager settings store', () => { - beforeEach( () => { - registry = createTestRegistry(); - } ); - - it( 'fetches settings from API if the settings are empty', async () => { - fetchMock.getOnce( - /^\/google-site-kit\/v1\/modules\/tagmanager\/data\/settings/, - { - body: {}, - status: 200, - } - ); - - await act( - () => - new Promise( ( resolve ) => { - renderHook( () => useGAPropertyIDEffect(), { - registry, - } ); - resolve(); - } ) - ); - - await act( waitForDefaultTimeouts ); - - expect( fetchMock ).toHaveFetched( - new RegExp( - '^/google-site-kit/v1/modules/tagmanager/data/settings' - ) - ); - } ); - } ); - - describe( 'with a populated Tag Manager store', () => { - beforeEach( () => { - registry = createTestRegistry(); - // Set settings to prevent fetch in resolver. - registry.dispatch( MODULES_TAGMANAGER ).receiveGetSettings( {} ); - // Set set no existing tag. - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetExistingTag( null ); - } ); - - it( 'sets the gaPropertyID with the current detected singular property ID in selected containers', async () => { - const { buildAndReceiveWebAndAMP } = - createBuildAndReceivers( registry ); - - const TEST_GA_PROPERTY_ID = 'UA-123456789-1'; - - buildAndReceiveWebAndAMP( { - webPropertyID: TEST_GA_PROPERTY_ID, - } ); - - await act( - () => - new Promise( ( resolve ) => { - renderHook( () => useGAPropertyIDEffect(), { - registry, - } ); - resolve(); - } ) - ); - - const propertyID = registry - .select( MODULES_TAGMANAGER ) - .getGAPropertyID(); - - expect( propertyID ).toBe( TEST_GA_PROPERTY_ID ); - } ); - } ); -} ); From 05ecf086a7efd9e18c7bfdea6061ae3b06e36b8e Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:35:45 +0000 Subject: [PATCH 06/44] Remove disabling analytics tag output when propertyIDs match in GTM and GA. --- includes/Modules/Tag_Manager.php | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/includes/Modules/Tag_Manager.php b/includes/Modules/Tag_Manager.php index 03a6de3b4b6..95cffd712a8 100644 --- a/includes/Modules/Tag_Manager.php +++ b/includes/Modules/Tag_Manager.php @@ -101,8 +101,6 @@ public function register() { // Tag Manager tag placement logic. add_action( 'template_redirect', array( $this, 'register_tag' ) ); - // Filter the Analytics `canUseSnippet` value. - add_filter( 'googlesitekit_analytics_can_use_snippet', $this->get_method_proxy( 'can_analytics_use_snippet' ), 10, 2 ); // Filter whether certain users can be excluded from tracking. add_filter( 'googlesitekit_allow_tracking_disabled', $this->get_method_proxy( 'filter_analytics_allow_tracking_disabled' ) ); add_action( 'googlesitekit_analytics_tracking_opt_out', $this->get_method_proxy( 'analytics_tracking_opt_out' ) ); @@ -582,26 +580,6 @@ public function get_tag_matchers() { return new Tag_Matchers(); } - /** - * Filters whether or not the Analytics module's snippet should be controlled by its `useSnippet` setting. - * - * @since 1.28.0 - * @since 1.75.0 Now requires current UA property ID as second parameter. - * - * @param boolean $original_value Original value of useSnippet setting. - * @param string $ua_property_id Current UA property. - * @return boolean Filtered value. - */ - private function can_analytics_use_snippet( $original_value, $ua_property_id ) { - $settings = $this->get_settings()->get(); - - if ( ! empty( $settings['gaPropertyID'] ) && $settings['useSnippet'] && $settings['gaPropertyID'] === $ua_property_id ) { - return false; - } - - return $original_value; - } - /** * Handles Analytics measurement opt-out for the configured Analytics property in the container(s). * From 760cfa8135a9469845afeecbf6d6f0cc03524636 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 14:55:08 +0000 Subject: [PATCH 07/44] Remove the googlesitekit_analytics_can_use_snippet filter. --- includes/Modules/Analytics/Settings.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/includes/Modules/Analytics/Settings.php b/includes/Modules/Analytics/Settings.php index ce7d276b4eb..c101d20117c 100644 --- a/includes/Modules/Analytics/Settings.php +++ b/includes/Modules/Analytics/Settings.php @@ -58,13 +58,6 @@ function ( $default ) { $default['adsenseLinked'] = (bool) $this->options->get( 'googlesitekit_analytics_adsense_linked' ); } - // `canUseSnippet` is a computed setting, so this sets the value if settings have not been saved yet. - // This filter is documented below. - $can_use_snippet = apply_filters( 'googlesitekit_analytics_can_use_snippet', true, '' ); - if ( is_bool( $can_use_snippet ) ) { - $default['canUseSnippet'] = $can_use_snippet; - } - return $default; } ); @@ -135,23 +128,6 @@ function ( $option ) { $option['adsenseLinked'] = $adsense_linked; } - /** - * Filters the state of the can use snipped setting. - * - * This filter exists so that useSnippet can be restored to true when the Tag Manager module - * is disconnected, ensuring the Analytics snippet is always included. - * - * @since 1.28.0 - * @since 1.75.0 Added the `$property_id` parameter. - * - * @param bool $can_use_snippet Whether or not `useSnippet` can control snippet output. Default: `true`. - * @param string $property_id The current property ID. - */ - $can_use_snippet = apply_filters( 'googlesitekit_analytics_can_use_snippet', true, $property_id ); - if ( is_bool( $can_use_snippet ) ) { - $option['canUseSnippet'] = $can_use_snippet; - } - return $option; } ); From 1dd0d9f7c39a34ede5e2e725a35e50fe50d031d4 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:18:41 +0000 Subject: [PATCH 08/44] Remove GTM ability to allow disabling tracking. --- includes/Modules/Tag_Manager.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/includes/Modules/Tag_Manager.php b/includes/Modules/Tag_Manager.php index 95cffd712a8..bb1853e4e6c 100644 --- a/includes/Modules/Tag_Manager.php +++ b/includes/Modules/Tag_Manager.php @@ -102,7 +102,6 @@ public function register() { // Tag Manager tag placement logic. add_action( 'template_redirect', array( $this, 'register_tag' ) ); // Filter whether certain users can be excluded from tracking. - add_filter( 'googlesitekit_allow_tracking_disabled', $this->get_method_proxy( 'filter_analytics_allow_tracking_disabled' ) ); add_action( 'googlesitekit_analytics_tracking_opt_out', $this->get_method_proxy( 'analytics_tracking_opt_out' ) ); } @@ -603,31 +602,6 @@ private function analytics_tracking_opt_out( $property_id ) { } - /** - * Filters whether or not the option to exclude certain users from tracking should be displayed. - * - * If Site Kit does not place the Analytics snippet (neither via Analytics nor via Tag Manager), - * the option to exclude certain users from tracking should not be displayed. - * - * @since 1.36.0 - * - * @param boolean $allowed Whether to allow tracking exclusion. - * @return boolean Filtered value. - */ - private function filter_analytics_allow_tracking_disabled( $allowed ) { - if ( $allowed ) { - return true; - } - - $settings = $this->get_settings()->get(); - - if ( ! empty( $settings['gaPropertyID'] ) && $settings['useSnippet'] ) { - return true; - } - - return $allowed; - } - /** * Checks if the current user has access to the current configured service entity. * From 150a2bcfc5e0aa90dbeb845e46b8d0921dc1613d Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:19:54 +0000 Subject: [PATCH 09/44] Remove GTM ability to render GA opt-out snippet. --- includes/Modules/Tag_Manager.php | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/includes/Modules/Tag_Manager.php b/includes/Modules/Tag_Manager.php index bb1853e4e6c..d350b8ddc29 100644 --- a/includes/Modules/Tag_Manager.php +++ b/includes/Modules/Tag_Manager.php @@ -101,8 +101,6 @@ public function register() { // Tag Manager tag placement logic. add_action( 'template_redirect', array( $this, 'register_tag' ) ); - // Filter whether certain users can be excluded from tracking. - add_action( 'googlesitekit_analytics_tracking_opt_out', $this->get_method_proxy( 'analytics_tracking_opt_out' ) ); } /** @@ -579,29 +577,6 @@ public function get_tag_matchers() { return new Tag_Matchers(); } - /** - * Handles Analytics measurement opt-out for the configured Analytics property in the container(s). - * - * @since 1.41.0 - * - * @param string $property_id Analytics property_id. - */ - private function analytics_tracking_opt_out( $property_id ) { - $settings = $this->get_settings()->get(); - $ga_property_id = $settings['gaPropertyID']; - if ( ! $ga_property_id || $ga_property_id === $property_id ) { - return; - } - - BC_Functions::wp_print_inline_script_tag( - sprintf( - 'window["ga-disable-%s"] = true;', - esc_attr( $ga_property_id ) - ) - ); - - } - /** * Checks if the current user has access to the current configured service entity. * From 4b5ddb867a48811f5e76154b8e9f8f66921c21ea Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:20:36 +0000 Subject: [PATCH 10/44] Remove unused import. --- includes/Modules/Tag_Manager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Modules/Tag_Manager.php b/includes/Modules/Tag_Manager.php index d350b8ddc29..6ac631fa411 100644 --- a/includes/Modules/Tag_Manager.php +++ b/includes/Modules/Tag_Manager.php @@ -36,7 +36,6 @@ use Google\Site_Kit\Core\REST_API\Exception\Invalid_Datapoint_Exception; use Google\Site_Kit\Core\Tags\Guards\Tag_Environment_Type_Guard; use Google\Site_Kit\Core\Tags\Guards\Tag_Verify_Guard; -use Google\Site_Kit\Core\Util\BC_Functions; use Google\Site_Kit\Core\Site_Health\Debug_Data; use Google\Site_Kit\Core\Util\Method_Proxy_Trait; use Google\Site_Kit\Core\Util\Sort; From a351f60416c514e8096ccb67b7ec6cf6ef821cdf Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:22:08 +0000 Subject: [PATCH 11/44] Remove gaPropertyID setting from TagManager backend. --- includes/Modules/Tag_Manager/Settings.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Modules/Tag_Manager/Settings.php b/includes/Modules/Tag_Manager/Settings.php index 7ddeeacc3d6..bf72901b88a 100644 --- a/includes/Modules/Tag_Manager/Settings.php +++ b/includes/Modules/Tag_Manager/Settings.php @@ -80,7 +80,6 @@ protected function get_default() { 'internalContainerID' => '', 'internalAMPContainerID' => '', 'useSnippet' => true, - 'gaPropertyID' => '', ); } From 577d99fc25aa7e4da5512db8a6151286d4b9d847 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:24:55 +0000 Subject: [PATCH 12/44] Remove phpunit tests for canUseSnippet filter in GTM. --- .../integration/Modules/Tag_ManagerTest.php | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/phpunit/integration/Modules/Tag_ManagerTest.php b/tests/phpunit/integration/Modules/Tag_ManagerTest.php index df5515f730a..84722c7fc11 100644 --- a/tests/phpunit/integration/Modules/Tag_ManagerTest.php +++ b/tests/phpunit/integration/Modules/Tag_ManagerTest.php @@ -45,7 +45,6 @@ public function tear_down() { public function test_register() { $tagmanager = new Tag_Manager( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ); remove_all_filters( 'googlesitekit_auth_scopes' ); - remove_all_filters( 'googlesitekit_analytics_can_use_snippet' ); $tagmanager->register(); @@ -53,38 +52,6 @@ public function test_register() { $tagmanager->get_scopes(), apply_filters( 'googlesitekit_auth_scopes', array() ) ); - $this->assertTrue( has_filter( 'googlesitekit_analytics_can_use_snippet' ) ); - } - - public function test_analytics_can_use_snippet() { - remove_all_filters( 'googlesitekit_analytics_can_use_snippet' ); - $context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); - $options = new Options( $context ); - $analytics_settings = new AnalyticsSettings( $options ); - $analytics_settings->delete(); - $tagmanager = new Tag_Manager( $context ); - $settings = $tagmanager->get_settings(); - - // The value should be `true` by default. - $this->assertTrue( $analytics_settings->get()['canUseSnippet'] ); - // Delayed to differentiate between initial value and post-registration value. - $tagmanager->register(); - $analytics_settings->register(); - $this->assertTrue( $analytics_settings->get()['canUseSnippet'] ); - // Should be `true` if there is a `gaPropertyID` set and is not the same as analytics property ID. - $settings->merge( array( 'gaPropertyID' => 'UA-S1T3K1T-1' ) ); - $analytics_settings->merge( array( 'propertyID' => 'UA-9999999-1' ) ); - $this->assertTrue( $analytics_settings->get()['canUseSnippet'] ); - // Should be `false` if there is a `gaPropertyID` set and is the same as analytics property ID. - $settings->merge( array( 'gaPropertyID' => 'UA-S1T3K1T-1' ) ); - $analytics_settings->merge( array( 'propertyID' => 'UA-S1T3K1T-1' ) ); - $this->assertFalse( $analytics_settings->get()['canUseSnippet'] ); - // Should be `true` even with a `gaPropertyID` if GTM's snippet is disabled. - $settings->merge( array( 'useSnippet' => false ) ); - $this->assertTrue( $analytics_settings->get()['canUseSnippet'] ); - // Still `true` if no `gaPropertyID` and no GTM snippet. - $settings->merge( array( 'gaPropertyID' => '' ) ); - $this->assertTrue( $analytics_settings->get()['canUseSnippet'] ); } public function test_register_template_redirect_amp() { From 3bf4ad9eb0dea4521a1ee8d85d1014a5b70f89ce Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:25:29 +0000 Subject: [PATCH 13/44] Remove phpunit test for gaPropertyID setting in GTM. --- tests/phpunit/integration/Modules/Tag_Manager/SettingsTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/integration/Modules/Tag_Manager/SettingsTest.php b/tests/phpunit/integration/Modules/Tag_Manager/SettingsTest.php index 781ed6f2706..d1bdcab0bb1 100644 --- a/tests/phpunit/integration/Modules/Tag_Manager/SettingsTest.php +++ b/tests/phpunit/integration/Modules/Tag_Manager/SettingsTest.php @@ -37,7 +37,6 @@ public function test_get_default() { 'internalContainerID' => '', 'internalAMPContainerID' => '', 'ownerID' => 0, - 'gaPropertyID' => '', ), get_option( Settings::OPTION ) ); From 23dd0226568e3593211910b1c24cbbd9443358fb Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:29:38 +0000 Subject: [PATCH 14/44] Remove the getCanUseSnippet selector. --- .../modules/analytics/datastore/settings.js | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/assets/js/modules/analytics/datastore/settings.js b/assets/js/modules/analytics/datastore/settings.js index cb51cf62517..ba4b18eae6f 100644 --- a/assets/js/modules/analytics/datastore/settings.js +++ b/assets/js/modules/analytics/datastore/settings.js @@ -24,7 +24,6 @@ import invariant from 'invariant'; /** * Internal dependencies */ -import Data from 'googlesitekit-data'; import API from 'googlesitekit-api'; import { CORE_FORMS } from '../../../googlesitekit/datastore/forms/constants'; import { CORE_USER } from '../../../googlesitekit/datastore/user/constants'; @@ -53,12 +52,8 @@ import { FORM_SETUP, } from './constants'; import { createStrictSelect } from '../../../googlesitekit/data/utils'; -import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants'; -import { MODULES_TAGMANAGER } from '../../tagmanager/datastore/constants'; import ga4ReportingTour from '../../../feature-tours/ga4-reporting'; -const { createRegistrySelector } = Data; - // Invariant error messages. export const INVARIANT_INVALID_ACCOUNT_ID = 'a valid accountID is required to submit changes'; @@ -240,42 +235,3 @@ export function validateCanSubmitChanges( select ) { select( MODULES_ANALYTICS_4 ).__dangerousCanSubmitChanges(); } } - -/** - * Gets the value of canUseSnippet based on the gaPropertyID of tagmanager module and propertyID. - * - * @since 1.75.0 - * - * @return {boolean|undefined} Computed value of canUseSnippet. `undefined` if not loaded. - */ -export const getCanUseSnippet = createRegistrySelector( ( select ) => () => { - const analyticsSettings = select( MODULES_ANALYTICS ).getSettings(); - - if ( ! analyticsSettings ) { - return undefined; - } - - const isTagManagerAvailable = - select( CORE_MODULES ).isModuleAvailable( 'tagmanager' ); - const isTagManagerConnected = - isTagManagerAvailable && - select( CORE_MODULES ).isModuleConnected( 'tagmanager' ); - - if ( ! isTagManagerConnected || ! select( MODULES_TAGMANAGER ) ) { - return analyticsSettings.canUseSnippet; - } - - const tagManagerUseSnippet = select( MODULES_TAGMANAGER ).getUseSnippet(); - - if ( ! tagManagerUseSnippet ) { - return analyticsSettings.canUseSnippet; - } - - const gtmGAPropertyID = select( MODULES_TAGMANAGER ).getGAPropertyID(); - - if ( isValidPropertyID( gtmGAPropertyID ) ) { - return gtmGAPropertyID !== analyticsSettings.propertyID; - } - - return analyticsSettings.canUseSnippet; -} ); From 7d59f1f22668867170fce537fd02db01d8fab5d4 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:30:58 +0000 Subject: [PATCH 15/44] Remove jest test for getCanUseSnippet selector. --- .../analytics/datastore/settings.test.js | 111 ------------------ 1 file changed, 111 deletions(-) diff --git a/assets/js/modules/analytics/datastore/settings.test.js b/assets/js/modules/analytics/datastore/settings.test.js index 8dcede03822..048e85be84b 100644 --- a/assets/js/modules/analytics/datastore/settings.test.js +++ b/assets/js/modules/analytics/datastore/settings.test.js @@ -22,8 +22,6 @@ import API from 'googlesitekit-api'; import { CORE_FORMS } from '../../../googlesitekit/datastore/forms/constants'; import { CORE_USER } from '../../../googlesitekit/datastore/user/constants'; -import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants'; -import { MODULES_TAGMANAGER } from '../../tagmanager/datastore/constants'; import { ENHANCED_MEASUREMENT_ENABLED, ENHANCED_MEASUREMENT_FORM, @@ -1417,114 +1415,5 @@ describe( 'modules/analytics settings', () => { } ); } ); } ); - - describe( 'getCanUseSnippet', () => { - beforeEach( () => { - registry - .dispatch( MODULES_ANALYTICS ) - .setSettings( validSettings ); - } ); - it( 'should return the value from analytics settings if tag manager is not available', () => { - const { ...modules } = registry - .select( CORE_MODULES ) - .getModules(); - delete modules.tagmanager; - registry - .dispatch( CORE_MODULES ) - .receiveGetModules( Object.values( modules ) ); - - expect( - registry.select( MODULES_ANALYTICS ).getCanUseSnippet() - ).toBe( validSettings.canUseSnippet ); - } ); - - it( 'should return the value from analytics settings if tag manager is not connected', () => { - provideModules( registry, [ - { - slug: 'tagmanager', - active: true, - connected: false, - }, - ] ); - - expect( - registry.select( MODULES_ANALYTICS ).getCanUseSnippet() - ).toBe( validSettings.canUseSnippet ); - } ); - - it( 'should return the value from analytics settings if tag manager useSnippet is false', () => { - provideModules( registry, [ - { - slug: 'tagmanager', - active: true, - connected: true, - }, - ] ); - - registry - .dispatch( MODULES_TAGMANAGER ) - .setSettings( { useSnippet: false } ); - - expect( - registry.select( MODULES_ANALYTICS ).getCanUseSnippet() - ).toBe( validSettings.canUseSnippet ); - } ); - - it( 'should return the value from analytics settings if there is no GA property in tag manager', () => { - provideModules( registry, [ - { - slug: 'tagmanager', - active: true, - connected: true, - }, - ] ); - - registry - .dispatch( MODULES_TAGMANAGER ) - .setSettings( { useSnippet: true } ); - - expect( - registry.select( MODULES_ANALYTICS ).getCanUseSnippet() - ).toBe( validSettings.canUseSnippet ); - } ); - - it( 'should return `true` if GA property in tag manager is not the same as analytics', () => { - provideModules( registry, [ - { - slug: 'tagmanager', - active: true, - connected: true, - }, - ] ); - - registry.dispatch( MODULES_TAGMANAGER ).setSettings( { - useSnippet: true, - gaPropertyID: 'UA-24680-1', - } ); - - expect( - registry.select( MODULES_ANALYTICS ).getCanUseSnippet() - ).toBe( true ); - } ); - - it( 'should return `false` if GA property in tag manager is the same as analytics', () => { - provideModules( registry, [ - { - slug: 'tagmanager', - active: true, - connected: true, - }, - ] ); - - registry.dispatch( MODULES_TAGMANAGER ).setSettings( { - useSnippet: true, - gaPropertyID: validSettings.propertyID, - } ); - - expect( - registry.select( MODULES_ANALYTICS ).getCanUseSnippet() - ).toBe( false ); - } ); - } ); } ); } ); From c6778761f63e50075fc9359b038fcd22c0be970f Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:31:36 +0000 Subject: [PATCH 16/44] Remove jest test for gaPropertyID setting in GTM. --- assets/js/modules/tagmanager/datastore/containers.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/js/modules/tagmanager/datastore/containers.test.js b/assets/js/modules/tagmanager/datastore/containers.test.js index 549ba76351a..eeab6d5328b 100644 --- a/assets/js/modules/tagmanager/datastore/containers.test.js +++ b/assets/js/modules/tagmanager/datastore/containers.test.js @@ -41,7 +41,6 @@ describe( 'modules/tagmanager containers', () => { internalAMPContainerID: '', internalContainerID: '', useSnippet: true, - gaPropertyID: '', }; beforeAll( () => { From 972900aad0f4c16ffdf57a875e2a58c93e3626ea Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:40:26 +0000 Subject: [PATCH 17/44] Remove the canUseSnippet setting from analytics-4 datastore. --- .../analytics-4/components/settings/SettingsForm.stories.js | 1 - .../analytics-4/components/settings/SettingsView.stories.js | 1 - assets/js/modules/analytics-4/datastore/base.js | 1 - 3 files changed, 3 deletions(-) diff --git a/assets/js/modules/analytics-4/components/settings/SettingsForm.stories.js b/assets/js/modules/analytics-4/components/settings/SettingsForm.stories.js index f01954028c3..f9bb5fb01f4 100644 --- a/assets/js/modules/analytics-4/components/settings/SettingsForm.stories.js +++ b/assets/js/modules/analytics-4/components/settings/SettingsForm.stories.js @@ -208,7 +208,6 @@ export default { webDataStreamID, measurementID, useSnippet: true, - canUseSnippet: true, anonymizeIP: true, trackingDisabled: [ 'loggedinUsers' ], } ); diff --git a/assets/js/modules/analytics-4/components/settings/SettingsView.stories.js b/assets/js/modules/analytics-4/components/settings/SettingsView.stories.js index 31bddc866ff..9e0b73688bf 100644 --- a/assets/js/modules/analytics-4/components/settings/SettingsView.stories.js +++ b/assets/js/modules/analytics-4/components/settings/SettingsView.stories.js @@ -76,7 +76,6 @@ export default { webDataStreamID, measurementID, useSnippet: true, - canUseSnippet: true, ...googleTagSettings, } ); diff --git a/assets/js/modules/analytics-4/datastore/base.js b/assets/js/modules/analytics-4/datastore/base.js index 959b2f96717..71407e20a37 100644 --- a/assets/js/modules/analytics-4/datastore/base.js +++ b/assets/js/modules/analytics-4/datastore/base.js @@ -48,7 +48,6 @@ const baseModuleStore = Modules.createModuleStore( 'analytics-4', { 'webDataStreamID', 'measurementID', 'useSnippet', - 'canUseSnippet', 'ownerID', 'googleTagID', 'googleTagAccountID', From d3b88dce9bd606ec863a218789b8b2632196c3c7 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:44:30 +0000 Subject: [PATCH 18/44] Remove the canUseSnippet setting from Analytics4 backend. --- includes/Modules/Analytics_4/Settings.php | 5 ----- .../phpunit/integration/Modules/Analytics_4/SettingsTest.php | 2 -- tests/phpunit/integration/Modules/Analytics_4Test.php | 5 ----- 3 files changed, 12 deletions(-) diff --git a/includes/Modules/Analytics_4/Settings.php b/includes/Modules/Analytics_4/Settings.php index 0272915d4a8..420598c8661 100644 --- a/includes/Modules/Analytics_4/Settings.php +++ b/includes/Modules/Analytics_4/Settings.php @@ -97,7 +97,6 @@ protected function get_default() { 'measurementID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'googleTagID' => '', 'googleTagAccountID' => '', 'googleTagContainerID' => '', @@ -122,9 +121,6 @@ protected function get_sanitize_callback() { if ( isset( $option['useSnippet'] ) ) { $option['useSnippet'] = (bool) $option['useSnippet']; } - if ( isset( $option['canUseSnippet'] ) ) { - $option['canUseSnippet'] = (bool) $option['canUseSnippet']; - } if ( isset( $option['googleTagID'] ) ) { if ( ! preg_match( '/^(G|GT|AW)-[a-zA-Z0-9]+$/', $option['googleTagID'] ) ) { $option['googleTagID'] = ''; @@ -200,7 +196,6 @@ protected function retrieve_missing_settings( $option ) { $keys_to_check = array( 'accountID', 'adsConversionID', - 'canUseSnippet', 'trackingDisabled', ); $missing_settings = array_diff( $keys_to_check, array_keys( $option ) ); diff --git a/tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php b/tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php index 6598c73cecd..8d51238a488 100644 --- a/tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php +++ b/tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php @@ -72,7 +72,6 @@ public function test_get_default() { 'measurementID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'ownerID' => 0, 'googleTagID' => '', 'googleTagAccountID' => '', @@ -181,7 +180,6 @@ public function test_retrieve_missing_analytics_4_settings() { $keys_to_check = array( 'accountID', 'adsConversionID', - 'canUseSnippet', 'trackingDisabled', ); $settings = $options->get( Settings::OPTION ); diff --git a/tests/phpunit/integration/Modules/Analytics_4Test.php b/tests/phpunit/integration/Modules/Analytics_4Test.php index 0ed67b045ba..afb329af58a 100644 --- a/tests/phpunit/integration/Modules/Analytics_4Test.php +++ b/tests/phpunit/integration/Modules/Analytics_4Test.php @@ -428,7 +428,6 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen 'adsConversionID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'googleTagID' => '', 'googleTagAccountID' => '', 'googleTagContainerID' => '', @@ -455,7 +454,6 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen 'adsConversionID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'googleTagID' => 'GT-123', 'googleTagAccountID' => $google_tag_account_id, 'googleTagContainerID' => $google_tag_container_id, @@ -575,7 +573,6 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen 'adsConversionID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'googleTagID' => '', 'googleTagAccountID' => '', 'googleTagContainerID' => '', @@ -696,7 +693,6 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen 'adsConversionID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'googleTagID' => '', 'googleTagAccountID' => '', 'googleTagContainerID' => '', @@ -726,7 +722,6 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen 'adsConversionID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, 'googleTagID' => '', 'googleTagAccountID' => '', 'googleTagContainerID' => '', From af0d8bae1c8fb617124a2ef5bd0694a8369e5314 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:45:23 +0000 Subject: [PATCH 19/44] Remove unused import. --- includes/Modules/Analytics_4/Settings.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Modules/Analytics_4/Settings.php b/includes/Modules/Analytics_4/Settings.php index 420598c8661..10b3a800a70 100644 --- a/includes/Modules/Analytics_4/Settings.php +++ b/includes/Modules/Analytics_4/Settings.php @@ -14,7 +14,6 @@ use Google\Site_Kit\Core\Storage\Setting_With_Owned_Keys_Interface; use Google\Site_Kit\Core\Storage\Setting_With_Owned_Keys_Trait; use Google\Site_Kit\Core\Storage\Setting_With_ViewOnly_Keys_Interface; -use Google\Site_Kit\Core\Util\Feature_Flags; use Google\Site_Kit\Core\Util\Method_Proxy_Trait; /** From 0f4343ff3a43b2472d16d0430359cd731490fc60 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:47:57 +0000 Subject: [PATCH 20/44] Remove canUseSnippet from the Analytics (UA) backend. --- includes/Modules/Analytics/Settings.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/includes/Modules/Analytics/Settings.php b/includes/Modules/Analytics/Settings.php index c101d20117c..d2776da2277 100644 --- a/includes/Modules/Analytics/Settings.php +++ b/includes/Modules/Analytics/Settings.php @@ -168,7 +168,6 @@ protected function get_default() { 'propertyID' => '', 'trackingDisabled' => array( 'loggedinUsers' ), 'useSnippet' => true, - 'canUseSnippet' => true, ); } @@ -185,9 +184,6 @@ protected function get_sanitize_callback() { if ( isset( $option['useSnippet'] ) ) { $option['useSnippet'] = (bool) $option['useSnippet']; } - if ( isset( $option['canUseSnippet'] ) ) { - $option['canUseSnippet'] = (bool) $option['canUseSnippet']; - } if ( isset( $option['anonymizeIP'] ) ) { $option['anonymizeIP'] = (bool) $option['anonymizeIP']; } From 10e122aa2f28aa87c9620ac10c72af7607c20db2 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:49:19 +0000 Subject: [PATCH 21/44] Remove phpunit tests for the getCanUseSnippet UA setting. --- .../Modules/Analytics/SettingsTest.php | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/tests/phpunit/integration/Modules/Analytics/SettingsTest.php b/tests/phpunit/integration/Modules/Analytics/SettingsTest.php index 39ab59ff036..485a94b8243 100644 --- a/tests/phpunit/integration/Modules/Analytics/SettingsTest.php +++ b/tests/phpunit/integration/Modules/Analytics/SettingsTest.php @@ -101,7 +101,6 @@ public function test_get_default() { 'profileID' => '', 'internalWebPropertyID' => '', 'useSnippet' => true, - 'canUseSnippet' => true, 'ownerID' => 0, 'anonymizeIP' => true, 'trackingDisabled' => array( 'loggedinUsers' ), @@ -243,64 +242,6 @@ public function test_adsense_linked_is_true_if_adsense_is_active_and_connected_o $this->assertTrue( $settings->get()['adsenseLinked'] ); } - public function test_can_use_snippet__default_value() { - remove_all_filters( 'googlesitekit_analytics_can_use_snippet' ); - $context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); - $settings = new Settings( new Options( $context ) ); - $settings->register(); - - // Defaults to `true` - $this->assertTrue( $settings->get()['canUseSnippet'] ); - // Only filters returning a boolean are allowed. - $filter_return = 'a string'; - add_filter( - 'googlesitekit_analytics_can_use_snippet', - function () use ( &$filter_return ) { - return $filter_return; - } - ); - $this->assertTrue( $settings->get()['canUseSnippet'] ); - $filter_return = false; - $this->assertFalse( $settings->get()['canUseSnippet'] ); - } - - public function test_can_use_snippet__saved_value() { - remove_all_filters( 'googlesitekit_analytics_can_use_snippet' ); - $context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); - $settings = new Settings( new Options( $context ) ); - $settings->register(); - - // Defaults to `true` - $this->assertTrue( $settings->get()['canUseSnippet'] ); - // Save with defaults. - $settings->merge( array() ); - $this->assertTrue( $settings->get()['canUseSnippet'] ); - // Saved value may be inconsistent with filtered return. - $settings->merge( array( 'canUseSnippet' => false ) ); - $raw_value = $this->queryOption( Settings::OPTION )['option_value']; - // Here we show that the raw value in the DB is `false` but the setting returns `true`. - $this->assertFalse( maybe_unserialize( $raw_value )['canUseSnippet'] ); - $this->assertTrue( $settings->get()['canUseSnippet'] ); - // Keep in mind the saved value is still `false` below. - - // Only filters returning a boolean are allowed. - $filter_return = 'a string'; - add_filter( - 'googlesitekit_analytics_can_use_snippet', - function () use ( &$filter_return ) { - return $filter_return; - } - ); - // Non-boolean filter return defaults to setting value (saved `false` above). - $this->assertFalse( $settings->get()['canUseSnippet'] ); - $filter_return = false; - $this->assertFalse( $settings->get()['canUseSnippet'] ); - - // No filters restores the default of `true`. - remove_all_filters( 'googlesitekit_analytics_can_use_snippet' ); - $this->assertTrue( $settings->get()['canUseSnippet'] ); - } - public function test_tracking_disabled() { $context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); $settings = new Settings( new Options( $context ) ); From 53accc85c33b474b75f3bbf0238ec44af71ed5d5 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:50:55 +0000 Subject: [PATCH 22/44] Remove the UA tag guard solely based on canUseSnippet setting. --- includes/Modules/Analytics/Tag_Guard.php | 36 ------------------------ 1 file changed, 36 deletions(-) delete mode 100644 includes/Modules/Analytics/Tag_Guard.php diff --git a/includes/Modules/Analytics/Tag_Guard.php b/includes/Modules/Analytics/Tag_Guard.php deleted file mode 100644 index 5f2879405d5..00000000000 --- a/includes/Modules/Analytics/Tag_Guard.php +++ /dev/null @@ -1,36 +0,0 @@ -settings->get(); - return $settings['canUseSnippet'] && ! empty( $settings['useSnippet'] ) && ! empty( $settings['propertyID'] ); - } - -} From 1aa0197caefe7e314b8234c8cbfb16532a0d3d67 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:56:00 +0000 Subject: [PATCH 23/44] Remove the canUseSnippet and its selector from old analytics datastore. --- assets/js/modules/analytics/datastore/base.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/assets/js/modules/analytics/datastore/base.js b/assets/js/modules/analytics/datastore/base.js index 9a3767f03c2..a9e0741ecf0 100644 --- a/assets/js/modules/analytics/datastore/base.js +++ b/assets/js/modules/analytics/datastore/base.js @@ -22,7 +22,6 @@ import Modules from 'googlesitekit-modules'; import { MODULES_ANALYTICS } from './constants'; import { - getCanUseSnippet, rollbackChanges, submitChanges, validateCanSubmitChanges, @@ -40,7 +39,6 @@ const baseModuleStore = Modules.createModuleStore( 'analytics', { 'accountID', 'adsConversionID', 'anonymizeIP', - 'canUseSnippet', 'internalWebPropertyID', 'ownerID', 'profileID', @@ -53,6 +51,4 @@ const baseModuleStore = Modules.createModuleStore( 'analytics', { validateCanSubmitChanges, } ); -baseModuleStore.selectors.getCanUseSnippet = getCanUseSnippet; - export default baseModuleStore; From 79108336696558db2f9a8dc486795970e241dadb Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 15:59:21 +0000 Subject: [PATCH 24/44] Remove usage of canUseSnippet from analytics settings frontend. --- .../settings/SettingsUseSnippetSwitch.js | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/assets/js/modules/analytics/components/settings/SettingsUseSnippetSwitch.js b/assets/js/modules/analytics/components/settings/SettingsUseSnippetSwitch.js index e4f83f97d5e..54e55e64467 100644 --- a/assets/js/modules/analytics/components/settings/SettingsUseSnippetSwitch.js +++ b/assets/js/modules/analytics/components/settings/SettingsUseSnippetSwitch.js @@ -34,10 +34,6 @@ export default function SettingsUseSnippetSwitch() { const useSnippet = useSelect( ( select ) => select( MODULES_ANALYTICS ).getUseSnippet() ); - const canUseSnippet = useSelect( ( select ) => - select( MODULES_ANALYTICS ).getCanUseSnippet() - ); - const existingTag = useSelect( ( select ) => select( MODULES_ANALYTICS ).getExistingTag() ); @@ -45,25 +41,6 @@ export default function SettingsUseSnippetSwitch() { select( MODULES_ANALYTICS ).getPropertyID() ); - if ( canUseSnippet === undefined ) { - return null; - } - - if ( canUseSnippet === false ) { - return ( - - { __( - 'The code is controlled by the Tag Manager module', - 'google-site-kit' - ) } -

- } - /> - ); - } - let description; if ( existingTag ) { From 0497f0084c6b61d49ca2e15a9b09242da23619c6 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:01:35 +0000 Subject: [PATCH 25/44] Remove usage of canUseSnippet from UA frontend switch. --- .../modules/analytics/components/common/UseSnippetSwitch.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/assets/js/modules/analytics/components/common/UseSnippetSwitch.js b/assets/js/modules/analytics/components/common/UseSnippetSwitch.js index f5833f2040a..3489b6751ba 100644 --- a/assets/js/modules/analytics/components/common/UseSnippetSwitch.js +++ b/assets/js/modules/analytics/components/common/UseSnippetSwitch.js @@ -42,9 +42,6 @@ export default function UseSnippetSwitch( { description } ) { const useSnippet = useSelect( ( select ) => select( MODULES_ANALYTICS ).getUseSnippet() ); - const canUseSnippet = useSelect( ( select ) => - select( MODULES_ANALYTICS ).getCanUseSnippet() - ); const hasExistingTag = useSelect( ( select ) => select( MODULES_ANALYTICS ).hasExistingTag() ); @@ -71,10 +68,9 @@ export default function UseSnippetSwitch( { description } ) { 'Place Universal Analytics code', 'google-site-kit' ) } - checked={ canUseSnippet === false ? false : useSnippet } + checked={ useSnippet } onClick={ onChange } hideLabel={ false } - disabled={ canUseSnippet === false } /> { description } From 04b3106914d786911215cd12834bf2615a7c6794 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:02:47 +0000 Subject: [PATCH 26/44] Remove canUseSnippet from UA setup form. --- .../components/setup/SetupUseSnippetSwitch.js | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/assets/js/modules/analytics/components/setup/SetupUseSnippetSwitch.js b/assets/js/modules/analytics/components/setup/SetupUseSnippetSwitch.js index 590df6cdbd2..a5882852303 100644 --- a/assets/js/modules/analytics/components/setup/SetupUseSnippetSwitch.js +++ b/assets/js/modules/analytics/components/setup/SetupUseSnippetSwitch.js @@ -35,34 +35,15 @@ export default function SetupUseSnippetSwitch() { select( MODULES_ANALYTICS ).getExistingTag() ); - const canUseSnippet = useSelect( ( select ) => - select( MODULES_ANALYTICS ).getCanUseSnippet() - ); - const propertyID = useSelect( ( select ) => select( MODULES_ANALYTICS ).getPropertyID() ); // Only render if there is an existing tag or the snippet has been disabled by GTM. - if ( ! ( Boolean( existingTag ) || canUseSnippet === false ) ) { + if ( ! Boolean( existingTag ) ) { return null; } - if ( canUseSnippet === false ) { - return ( - - { __( - 'The code is controlled by the Tag Manager module', - 'google-site-kit' - ) } -

- } - /> - ); - } - const description = existingTag === propertyID ? ( From 3d8882ef65d6eba4ae82b993164f296162512976 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:04:04 +0000 Subject: [PATCH 27/44] Remove canUseSnippet checks from legacy UA forms. --- .../analytics/components/common/AdsConversionIDTextField.js | 5 +---- .../analytics/components/settings/OptionalSettingsView.js | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/assets/js/modules/analytics/components/common/AdsConversionIDTextField.js b/assets/js/modules/analytics/components/common/AdsConversionIDTextField.js index 7800cc1d81e..5dce99c3a20 100644 --- a/assets/js/modules/analytics/components/common/AdsConversionIDTextField.js +++ b/assets/js/modules/analytics/components/common/AdsConversionIDTextField.js @@ -45,10 +45,7 @@ export default function AdsConversionIDTextField() { select( MODULES_ANALYTICS ).getAdsConversionID() ); const snippetEnabled = useSelect( ( select ) => { - return ( - select( MODULES_ANALYTICS ).getCanUseSnippet() && - select( MODULES_ANALYTICS ).getUseSnippet() - ); + return select( MODULES_ANALYTICS ).getUseSnippet(); } ); const ga4SnippetEnabled = useSelect( ( select ) => select( MODULES_ANALYTICS_4 ).getUseSnippet() diff --git a/assets/js/modules/analytics/components/settings/OptionalSettingsView.js b/assets/js/modules/analytics/components/settings/OptionalSettingsView.js index eabdde70672..6d3f75824b3 100644 --- a/assets/js/modules/analytics/components/settings/OptionalSettingsView.js +++ b/assets/js/modules/analytics/components/settings/OptionalSettingsView.js @@ -38,9 +38,6 @@ export default function OptionalSettingsView() { const useSnippet = useSelect( ( select ) => select( MODULES_ANALYTICS ).getUseSnippet() ); - const canUseSnippet = useSelect( ( select ) => - select( MODULES_ANALYTICS ).getCanUseSnippet() - ); const propertyID = useSelect( ( select ) => select( MODULES_ANALYTICS ).getPropertyID() ); @@ -64,7 +61,7 @@ export default function OptionalSettingsView() { useSnippet && ampMode !== 'primary' && isUAConnected; const showAdsConversionIDSettings = - canUseSnippet && ( ( isUAConnected && useSnippet ) || useGA4Snippet ); + ( isUAConnected && useSnippet ) || useGA4Snippet; return ( From 493a0dc1c7dd22f01637f9d7f2fef628e8396a65 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:04:54 +0000 Subject: [PATCH 28/44] Remove canUseSnippet from old analytics fixtures. --- .../datastore/__fixtures__/settings--default.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/assets/js/modules/analytics/datastore/__fixtures__/settings--default.json b/assets/js/modules/analytics/datastore/__fixtures__/settings--default.json index 291c721d16d..a6c7d0c2ce0 100644 --- a/assets/js/modules/analytics/datastore/__fixtures__/settings--default.json +++ b/assets/js/modules/analytics/datastore/__fixtures__/settings--default.json @@ -1,15 +1,14 @@ { - "ownerID": 0, "accountID": "", "adsConversionID": "", "adsenseLinked": false, "anonymizeIP": true, "internalWebPropertyID": "", + "ownerID": 0, "profileID": "", "propertyID": "", "trackingDisabled": [ "loggedinUsers" ], - "useSnippet": true, - "canUseSnippet": true -} \ No newline at end of file + "useSnippet": true +} From 50ddfe06dd5deb52eb16b224003325712f4bb966 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:05:35 +0000 Subject: [PATCH 29/44] Remove jest test for the canUseSnippet setting. --- assets/js/modules/analytics/datastore/settings.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/js/modules/analytics/datastore/settings.test.js b/assets/js/modules/analytics/datastore/settings.test.js index 048e85be84b..d4a5bcaa6c4 100644 --- a/assets/js/modules/analytics/datastore/settings.test.js +++ b/assets/js/modules/analytics/datastore/settings.test.js @@ -74,7 +74,6 @@ describe( 'modules/analytics settings', () => { useSnippet: true, trackingDisabled: [], anonymizeIP: true, - canUseSnippet: true, }; const tagWithPermission = { accountID: '12345', From bf5c2bcc5ccd68f5c6914c220c6bc88ec66801a5 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:06:20 +0000 Subject: [PATCH 30/44] Remove the canUseSnippet setting from legacy UA stories. --- .../analytics/components/settings/SettingsForm.stories.js | 1 - .../analytics/components/settings/SettingsView.stories.js | 1 - .../modules/analytics/components/setup/SetupFormGA4.stories.js | 1 - .../components/setup/SetupFormGA4Transitional.stories.js | 1 - .../js/modules/analytics/components/setup/SetupFormUA.stories.js | 1 - 5 files changed, 5 deletions(-) diff --git a/assets/js/modules/analytics/components/settings/SettingsForm.stories.js b/assets/js/modules/analytics/components/settings/SettingsForm.stories.js index 2904a2e5f61..f3ffbf24d14 100644 --- a/assets/js/modules/analytics/components/settings/SettingsForm.stories.js +++ b/assets/js/modules/analytics/components/settings/SettingsForm.stories.js @@ -432,7 +432,6 @@ export default { } ); registry.dispatch( MODULES_ANALYTICS ).receiveGetSettings( { useSnippet: true, - canUseSnippet: true, anonymizeIP: true, trackingDisabled: [ 'loggedinUsers' ], } ); diff --git a/assets/js/modules/analytics/components/settings/SettingsView.stories.js b/assets/js/modules/analytics/components/settings/SettingsView.stories.js index 11f3b80e7bf..42914664021 100644 --- a/assets/js/modules/analytics/components/settings/SettingsView.stories.js +++ b/assets/js/modules/analytics/components/settings/SettingsView.stories.js @@ -145,7 +145,6 @@ export default { } ); registry.dispatch( MODULES_ANALYTICS ).receiveGetSettings( { useSnippet: true, - canUseSnippet: true, } ); registry .dispatch( MODULES_ANALYTICS ) diff --git a/assets/js/modules/analytics/components/setup/SetupFormGA4.stories.js b/assets/js/modules/analytics/components/setup/SetupFormGA4.stories.js index 967125bf36a..0c7947042c1 100644 --- a/assets/js/modules/analytics/components/setup/SetupFormGA4.stories.js +++ b/assets/js/modules/analytics/components/setup/SetupFormGA4.stories.js @@ -101,7 +101,6 @@ export default { .receiveGetExistingTag( null ); registry.dispatch( MODULES_ANALYTICS ).receiveGetSettings( { adsConversionID: '', - canUseSnippet: true, } ); registry .dispatch( MODULES_ANALYTICS ) diff --git a/assets/js/modules/analytics/components/setup/SetupFormGA4Transitional.stories.js b/assets/js/modules/analytics/components/setup/SetupFormGA4Transitional.stories.js index 47066fd9025..b63a4cbea8f 100644 --- a/assets/js/modules/analytics/components/setup/SetupFormGA4Transitional.stories.js +++ b/assets/js/modules/analytics/components/setup/SetupFormGA4Transitional.stories.js @@ -182,7 +182,6 @@ export default { .receiveGetExistingTag( null ); registry.dispatch( MODULES_ANALYTICS ).receiveGetSettings( { adsConversionID: '', - canUseSnippet: true, } ); registry .dispatch( MODULES_ANALYTICS ) diff --git a/assets/js/modules/analytics/components/setup/SetupFormUA.stories.js b/assets/js/modules/analytics/components/setup/SetupFormUA.stories.js index f4c84ac10a9..d0d7464d0e3 100644 --- a/assets/js/modules/analytics/components/setup/SetupFormUA.stories.js +++ b/assets/js/modules/analytics/components/setup/SetupFormUA.stories.js @@ -76,7 +76,6 @@ export default { .receiveGetExistingTag( null ); registry.dispatch( MODULES_ANALYTICS ).receiveGetSettings( { adsConversionID: '', - canUseSnippet: true, } ); registry .dispatch( MODULES_ANALYTICS ) From fc8d26a0c9aa77be28df953edd49242b9388320d Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:13:53 +0000 Subject: [PATCH 31/44] Remove phpunit test for canUseSnippet tag guard. --- .../Modules/Analytics/Tag_GuardTest.php | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 tests/phpunit/integration/Modules/Analytics/Tag_GuardTest.php diff --git a/tests/phpunit/integration/Modules/Analytics/Tag_GuardTest.php b/tests/phpunit/integration/Modules/Analytics/Tag_GuardTest.php deleted file mode 100644 index aaac42c033b..00000000000 --- a/tests/phpunit/integration/Modules/Analytics/Tag_GuardTest.php +++ /dev/null @@ -1,65 +0,0 @@ - 'test-property-id', - 'useSnippet' => true, - ) - ); - - $this->assertTrue( $guard->can_activate() ); - } - - public function test_cant_activate() { - $settings = new Settings( new Options( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ) ); - $guard = new Tag_Guard( $settings ); - - update_option( - Settings::OPTION, - array( - 'propertyID' => 'test-property-id', - 'useSnippet' => false, - ) - ); - - $this->assertFalse( $guard->can_activate(), 'Should return FALSE when useSnippet has negative value.' ); - - update_option( - Settings::OPTION, - array( - 'propertyID' => '', - 'useSnippet' => true, - ) - ); - - $this->assertFalse( $guard->can_activate(), 'Should return FALSE when propertyID is empty.' ); - } - -} From faa0e56e193d2a97d2079bfa61cdbd323be190d2 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:34:34 +0000 Subject: [PATCH 32/44] Remove validation for legacy getSingleAnalyticsPropertyID selector. --- .../js/modules/tagmanager/datastore/settings.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/settings.js b/assets/js/modules/tagmanager/datastore/settings.js index 30905bbc0c6..63cba51a90a 100644 --- a/assets/js/modules/tagmanager/datastore/settings.js +++ b/assets/js/modules/tagmanager/datastore/settings.js @@ -154,14 +154,10 @@ export function validateCanSubmitChanges( select ) { getAMPContainerID, getInternalContainerID, getInternalAMPContainerID, - getSingleAnalyticsPropertyID, - hasAnyAnalyticsPropertyID, haveSettingsChanged, isDoingSubmitChanges, } = strictSelect( MODULES_TAGMANAGER ); const { isAMP, isSecondaryAMP } = strictSelect( CORE_SITE ); - const { isModuleActive } = strictSelect( CORE_MODULES ); - const { getPropertyID } = strictSelect( MODULES_ANALYTICS ); const accountID = getAccountID(); @@ -240,15 +236,4 @@ export function validateCanSubmitChanges( select ) { ); } } - - if ( - isModuleActive( 'analytics' ) && - getPropertyID() && - hasAnyAnalyticsPropertyID() - ) { - invariant( - getSingleAnalyticsPropertyID() === getPropertyID(), - INVARIANT_GTM_GA_PROPERTY_ID_MISMATCH - ); - } } From e5501906851163f5ae3ed86a202cca0e2cc8f928 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:34:54 +0000 Subject: [PATCH 33/44] Remove the getSingleAnalyticsPropertyID selector. --- .../modules/tagmanager/datastore/versions.js | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.js b/assets/js/modules/tagmanager/datastore/versions.js index 138d61b521d..1a694ccdc85 100644 --- a/assets/js/modules/tagmanager/datastore/versions.js +++ b/assets/js/modules/tagmanager/datastore/versions.js @@ -433,31 +433,6 @@ const baseSelectors = { ]; }, - /** - * Gets the single property ID used by all selected containers. - * - * @since 1.18.0 - * - * @return {(string|null|boolean|undefined)} String property ID used by all containers, - * `null` if no property ID was found in either container, - * `false` if a single property ID could not be determined, - * or `undefined` if live container data is not loaded yet. - */ - getSingleAnalyticsPropertyID: createRegistrySelector( ( select ) => () => { - const propertyIDs = - select( MODULES_TAGMANAGER ).getAnalyticsPropertyIDs(); - - if ( propertyIDs === undefined ) { - return undefined; - } - - if ( propertyIDs.length === 1 ) { - return propertyIDs[ 0 ]; // (string|null) - } - - return false; - } ), - /** * Checks whether any Analytics property ID is present in either selected container. * From 18d1826012cd78fa818ee07dffc5eefb024e4c27 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:35:20 +0000 Subject: [PATCH 34/44] Remove jest tests for getSingleAnalyticsPropertyID. --- .../tagmanager/datastore/versions.test.js | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js index a7076c16d7d..9f25017acfe 100644 --- a/assets/js/modules/tagmanager/datastore/versions.test.js +++ b/assets/js/modules/tagmanager/datastore/versions.test.js @@ -907,49 +907,6 @@ describe( 'modules/tagmanager versions', () => { } ); } ); - describe( 'getSingleAnalyticsPropertyID', () => { - // Having multiple propertyIDs is currently only possible in secondary AMP - // so we'll use that context for all of these tests. - beforeEach( () => - registry - .dispatch( CORE_SITE ) - .receiveSiteInfo( { ampMode: AMP_MODE_SECONDARY } ) - ); - - it( 'returns the single common property ID used by both containers', () => { - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-123456789-1', - ampPropertyID: 'UA-123456789-1', - } ); - - const singleAnalyticsPropertyID = registry - .select( MODULES_TAGMANAGER ) - .getSingleAnalyticsPropertyID(); - expect( singleAnalyticsPropertyID ).toBe( 'UA-123456789-1' ); - } ); - - it( 'returns false if both containers don’t reference the same property ID', () => { - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-123456789-1', - ampPropertyID: 'UA-9999999-9', - } ); - - const singleAnalyticsPropertyID = registry - .select( MODULES_TAGMANAGER ) - .getSingleAnalyticsPropertyID(); - expect( singleAnalyticsPropertyID ).toBe( false ); - } ); - - it( 'returns null if no Analytics property ID was found', () => { - buildAndReceiveWebAndAMP(); - - const singleAnalyticsPropertyID = registry - .select( MODULES_TAGMANAGER ) - .getSingleAnalyticsPropertyID(); - expect( singleAnalyticsPropertyID ).toBe( null ); - } ); - } ); - describe( 'hasAnyAnalyticsPropertyID', () => { // Having multiple propertyIDs is currently only possible in secondary AMP // so we'll use that context for all of these tests. From 381b2d2a834e4c9dcd206d2f0a52b6e08c02d213 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:36:14 +0000 Subject: [PATCH 35/44] Remove the legacy hasAnyAnalyticsPropertyID selector. --- .../modules/tagmanager/datastore/versions.js | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.js b/assets/js/modules/tagmanager/datastore/versions.js index 1a694ccdc85..d7da8f0e0c8 100644 --- a/assets/js/modules/tagmanager/datastore/versions.js +++ b/assets/js/modules/tagmanager/datastore/versions.js @@ -433,26 +433,6 @@ const baseSelectors = { ]; }, - /** - * Checks whether any Analytics property ID is present in either selected container. - * - * @since 1.18.0 - * - * @return {(boolean|undefined)} `true` if an Analytics property ID is present in either container, - * `false` if no Analytics property ID is present in either container, - * `undefined` if live container version data is not loaded yet. - */ - hasAnyAnalyticsPropertyID: createRegistrySelector( ( select ) => () => { - const propertyIDs = - select( MODULES_TAGMANAGER ).getAnalyticsPropertyIDs(); - - if ( propertyIDs === undefined ) { - return undefined; - } - - return propertyIDs.some( ( propertyID ) => propertyID !== null ); - } ), - /** * Checks whether or not the live container version is being fetched for the given account and container IDs. * From 8f506066e17193aa08ecc44bff25095b4c3a892b Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:36:41 +0000 Subject: [PATCH 36/44] Remove jest tests for hasAnyAnalyticsPropertyID selector. --- .../tagmanager/datastore/versions.test.js | 57 ------------------- 1 file changed, 57 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js index 9f25017acfe..15c8355b9f0 100644 --- a/assets/js/modules/tagmanager/datastore/versions.test.js +++ b/assets/js/modules/tagmanager/datastore/versions.test.js @@ -907,63 +907,6 @@ describe( 'modules/tagmanager versions', () => { } ); } ); - describe( 'hasAnyAnalyticsPropertyID', () => { - // Having multiple propertyIDs is currently only possible in secondary AMP - // so we'll use that context for all of these tests. - beforeEach( () => - registry - .dispatch( CORE_SITE ) - .receiveSiteInfo( { ampMode: AMP_MODE_SECONDARY } ) - ); - - it( 'returns true if the web container has a property ID and the AMP container does not', () => { - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-12345-1', - } ); - - expect( - registry - .select( MODULES_TAGMANAGER ) - .hasAnyAnalyticsPropertyID() - ).toBe( true ); - } ); - - it( 'returns true if the AMP container has a property ID and the web container does not', () => { - buildAndReceiveWebAndAMP( { - ampPropertyID: 'UA-12345-1', - } ); - - expect( - registry - .select( MODULES_TAGMANAGER ) - .hasAnyAnalyticsPropertyID() - ).toBe( true ); - } ); - - it( 'returns true if both containers have a property ID, regardless of matching', () => { - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-99999-9', - ampPropertyID: 'UA-12345-1', - } ); - - expect( - registry - .select( MODULES_TAGMANAGER ) - .hasAnyAnalyticsPropertyID() - ).toBe( true ); - } ); - - it( 'returns false if neither container has a property ID', () => { - buildAndReceiveWebAndAMP(); - - expect( - registry - .select( MODULES_TAGMANAGER ) - .hasAnyAnalyticsPropertyID() - ).toBe( false ); - } ); - } ); - describe( 'isDoingGetLiveContainerVersion', () => { it( 'returns true while the live container version fetch is in progress', async () => { jest.useFakeTimers(); From d8b95bf1b384d6f44cf8ea5300df279ac1b26a4a Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:38:14 +0000 Subject: [PATCH 37/44] Remove the legacy getAnalyticsPropertyIDs selector. --- .../modules/tagmanager/datastore/versions.js | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.js b/assets/js/modules/tagmanager/datastore/versions.js index d7da8f0e0c8..e2327cfa559 100644 --- a/assets/js/modules/tagmanager/datastore/versions.js +++ b/assets/js/modules/tagmanager/datastore/versions.js @@ -27,7 +27,6 @@ import invariant from 'invariant'; import API from 'googlesitekit-api'; import Data from 'googlesitekit-data'; import { MODULES_TAGMANAGER, CONTEXT_WEB } from './constants'; -import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants'; import { isValidAccountID, isValidInternalContainerID, @@ -117,60 +116,6 @@ const baseResolvers = { }; const baseSelectors = { - /** - * Gets a unique list of Analytics property IDs for all effective containers based on current selections. - * - * @since 1.18.0 - * - * @return {(Array|undefined)} Array of unique property IDs, including `null` if none, or `undefined` if not fully loaded. - */ - getAnalyticsPropertyIDs: createRegistrySelector( ( select ) => () => { - const { isAMP, isSecondaryAMP } = select( CORE_SITE ); - const accountID = select( MODULES_TAGMANAGER ).getAccountID(); - - if ( ! isValidAccountID( accountID ) ) { - return []; - } - - const propertyIDs = new Set(); - const internalContainerID = - select( MODULES_TAGMANAGER ).getInternalContainerID(); - if ( - ( ! isAMP() || isSecondaryAMP() ) && - isValidInternalContainerID( internalContainerID ) - ) { - propertyIDs.add( - select( - MODULES_TAGMANAGER - ).getLiveContainerAnalyticsPropertyID( - accountID, - internalContainerID - ) - ); - } - - const internalAMPContainerID = - select( MODULES_TAGMANAGER ).getInternalAMPContainerID(); - if ( isAMP() && isValidInternalContainerID( internalAMPContainerID ) ) { - propertyIDs.add( - select( - MODULES_TAGMANAGER - ).getLiveContainerAnalyticsPropertyID( - accountID, - internalAMPContainerID - ) - ); - } - - // If either selector returned undefined, return undefined here as well. - // We do this here to ensure resolvers are triggered for both. - if ( propertyIDs.has( undefined ) ) { - return undefined; - } - - return Array.from( propertyIDs ); - } ), - /** * Gets the live container Universal Analytics property ID for the given account and container ID. * From 64900b978e7fdfc544b19d92d346f6a1cc0477fb Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:40:01 +0000 Subject: [PATCH 38/44] Remove jest tests for getAnalyticsPropertyIDs. --- .../tagmanager/datastore/versions.test.js | 314 +----------------- 1 file changed, 1 insertion(+), 313 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js index 15c8355b9f0..a744e564082 100644 --- a/assets/js/modules/tagmanager/datastore/versions.test.js +++ b/assets/js/modules/tagmanager/datastore/versions.test.js @@ -21,27 +21,18 @@ */ import API from 'googlesitekit-api'; import { MODULES_TAGMANAGER } from './constants'; -import { - CORE_SITE, - AMP_MODE_PRIMARY, - AMP_MODE_SECONDARY, -} from '../../../googlesitekit/datastore/site/constants'; import { createTestRegistry, muteFetch, untilResolved, unsubscribeFromAll, } from '../../../../../tests/js/utils'; -import { - createBuildAndReceivers, - parseLiveContainerVersionIDs as parseIDs, -} from './__factories__/utils'; +import { parseLiveContainerVersionIDs as parseIDs } from './__factories__/utils'; import * as factories from './__factories__'; import * as fixtures from './__fixtures__'; describe( 'modules/tagmanager versions', () => { let registry; - let buildAndReceiveWebAndAMP; beforeAll( () => { API.setUsingCache( false ); @@ -49,7 +40,6 @@ describe( 'modules/tagmanager versions', () => { beforeEach( () => { registry = createTestRegistry(); - ( { buildAndReceiveWebAndAMP } = createBuildAndReceivers( registry ) ); } ); afterAll( () => { @@ -99,308 +89,6 @@ describe( 'modules/tagmanager versions', () => { } ); describe( 'selectors', () => { - describe( 'getAnalyticsPropertyIDs', () => { - describe( 'no AMP', () => { - beforeEach( () => - registry - .dispatch( CORE_SITE ) - .receiveSiteInfo( { ampMode: false } ) - ); - - it( 'returns an array including the property ID found in the current web container', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionWeb( { - propertyID: 'UA-12345-1', - } ); - const { accountID, containerID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( accountID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setContainerID( containerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalContainerID( internalContainerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ 'UA-12345-1' ] ); - } ); - - it( 'returns an array of `null` if the selected container has no Analytics property tags', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionWeb(); - const { accountID, containerID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( accountID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setContainerID( containerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalContainerID( internalContainerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - expect( - registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ) - ).toEqual( null ); - - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ null ] ); - } ); - - it( 'returns undefined if the live container data is not loaded yet', async () => { - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( '12345' ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setContainerID( 'GTM-G000GL3' ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalContainerID( '9876' ); - - muteFetch( - new RegExp( - '^/google-site-kit/v1/modules/tagmanager/data/live-container-version' - ) - ); - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toStrictEqual( undefined ); - - await untilResolved( - registry, - MODULES_TAGMANAGER - ).getLiveContainerVersion( '12345', '9876' ); - } ); - } ); - - describe( 'Primary AMP', () => { - beforeEach( () => - registry - .dispatch( CORE_SITE ) - .receiveSiteInfo( { ampMode: AMP_MODE_PRIMARY } ) - ); - - it( 'returns an array including the property ID found in the current AMP container', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionAMP( { - propertyID: 'UA-12345-1', - } ); - const { accountID, containerID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( accountID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAMPContainerID( containerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalAMPContainerID( internalContainerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ 'UA-12345-1' ] ); - } ); - - it( 'returns an array of `null` if the selected container has no Analytics property tags', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionAMP(); - const { accountID, containerID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( accountID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAMPContainerID( containerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalAMPContainerID( internalContainerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - expect( - registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ) - ).toEqual( null ); - - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ null ] ); - } ); - - it( 'returns undefined if the live container data is not loaded yet', async () => { - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( '12345' ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAMPContainerID( 'GTM-G000GL3' ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalAMPContainerID( '9876' ); - - muteFetch( - new RegExp( - '^/google-site-kit/v1/modules/tagmanager/data/live-container-version' - ) - ); - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toStrictEqual( undefined ); - - await untilResolved( - registry, - MODULES_TAGMANAGER - ).getLiveContainerVersion( '12345', '9876' ); - } ); - } ); - - describe( 'Secondary AMP', () => { - beforeEach( () => - registry - .dispatch( CORE_SITE ) - .receiveSiteInfo( { ampMode: AMP_MODE_SECONDARY } ) - ); - - it( 'returns an array including property IDs found in both the web and AMP containers', () => { - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-123456789-1', - ampPropertyID: 'UA-9999999-9', - } ); - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ - 'UA-123456789-1', - 'UA-9999999-9', - ] ); - } ); - - it( 'returns an array of unique property IDs of both the web and AMP containers', () => { - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-123456789-1', - ampPropertyID: 'UA-123456789-1', - } ); - - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ 'UA-123456789-1' ] ); - } ); - - it( 'returns an array of `null` if the selected containers have no Analytics property tags', () => { - buildAndReceiveWebAndAMP(); - - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toEqual( [ null ] ); - } ); - - it( 'returns undefined if the live container data is not loaded yet for either container', async () => { - const liveContainerVersionWeb = - factories.buildLiveContainerVersionWeb(); - const { accountID, containerID, internalContainerID } = - parseIDs( liveContainerVersionWeb ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAccountID( accountID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setContainerID( containerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalContainerID( internalContainerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( - liveContainerVersionWeb, - { accountID, internalContainerID } - ); - const liveContainerVersionAMP = - factories.buildLiveContainerVersionWeb(); - const { ampContainerID, internalAMPContainerID } = parseIDs( - liveContainerVersionAMP - ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setAMPContainerID( ampContainerID ); - registry - .dispatch( MODULES_TAGMANAGER ) - .setInternalAMPContainerID( internalAMPContainerID ); - // Received the live container data for the web container but not the AMP container. - - muteFetch( - new RegExp( - '^/google-site-kit/v1/modules/tagmanager/data/live-container-version' - ) - ); - const propertyIDs = registry - .select( MODULES_TAGMANAGER ) - .getAnalyticsPropertyIDs(); - - expect( propertyIDs ).toStrictEqual( undefined ); - - await untilResolved( - registry, - MODULES_TAGMANAGER - ).getLiveContainerVersion( '100', '223' ); - } ); - } ); - } ); - describe( 'getLiveContainerAnalyticsTag', () => { it( 'returns the Universal Analytics tag object from the live container object', () => { const liveContainerVersion = From 9d8154a61b9fb02eb1a7b589dc641d6548f04ef0 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:41:20 +0000 Subject: [PATCH 39/44] Remove the legacy getLiveContainerAnalyticsPropertyID selector. --- .../modules/tagmanager/datastore/versions.js | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.js b/assets/js/modules/tagmanager/datastore/versions.js index e2327cfa559..65da9976fe2 100644 --- a/assets/js/modules/tagmanager/datastore/versions.js +++ b/assets/js/modules/tagmanager/datastore/versions.js @@ -32,7 +32,6 @@ import { isValidInternalContainerID, } from '../util/validation'; import { createFetchStore } from '../../../googlesitekit/data/create-fetch-store'; -import { isValidPropertyID } from '../../analytics/util'; import { isValidGoogleTagID } from '../../analytics-4/utils/validation'; const { createRegistrySelector } = Data; @@ -116,65 +115,6 @@ const baseResolvers = { }; const baseSelectors = { - /** - * Gets the live container Universal Analytics property ID for the given account and container ID. - * - * @since 1.18.0 - * - * @param {Object} state Data store's state. - * @param {string} accountID Account ID the container belongs to. - * @param {string} internalContainerID Internal container ID to get the Analytics tag for. - * @return {(string|null|undefined)} Analytics property ID if present and valid, `null` if none exists or not valid, or `undefined` if not loaded yet. - */ - getLiveContainerAnalyticsPropertyID: createRegistrySelector( - ( select ) => - function ( state, accountID, internalContainerID ) { - const analyticsTag = select( - MODULES_TAGMANAGER - ).getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ); - - if ( analyticsTag === undefined ) { - return undefined; - } - - if ( analyticsTag?.parameter ) { - // Check if property ID is provided directly on the tag first. - let propertyID = analyticsTag.parameter.find( - ( { key } ) => key === 'trackingId' - )?.value; - // If not, check if there is a gaSettings variable referenced. - if ( ! propertyID ) { - propertyID = analyticsTag.parameter.find( - ( { key } ) => key === 'gaSettings' - )?.value; - } - // If the propertyID is a variable, parse out the name and look up its value. - if ( propertyID?.startsWith( '{{' ) ) { - propertyID = propertyID.replace( /(\{\{|\}\})/g, '' ); - const gaSettingsVariable = select( - MODULES_TAGMANAGER - ).getLiveContainerVariable( - accountID, - internalContainerID, - propertyID - ); - propertyID = gaSettingsVariable?.parameter.find( - ( { key } ) => key === 'trackingId' - )?.value; - } - // Finally, check that whatever was found is a valid ID. - if ( isValidPropertyID( propertyID ) ) { - return propertyID; - } - } - - return null; - } - ), - /** * Gets the first Google Tag object within the current live container for the given account and internal container ID. * From 1439b36678fc51e7eba38e9cb4697006c6338ced Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:41:52 +0000 Subject: [PATCH 40/44] Remove jest tests for the legacy getLiveContainerAnalyticsPropertyID selector. --- .../tagmanager/datastore/versions.test.js | 118 ------------------ 1 file changed, 118 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js index a744e564082..04e2afe44b7 100644 --- a/assets/js/modules/tagmanager/datastore/versions.test.js +++ b/assets/js/modules/tagmanager/datastore/versions.test.js @@ -215,124 +215,6 @@ describe( 'modules/tagmanager versions', () => { } ); } ); - describe( 'getLiveContainerAnalyticsPropertyID', () => { - it( 'gets the propertyID associated with the Universal Analytics tag settings variable', () => { - const liveContainerVersion = - fixtures.liveContainerVersions.web.gaWithVariable; - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const propertyID = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsPropertyID( - accountID, - internalContainerID - ); - - expect( propertyID ).toBe( 'UA-123456789-1' ); - } ); - - it( 'gets the propertyID associated with the Universal Analytics tag settings when provided directly', () => { - const liveContainerVersion = - fixtures.liveContainerVersions.web.gaWithOverride; - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const propertyID = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsPropertyID( - accountID, - internalContainerID - ); - - expect( propertyID ).toBe( 'UA-1234567-99' ); - } ); - - it( 'gets the propertyID associated with the Universal Analytics tag for an AMP container', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionAMP( { - propertyID: 'UA-123456789-1', - } ); - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const propertyID = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsPropertyID( - accountID, - internalContainerID - ); - - expect( propertyID ).toBe( 'UA-123456789-1' ); - } ); - - it( 'returns null if no Analytics tag exists in the container', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionWeb(); - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const propertyID = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsPropertyID( - accountID, - internalContainerID - ); - - expect( propertyID ).toStrictEqual( null ); - } ); - - it( 'returns undefined if the live container version is not loaded yet', async () => { - const liveContainerVersion = - factories.buildLiveContainerVersionWeb(); - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - - muteFetch( - new RegExp( - '^/google-site-kit/v1/modules/tagmanager/data/live-container-version' - ) - ); - const propertyID = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsPropertyID( - accountID, - internalContainerID - ); - - expect( propertyID ).toStrictEqual( undefined ); - - await untilResolved( - registry, - MODULES_TAGMANAGER - ).getLiveContainerVersion( '100', '235' ); - } ); - } ); - describe( 'getLiveContainerVariable', () => { it( 'returns the variable object from the live container object by variable name', () => { const liveContainerVersion = From fc90622f91056a8a71828361b27e9d7334b0ed52 Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:42:53 +0000 Subject: [PATCH 41/44] Remove the legacy getLiveContainerAnalyticsTag selector. --- .../modules/tagmanager/datastore/versions.js | 40 +------------------ 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.js b/assets/js/modules/tagmanager/datastore/versions.js index 65da9976fe2..0da7a4c6e20 100644 --- a/assets/js/modules/tagmanager/datastore/versions.js +++ b/assets/js/modules/tagmanager/datastore/versions.js @@ -26,7 +26,7 @@ import invariant from 'invariant'; */ import API from 'googlesitekit-api'; import Data from 'googlesitekit-data'; -import { MODULES_TAGMANAGER, CONTEXT_WEB } from './constants'; +import { MODULES_TAGMANAGER } from './constants'; import { isValidAccountID, isValidInternalContainerID, @@ -230,44 +230,6 @@ const baseSelectors = { } ), - /** - * Gets the live container Universal Analytics tag object for the given account and container ID. - * - * @since 1.18.0 - * - * @param {Object} state Data store's state. - * @param {string} accountID Account ID the container belongs to. - * @param {string} internalContainerID Internal container ID to get the Analytics tag for. - * @return {(Object|null|undefined)} Live container Universal Analytics tag object, `null` if none exists, or `undefined` if not loaded yet. - */ - getLiveContainerAnalyticsTag: createRegistrySelector( - ( select ) => - function ( state, accountID, internalContainerID ) { - const liveContainerVersion = select( - MODULES_TAGMANAGER - ).getLiveContainerVersion( accountID, internalContainerID ); - - if ( liveContainerVersion === undefined ) { - return undefined; - } - - if ( liveContainerVersion?.tag ) { - const tagType = - liveContainerVersion.container.usageContext[ 0 ] === - CONTEXT_WEB - ? 'ua' - : 'ua_amp'; - return ( - liveContainerVersion.tag.find( - ( { type } ) => type === tagType - ) || null - ); - } - - return null; - } - ), - /** * Gets the live container variable object by the given name for the given account and container ID. * From 7e3e299e6e0a2e40f7ffc3f841677a13bb9e004e Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:43:19 +0000 Subject: [PATCH 42/44] Remove jest tests for the legacy getLiveContainerAnalyticsTag selector. --- .../tagmanager/datastore/versions.test.js | 126 ------------------ 1 file changed, 126 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js index 04e2afe44b7..93d99f3dae8 100644 --- a/assets/js/modules/tagmanager/datastore/versions.test.js +++ b/assets/js/modules/tagmanager/datastore/versions.test.js @@ -89,132 +89,6 @@ describe( 'modules/tagmanager versions', () => { } ); describe( 'selectors', () => { - describe( 'getLiveContainerAnalyticsTag', () => { - it( 'returns the Universal Analytics tag object from the live container object', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionWeb( { - propertyID: 'UA-12345-1', - } ); - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const tagObject = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ); - - expect( tagObject ).toMatchObject( { type: 'ua' } ); - expect( tagObject ).toEqual( - liveContainerVersion.tag.find( - ( { type } ) => type === 'ua' - ) - ); - } ); - - it( 'returns the Universal Analytics tag object from the live container object for an AMP container', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionAMP( { - propertyID: 'UA-12345-1', - } ); - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const tagObject = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ); - - expect( tagObject ).toMatchObject( { type: 'ua_amp' } ); - expect( tagObject ).toEqual( - liveContainerVersion.tag.find( - ( { type } ) => type === 'ua_amp' - ) - ); - } ); - - it( 'returns null if the live container version does not contain a Universal Analytics tag', () => { - const liveContainerVersion = - factories.buildLiveContainerVersionWeb(); - const { accountID, internalContainerID } = - parseIDs( liveContainerVersion ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( liveContainerVersion, { - accountID, - internalContainerID, - } ); - - const tagObject = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ); - - expect( tagObject ).toStrictEqual( null ); - } ); - - it( 'returns null if no live container version exists', () => { - const accountID = '12345'; - const internalContainerID = '98765'; - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( null, { - accountID, - internalContainerID, - } ); - - const tagObject = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ); - - expect( tagObject ).toStrictEqual( null ); - } ); - - it( 'returns undefined if the live container version is not loaded yet', async () => { - const accountID = '12345'; - const internalContainerID = '98765'; - - muteFetch( - new RegExp( - '^/google-site-kit/v1/modules/tagmanager/data/live-container-version' - ) - ); - const tagObject = registry - .select( MODULES_TAGMANAGER ) - .getLiveContainerAnalyticsTag( - accountID, - internalContainerID - ); - - expect( tagObject ).toStrictEqual( undefined ); - - await untilResolved( - registry, - MODULES_TAGMANAGER - ).getLiveContainerVersion( '12345', '98765' ); - } ); - } ); - describe( 'getLiveContainerVariable', () => { it( 'returns the variable object from the live container object by variable name', () => { const liveContainerVersion = From 708e75395782921c6c9187e4659717f0bc12214a Mon Sep 17 00:00:00 2001 From: Jimmy Madon Date: Sat, 24 Feb 2024 16:55:55 +0000 Subject: [PATCH 43/44] Remove additional jest tests for legacy GTM and UA integration. --- .../tagmanager/datastore/settings.test.js | 190 +----------------- 1 file changed, 2 insertions(+), 188 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/settings.test.js b/assets/js/modules/tagmanager/datastore/settings.test.js index 6ae657d93f3..eff731899bb 100644 --- a/assets/js/modules/tagmanager/datastore/settings.test.js +++ b/assets/js/modules/tagmanager/datastore/settings.test.js @@ -36,14 +36,12 @@ import { import { CORE_FORMS } from '../../../googlesitekit/datastore/forms/constants'; import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants'; import { MODULES_ANALYTICS } from '../../analytics/datastore/constants'; -import defaultModules, * as modulesFixtures from '../../../googlesitekit/modules/datastore/__fixtures__'; +import defaultModules from '../../../googlesitekit/modules/datastore/__fixtures__'; import * as fixtures from './__fixtures__'; import { accountBuilder, containerBuilder, buildAccountWithContainers, - buildLiveContainerVersionWeb, - buildLiveContainerVersionAMP, } from './__factories__'; import { createTestRegistry, @@ -54,13 +52,9 @@ import { import { getItem, setItem } from '../../../googlesitekit/api/cache'; import { createCacheKey } from '../../../googlesitekit/api'; import fetchMock from 'fetch-mock'; -import { - parseLiveContainerVersionIDs, - createBuildAndReceivers, -} from './__factories__/utils'; +import { createBuildAndReceivers } from './__factories__/utils'; import { getNormalizedContainerName } from '../util'; import { - INVARIANT_GTM_GA_PROPERTY_ID_MISMATCH, INVARIANT_INVALID_ACCOUNT_ID, INVARIANT_INVALID_AMP_CONTAINER_SELECTION, INVARIANT_INVALID_AMP_INTERNAL_CONTAINER_ID, @@ -694,68 +688,6 @@ describe( 'modules/tagmanager settings', () => { registry.select( MODULES_TAGMANAGER ).canSubmitChanges() ).toBe( false ); } ); - - it( 'requires Analytics propertyID setting to match the propertyID in the web container', () => { - const modules = modulesFixtures.withActive( 'analytics' ); - registry - .dispatch( CORE_MODULES ) - .receiveGetModules( modules ); - registry - .dispatch( MODULES_ANALYTICS ) - .receiveGetSettings( { propertyID: '' } ); - const liveContainerVersion = buildLiveContainerVersionWeb( { - propertyID: 'UA-12345-1', - } ); - parseLiveContainerVersionIDs( - liveContainerVersion, - ( { accountID, containerID, internalContainerID } ) => { - registry - .dispatch( MODULES_TAGMANAGER ) - .setSettings( { - ...validSettings, - accountID, - containerID, - internalContainerID, - } ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( - liveContainerVersion, - { accountID, internalContainerID } - ); - } - ); - - // No property ID set in Analytics - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges(); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( true ); - // Matching property ID in Analytics and GTM - registry - .dispatch( MODULES_ANALYTICS ) - .setPropertyID( 'UA-12345-1' ); - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges(); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( true ); - // Non-matching property IDs - registry - .dispatch( MODULES_ANALYTICS ) - .setPropertyID( 'UA-99999-9' ); - expect( () => - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges() - ).toThrow( INVARIANT_GTM_GA_PROPERTY_ID_MISMATCH ); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( false ); - } ); } ); describe( 'with primary AMP', () => { @@ -955,73 +887,6 @@ describe( 'modules/tagmanager settings', () => { .__dangerousCanSubmitChanges() ).toThrow( INVARIANT_INVALID_ACCOUNT_ID ); } ); - - it( 'requires Analytics propertyID setting to match the propertyID in the AMP container', () => { - const modules = modulesFixtures.withActive( 'analytics' ); - registry - .dispatch( CORE_MODULES ) - .receiveGetModules( modules ); - registry - .dispatch( MODULES_ANALYTICS ) - .receiveGetSettings( { propertyID: '' } ); - const liveContainerVersion = buildLiveContainerVersionAMP( { - propertyID: 'UA-12345-1', - } ); - parseLiveContainerVersionIDs( - liveContainerVersion, - ( { - accountID, - internalContainerID, - ampContainerID, - internalAMPContainerID, - } ) => { - registry - .dispatch( MODULES_TAGMANAGER ) - .setSettings( { - ...validSettings, - accountID, - ampContainerID, - internalAMPContainerID, - } ); - registry - .dispatch( MODULES_TAGMANAGER ) - .receiveGetLiveContainerVersion( - liveContainerVersion, - { accountID, internalContainerID } - ); - } - ); - - // No property ID set in Analytics - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges(); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( true ); - // Matching property ID in Analytics and GTM - registry - .dispatch( MODULES_ANALYTICS ) - .setPropertyID( 'UA-12345-1' ); - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges(); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( true ); - // Non-matching property IDs - registry - .dispatch( MODULES_ANALYTICS ) - .setPropertyID( 'UA-99999-9' ); - expect( () => - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges() - ).toThrow( INVARIANT_GTM_GA_PROPERTY_ID_MISMATCH ); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( false ); - } ); } ); describe( 'with secondary AMP', () => { @@ -1329,57 +1194,6 @@ describe( 'modules/tagmanager settings', () => { registry.select( MODULES_TAGMANAGER ).canSubmitChanges() ).toBe( true ); } ); - - it( 'requires Analytics propertyID setting to match the propertyID in both containers', () => { - const modules = modulesFixtures.withActive( 'analytics' ); - registry - .dispatch( CORE_MODULES ) - .receiveGetModules( modules ); - registry - .dispatch( MODULES_ANALYTICS ) - .receiveGetSettings( { propertyID: '' } ); - const { buildAndReceiveWebAndAMP } = - createBuildAndReceivers( registry ); - buildAndReceiveWebAndAMP( { - webPropertyID: 'UA-12345-1', - ampPropertyID: 'UA-12345-1', - } ); - - // This test only checks matching between the singular propertyID in containers - // and the Analytics propertyID setting. This is because the check for - // multiple property IDs (non-matching IDs between containers) happens before this - // and results in a different validation error (see above). - - // No property ID set in Analytics - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges(); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( true ); - // Matching property ID in Analytics and GTM - registry - .dispatch( MODULES_ANALYTICS ) - .setPropertyID( 'UA-12345-1' ); - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges(); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( true ); - // Non-matching property IDs - registry - .dispatch( MODULES_ANALYTICS ) - .setPropertyID( 'UA-99999-9' ); - expect( () => - registry - .select( MODULES_TAGMANAGER ) - .__dangerousCanSubmitChanges() - ).toThrow( INVARIANT_GTM_GA_PROPERTY_ID_MISMATCH ); - expect( - registry.select( MODULES_TAGMANAGER ).canSubmitChanges() - ).toBe( false ); - } ); } ); } ); } ); From 837506cfbe312528e41dd640c20cf5c5281d23ca Mon Sep 17 00:00:00 2001 From: Arafat Zahan Date: Tue, 27 Feb 2024 16:39:08 +0600 Subject: [PATCH 44/44] Fix jest test. --- assets/js/modules/tagmanager/datastore/versions.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js index 93d99f3dae8..c0c8c1d3872 100644 --- a/assets/js/modules/tagmanager/datastore/versions.test.js +++ b/assets/js/modules/tagmanager/datastore/versions.test.js @@ -26,6 +26,7 @@ import { muteFetch, untilResolved, unsubscribeFromAll, + waitForDefaultTimeouts, } from '../../../../../tests/js/utils'; import { parseLiveContainerVersionIDs as parseIDs } from './__factories__/utils'; import * as factories from './__factories__'; @@ -184,10 +185,7 @@ describe( 'modules/tagmanager versions', () => { expect( variableObject ).toStrictEqual( undefined ); - await untilResolved( - registry, - MODULES_TAGMANAGER - ).getLiveContainerVersion( '100', '239' ); + await waitForDefaultTimeouts(); } ); } );