/**
 * PageSpeed Insights module initialization.
 *
 * 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 { __ } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import {
	AREA_DASHBOARD_SPEED,
	AREA_ENTITY_DASHBOARD_SPEED_PRIMARY,
	AREA_MAIN_DASHBOARD_SPEED_PRIMARY,
	AREA_PAGE_DASHBOARD_SPEED,
} from '../../googlesitekit/widgets/default-areas';
import { SettingsView } from './components/settings';
import DashboardPageSpeedWidget from './components/dashboard/DashboardPageSpeedWidget';
import PageSpeedInsightsIcon from '../../../svg/pagespeed-insights.svg';
import { MODULES_PAGESPEED_INSIGHTS } from './datastore/constants';

export { registerStore } from './datastore';

export const registerModule = ( modules ) => {
	modules.registerModule( 'pagespeed-insights', {
		storeName: MODULES_PAGESPEED_INSIGHTS,
		SettingsViewComponent: SettingsView,
		Icon: PageSpeedInsightsIcon,
		features: [
			__(
				'Website performance reports for mobile and desktop',
				'google-site-kit'
			),
		],
	} );
};

export const registerWidgets = ( widgets ) => {
	widgets.registerWidget(
		'pagespeedInsightsWebVitals',
		{
			Component: DashboardPageSpeedWidget,
			width: widgets.WIDGET_WIDTHS.FULL,
			wrapWidget: false,
		},
		[
			AREA_DASHBOARD_SPEED,
			AREA_PAGE_DASHBOARD_SPEED,
			AREA_MAIN_DASHBOARD_SPEED_PRIMARY,
			AREA_ENTITY_DASHBOARD_SPEED_PRIMARY,
		]
	);
};

@@ -1232,16 +1232,67 @@
 stants';
+%0Aimport %7B isFeatureEnabled %7D from '../../features';
 %0A%0Aexport
@@ -1708,16 +1708,68 @@
  ) =%3E %7B%0A
+%09if ( ! isFeatureEnabled( 'unifiedDashboard' ) ) %7B%0A%09
 %09widgets
@@ -1785,16 +1785,17 @@
 Widget(%0A
+%09
 %09%09'pages
@@ -1820,18 +1820,20 @@
 als',%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09Compo
@@ -1867,16 +1867,17 @@
 get,%0A%09%09%09
+%09
 width: w
@@ -1906,16 +1906,17 @@
 ULL,%0A%09%09%09
+%09
 wrapWidg
@@ -1932,18 +1932,17 @@
 ,%0A%09%09
+%09
 %7D,%0A%09%09
-%5B%0A%09%09%09
+%09%5B 
 AREA
@@ -1954,28 +1954,25 @@
 BOARD_SPEED,
-%0A%09%09%09
+ 
 AREA_PAGE_DA
@@ -1984,18 +1984,256 @@
 RD_SPEED
-,%0A
+ %5D%0A%09%09);%0A%09%7D%0A%0A%09if ( isFeatureEnabled( 'unifiedDashboard' ) ) %7B%0A%09%09widgets.registerWidget(%0A%09%09%09'pagespeedInsightsWebVitals',%0A%09%09%09%7B%0A%09%09%09%09Component: DashboardPageSpeedWidget,%0A%09%09%09%09width: widgets.WIDGET_WIDTHS.FULL,%0A%09%09%09%09wrapWidget: false,%0A%09%09%09%7D,%0A%09%09%09%5B%0A%09
 %09%09%09AREA_
@@ -2262,16 +2262,17 @@
 RIMARY,%0A
+%09
 %09%09%09AREA_
@@ -2307,15 +2307,20 @@
 RY,%0A
+%09
 %09%09%5D%0A
+%09
 %09);%0A
+%09%7D%0A
 %7D;%0A

Put PageSpeed Insights inside feature flags.