Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions assets/js/components/setup/ModuleSetup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ describe( 'ModuleSetup', () => {
const propertyID = properties[ 0 ]._id;
const webDataStreamID = webDataStreamsBatch[ propertyID ][ 0 ]._id;

registry.dispatch( MODULES_ANALYTICS_4 ).receiveGetSettings( {
adsConversionID: '',
} );
registry.dispatch( MODULES_ANALYTICS_4 ).receiveGetSettings( {} );

registry
.dispatch( MODULES_ANALYTICS_4 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,91 +20,48 @@
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useSelect } from 'googlesitekit-data';
import { MODULES_ANALYTICS_4 } from '@/js/modules/analytics-4/datastore/constants';
import DisplaySetting from '@/js/components/DisplaySetting';
import { trackingExclusionLabels } from '@/js/modules/analytics-4/components/common/TrackingExclusionSwitches';
import Typography from '@/js/components/Typography';

export default function OptionalSettingsView() {
const useSnippet = useSelect( ( select ) =>
select( MODULES_ANALYTICS_4 ).getUseSnippet()
);
const adsConversionIDMigratedAtMs = useSelect( ( select ) =>
select( MODULES_ANALYTICS_4 ).getAdsConversionIDMigratedAtMs()
);
const trackingDisabled = useSelect(
( select ) => select( MODULES_ANALYTICS_4 ).getTrackingDisabled() || []
);
const adsConversionID = useSelect( ( select ) =>
select( MODULES_ANALYTICS_4 ).getAdsConversionID()
);

return (
<Fragment>
<div className="googlesitekit-settings-module__meta-items">
<div className="googlesitekit-settings-module__meta-item">
<Typography
as="h5"
size="medium"
type="label"
className="googlesitekit-settings-module__meta-item-type"
>
{ __( 'Excluded from Analytics', 'google-site-kit' ) }
</Typography>
<p className="googlesitekit-settings-module__meta-item-data">
{ !! trackingDisabled.length &&
trackingDisabled
.map(
( exclusion ) =>
trackingExclusionLabels[ exclusion ]
)
.join(
_x(
', ',
'list separator',
'google-site-kit'
)
) }
{ ! trackingDisabled.length &&
__(
'Analytics is currently enabled for all visitors',
'google-site-kit'
<div className="googlesitekit-settings-module__meta-items">
<div className="googlesitekit-settings-module__meta-item">
<Typography
as="h5"
size="medium"
type="label"
className="googlesitekit-settings-module__meta-item-type"
>
{ __( 'Excluded from Analytics', 'google-site-kit' ) }
</Typography>
<p className="googlesitekit-settings-module__meta-item-data">
{ !! trackingDisabled.length &&
trackingDisabled
.map(
( exclusion ) =>
trackingExclusionLabels[ exclusion ]
)
.join(
_x( ', ', 'list separator', 'google-site-kit' )
) }
</p>
</div>
{ ! trackingDisabled.length &&
__(
'Analytics is currently enabled for all visitors',
'google-site-kit'
) }
</p>
</div>

{ /* Prevent the Ads Conversion ID setting displaying after this field has been
migrated to the Ads module, even after resetting the Analytics module. */ }
{ useSnippet &&
! adsConversionIDMigratedAtMs &&
!! adsConversionID && (
<div className="googlesitekit-settings-module__meta-items">
<div className="googlesitekit-settings-module__meta-item">
<Typography
as="h5"
size="medium"
type="label"
className="googlesitekit-settings-module__meta-item-type"
>
{ __( 'Ads Conversion ID', 'google-site-kit' ) }
</Typography>
<p className="googlesitekit-settings-module__meta-item-data">
{ !! adsConversionID && (
<DisplaySetting value={ adsConversionID } />
) }
{ ! adsConversionID &&
__( 'None', 'google-site-kit' ) }
</p>
</div>
</div>
) }
</Fragment>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ export default {
provideSiteInfo( registry );
provideModuleRegistrations( registry );

registry.dispatch( MODULES_ANALYTICS_4 ).receiveGetSettings( {
adsConversionID: '',
} );
registry
.dispatch( MODULES_ANALYTICS_4 )
.receiveGetExistingTag( null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ describe( 'SetupForm', () => {
} );

it( 'submits the form upon pressing the CTA', async () => {
registry.dispatch( MODULES_ANALYTICS_4 ).setSettings( {
adsConversionID: '',
} );
registry.dispatch( MODULES_TAGMANAGER ).setSettings( {} );
registry
.dispatch( MODULES_ANALYTICS_4 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ exports[`SetupForm renders the form correctly 1`] = `
>
<button
class="mdc-button googlesitekit-button-icon--spinner googlesitekit-button-icon--spinner__after mdc-button--raised"
disabled=""
target="_self"
>
<span
Expand Down Expand Up @@ -480,7 +479,6 @@ exports[`SetupForm renders the form correctly with setupFlowRefresh enabled 1`]
>
<button
class="mdc-button googlesitekit-button-icon--spinner googlesitekit-button-icon--spinner__after mdc-button--raised"
disabled=""
target="_self"
>
<span
Expand Down
2 changes: 0 additions & 2 deletions assets/js/modules/analytics-4/datastore/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const baseModuleStore = Modules.createModuleStore( MODULE_SLUG_ANALYTICS_4, {
storeName: MODULES_ANALYTICS_4,
settingSlugs: [
'accountID',
'adsConversionID',
'adSenseLinked',
'adSenseLinkedLastSyncedAt',
'propertyID',
Expand All @@ -59,7 +58,6 @@ const baseModuleStore = Modules.createModuleStore( MODULE_SLUG_ANALYTICS_4, {
'availableCustomDimensions',
'propertyCreateTime',
'trackingDisabled',
'adsConversionIDMigratedAtMs',
'adsLinked',
'adsLinkedLastSyncedAt',
'detectedEvents',
Expand Down
13 changes: 0 additions & 13 deletions assets/js/modules/analytics-4/datastore/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
WEBDATASTREAM_CREATE,
} from './constants';
import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants';
import { isValidConversionID } from '@/js/modules/ads/utils/validation';
import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants';
import { CORE_NOTIFICATIONS } from '@/js/googlesitekit/notifications/datastore/constants';
import { GTG_SETUP_CTA_BANNER_NOTIFICATION } from '@/js/googlesitekit/notifications/constants';
Expand All @@ -65,8 +64,6 @@ export const INVARIANT_INVALID_WEBDATASTREAM_NAME =
'a valid web data stream name is required to submit changes';
export const INVARIANT_WEBDATASTREAM_ALREADY_EXISTS =
'a web data stream with the same name already exists';
export const INVARIANT_INVALID_ADS_CONVERSION_ID =
'a valid ads adsConversionID is required to submit changes';

const store = {
selectors: {
Expand Down Expand Up @@ -292,7 +289,6 @@ export function validateCanSubmitChanges( select ) {
getPropertyID,
getWebDataStreamID,
doesWebDataStreamExist,
getAdsConversionID,
} = createStrictSelect( select )( MODULES_ANALYTICS_4 );

invariant( haveAnyGA4SettingsChanged(), INVARIANT_SETTINGS_NOT_CHANGED );
Expand Down Expand Up @@ -332,15 +328,6 @@ export function validateCanSubmitChanges( select ) {
);
}
}

const adsConversionID = getAdsConversionID();

if ( adsConversionID !== '' ) {
invariant(
isValidConversionID( adsConversionID ),
INVARIANT_INVALID_ADS_CONVERSION_ID
);
}
}

export function validateHaveSettingsChanged( select, state, keys ) {
Expand Down
28 changes: 0 additions & 28 deletions assets/js/modules/analytics-4/datastore/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,6 @@ describe( 'modules/analytics-4 settings', () => {
it( 'accepts a change to analytics-4 settings as a valid change', () => {
registry.dispatch( MODULES_ANALYTICS_4 ).setSettings( {
propertyID: '1001',
adsConversionID: '',
} );

expect(
Expand All @@ -1073,33 +1072,6 @@ describe( 'modules/analytics-4 settings', () => {
.__dangerousCanSubmitChanges()
).not.toThrow();
} );

it( 'accepts a change to enhanced measurement settings as a valid change', () => {
registry.dispatch( MODULES_ANALYTICS_4 ).setSettings( {
adsConversionID: '',
} );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setEnhancedMeasurementSettings(
propertyID,
webDataStreamID,
{
streamEnabled: false,
}
);

expect(
registry
.select( MODULES_ANALYTICS_4 )
.canSubmitChanges()
).toBe( true );

expect( () =>
registry
.select( MODULES_ANALYTICS_4 )
.__dangerousCanSubmitChanges()
).not.toThrow();
} );
} );

it( 'should require a valid propertyID', () => {
Expand Down
133 changes: 133 additions & 0 deletions includes/Core/Util/Migration_n_e_x_t.php
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this has been added to IB, but we don't need this migration. There is nothing to migrate here. Let's remove this class.

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* Migration for Analytics Ads Conversion ID.
*
* @package Google\Site_Kit\Core\Util
* @copyright 2026 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/

namespace Google\Site_Kit\Core\Util;

use Google\Site_Kit\Context;
use Google\Site_Kit\Core\Storage\Options;
use Google\Site_Kit\Modules\Analytics_4\Settings as Analytics_Settings;

/**
* Class Migration_n_e_x_t
*
* @since n.e.x.t
* @access private
* @ignore
*/
class Migration_N_E_X_T {
/**
* Target DB version.
*/
const DB_VERSION = 'n.e.x.t';

/**
* DB version option name.
*/
const DB_VERSION_OPTION = 'googlesitekit_db_version';

/**
* Context instance.
*
* @since n.e.x.t
* @var Context
*/
protected $context;

/**
* Options instance.
*
* @since n.e.x.t
* @var Options
*/
protected $options;

/**
* Analytics_Settings instance.
*
* @since n.e.x.t
* @var Analytics_Settings
*/
protected $analytics_settings;

/**
* Constructor.
*
* @since n.e.x.t
*
* @param Context $context Plugin context instance.
* @param Options $options Optional. Options instance.
*/
public function __construct(
Context $context,
?Options $options = null
) {
$this->context = $context;
$this->options = $options ?: new Options( $context );
$this->analytics_settings = new Analytics_Settings( $this->options );
}

/**
* Registers hooks.
*
* @since n.e.x.t
*/
public function register() {
add_action( 'admin_init', array( $this, 'migrate' ) );
}

/**
* Migrates the DB.
*
* @since n.e.x.t
*/
public function migrate() {
$db_version = $this->options->get( self::DB_VERSION_OPTION );

if ( ! $db_version || version_compare( $db_version, self::DB_VERSION, '<' ) ) {
$this->migrate_remove_analytics_conversion_id_setting();

$this->options->set( self::DB_VERSION_OPTION, self::DB_VERSION );
}
}

/**
* Removes the `adsConversionIDMigratedAtMs` setting that is no longer used,
* if present.
*
* @since n.e.x.t
*/
protected function migrate_remove_analytics_conversion_id_setting() {
if ( ! $this->analytics_settings->has() ) {
return;
}

$analytics_settings = $this->analytics_settings->get();

if ( ! is_array( $analytics_settings ) || empty( $analytics_settings ) ) {
return;
}

// If the `adsConversionIDMigratedAtMs` setting does not exist,
// there is nothing to remove and we can return early.
if (
! array_key_exists(
'adsConversionIDMigratedAtMs',
$analytics_settings
)
) {
return;
}

unset( $analytics_settings['adsConversionIDMigratedAtMs'] );

// Save the updated settings.
$this->analytics_settings->set( $analytics_settings );
}
}
Loading
Loading