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',
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/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 }
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 (
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/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 ) {
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 )
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 ? (
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
+}
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;
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;
-} );
diff --git a/assets/js/modules/analytics/datastore/settings.test.js b/assets/js/modules/analytics/datastore/settings.test.js
index 8dcede03822..d4a5bcaa6c4 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,
@@ -76,7 +74,6 @@ describe( 'modules/analytics settings', () => {
useSnippet: true,
trackingDisabled: [],
anonymizeIP: true,
- canUseSnippet: true,
};
const tagWithPermission = {
accountID: '12345',
@@ -1417,114 +1414,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 );
- } );
- } );
} );
} );
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
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
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 );
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( () => {
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
- );
- }
}
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 );
- } );
} );
} );
} );
diff --git a/assets/js/modules/tagmanager/datastore/versions.js b/assets/js/modules/tagmanager/datastore/versions.js
index 138d61b521d..0da7a4c6e20 100644
--- a/assets/js/modules/tagmanager/datastore/versions.js
+++ b/assets/js/modules/tagmanager/datastore/versions.js
@@ -26,14 +26,12 @@ 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 { MODULES_TAGMANAGER } from './constants';
import {
isValidAccountID,
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;
@@ -117,119 +115,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.
- *
- * @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.
*
@@ -345,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.
*
@@ -433,51 +280,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.
- *
- * @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.
*
diff --git a/assets/js/modules/tagmanager/datastore/versions.test.js b/assets/js/modules/tagmanager/datastore/versions.test.js
index a7076c16d7d..c0c8c1d3872 100644
--- a/assets/js/modules/tagmanager/datastore/versions.test.js
+++ b/assets/js/modules/tagmanager/datastore/versions.test.js
@@ -21,27 +21,19 @@
*/
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,
+ waitForDefaultTimeouts,
} 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 +41,6 @@ describe( 'modules/tagmanager versions', () => {
beforeEach( () => {
registry = createTestRegistry();
- ( { buildAndReceiveWebAndAMP } = createBuildAndReceivers( registry ) );
} );
afterAll( () => {
@@ -99,552 +90,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 =
- 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( '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 =
@@ -740,10 +185,7 @@ describe( 'modules/tagmanager versions', () => {
expect( variableObject ).toStrictEqual( undefined );
- await untilResolved(
- registry,
- MODULES_TAGMANAGER
- ).getLiveContainerVersion( '100', '239' );
+ await waitForDefaultTimeouts();
} );
} );
@@ -907,106 +349,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.
- 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();
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,
- ] );
-}
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 );
- } );
- } );
-} );
diff --git a/includes/Modules/Analytics/Settings.php b/includes/Modules/Analytics/Settings.php
index ce7d276b4eb..d2776da2277 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;
}
);
@@ -192,7 +168,6 @@ protected function get_default() {
'propertyID' => '',
'trackingDisabled' => array( 'loggedinUsers' ),
'useSnippet' => true,
- 'canUseSnippet' => true,
);
}
@@ -209,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'];
}
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'] );
- }
-
-}
diff --git a/includes/Modules/Analytics_4/Settings.php b/includes/Modules/Analytics_4/Settings.php
index 0272915d4a8..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;
/**
@@ -97,7 +96,6 @@ protected function get_default() {
'measurementID' => '',
'trackingDisabled' => array( 'loggedinUsers' ),
'useSnippet' => true,
- 'canUseSnippet' => true,
'googleTagID' => '',
'googleTagAccountID' => '',
'googleTagContainerID' => '',
@@ -122,9 +120,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 +195,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/includes/Modules/Tag_Manager.php b/includes/Modules/Tag_Manager.php
index 03a6de3b4b6..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;
@@ -101,11 +100,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,74 +576,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).
- *
- * @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 )
- )
- );
-
- }
-
- /**
- * 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.
*
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' => '',
);
}
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 ) );
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.' );
- }
-
-}
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' => '',
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 )
);
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() {