From bedb26dc759245f33f4a90bfb236217a1f023e92 Mon Sep 17 00:00:00 2001 From: Asvin Balloo Date: Mon, 11 Oct 2021 14:13:47 +0400 Subject: [PATCH 1/8] Add AdBlockerWarning Widget. --- .../dashboard/AdBlockerWarningWidget.js | 55 ++++++++++++++++ .../AdBlockerWarningWidget.stories.js | 62 +++++++++++++++++++ .../adsense/components/dashboard/index.js | 1 + assets/js/modules/adsense/index.js | 18 +++++- assets/sass/admin.scss | 1 + ...googlesitekit-widget-adBlockerWarning.scss | 30 +++++++++ 6 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js create mode 100644 assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.stories.js create mode 100644 assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss diff --git a/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js b/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js new file mode 100644 index 00000000000..afc2a25ce84 --- /dev/null +++ b/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js @@ -0,0 +1,55 @@ +/** + * AdBlockerWarningWidget component. + * + * 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 PropTypes from 'prop-types'; + +/** + * Internal dependencies + */ +import Data from 'googlesitekit-data'; +import { MODULES_ADSENSE } from '../../datastore/constants'; +import AdBlockerWarning from '../common/AdBlockerWarning'; +import whenActive from '../../../../util/when-active'; +const { useSelect } = Data; + +function AdBlockerWarningWidget( { Widget } ) { + const isAdBlockerActive = useSelect( ( select ) => + select( MODULES_ADSENSE ).isAdBlockerActive() + ); + + if ( ! isAdBlockerActive ) { + return null; + } + + return ( + + + + ); +} + +AdBlockerWarningWidget.propTypes = { + Widget: PropTypes.elementType.isRequired, +}; + +export default whenActive( { moduleName: 'adsense' } )( + AdBlockerWarningWidget +); diff --git a/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.stories.js b/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.stories.js new file mode 100644 index 00000000000..77ce7053cfa --- /dev/null +++ b/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.stories.js @@ -0,0 +1,62 @@ +/** + * AdBlockerWarningWidget Component Stories. + * + * 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. + */ + +/** + * Internal dependencies + */ +import { MODULES_ADSENSE } from '../../datastore/constants'; +import { provideModules } from '../../../../../../tests/js/utils'; +import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util'; +import WithRegistrySetup from '../../../../../../tests/js/WithRegistrySetup'; +import AdBlockerWarningWidget from './AdBlockerWarningWidget'; + +const WidgetWithComponentProps = withWidgetComponentProps( 'adBlockerWarning' )( + AdBlockerWarningWidget +); + +const Template = () => ; + +export const Ready = Template.bind( {} ); +Ready.storyName = 'Ready'; + +export default { + title: 'Modules/AdSense/Widgets/AdBlockerWarning', + decorators: [ + ( Story ) => { + const setupRegistry = ( registry ) => { + provideModules( registry, [ + { + active: true, + connected: true, + slug: 'adsense', + }, + ] ); + + registry + .dispatch( MODULES_ADSENSE ) + .receiveIsAdBlockerActive( true ); + }; + + return ( + + + + ); + }, + ], +}; diff --git a/assets/js/modules/adsense/components/dashboard/index.js b/assets/js/modules/adsense/components/dashboard/index.js index 755feb844fb..881833d1d00 100644 --- a/assets/js/modules/adsense/components/dashboard/index.js +++ b/assets/js/modules/adsense/components/dashboard/index.js @@ -20,3 +20,4 @@ export { default as DashboardAdSenseTopPages } from './DashboardAdSenseTopPages' export { default as DashboardZeroData } from './DashboardZeroData'; export { default as DashboardSummaryWidget } from './DashboardSummaryWidget'; export { default as DashboardTopEarningPagesWidget } from './DashboardTopEarningPagesWidget'; +export { default as AdBlockerWarningWidget } from './AdBlockerWarningWidget'; diff --git a/assets/js/modules/adsense/index.js b/assets/js/modules/adsense/index.js index 953e39e62c0..b321cc9531a 100644 --- a/assets/js/modules/adsense/index.js +++ b/assets/js/modules/adsense/index.js @@ -38,6 +38,7 @@ import { import { DashboardSummaryWidget, DashboardTopEarningPagesWidget, + AdBlockerWarningWidget, } from './components/dashboard'; import ModuleTopEarningPagesWidget from './components/module/ModuleTopEarningPagesWidget'; import { ModuleOverviewWidget } from './components/module'; @@ -102,6 +103,21 @@ export const registerModule = ( modules ) => { }; export const registerWidgets = ( widgets ) => { + widgets.registerWidget( + 'adBlockerWarning', + { + Component: AdBlockerWarningWidget, + width: widgets.WIDGET_WIDTHS.FULL, + priority: 1, + wrapWidget: false, + }, + [ + isFeatureEnabled( 'unifiedDashboard' ) + ? AREA_MAIN_DASHBOARD_MONETIZATION_PRIMARY + : AREA_MODULE_ADSENSE_MAIN, + ] + ); + if ( ! isFeatureEnabled( 'unifiedDashboard' ) ) { widgets.registerWidget( 'adsenseSummary', @@ -134,7 +150,7 @@ export const registerWidgets = ( widgets ) => { { Component: ModuleOverviewWidget, width: widgets.WIDGET_WIDTHS.FULL, - priority: 1, + priority: 2, wrapWidget: false, }, [ diff --git a/assets/sass/admin.scss b/assets/sass/admin.scss index 32ee77a4d09..772f94c89c6 100644 --- a/assets/sass/admin.scss +++ b/assets/sass/admin.scss @@ -164,6 +164,7 @@ @import "widgets/widgets"; @import "widgets/googlesitekit-widget-adsense-performance"; @import "widgets/googlesitekit-widget-analyticsAllTraffic"; +@import "widgets/googlesitekit-widget-adBlockerWarning"; // Utilities @import "utilities/alignment"; diff --git a/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss b/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss new file mode 100644 index 00000000000..032bfa1e219 --- /dev/null +++ b/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss @@ -0,0 +1,30 @@ +/** + * AdSense AdBlocker Warning widget styles. + * + * 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. + */ + +.googlesitekit-plugin { + + .googlesitekit-widget--adBlockerWarning { + background-color: transparent; + box-shadow: none; + + .googlesitekit-widget__body { + padding-left: 0; + padding-right: 0; + } + } +} From c335dec4f6dc9fd430134bff0b3f1193c887b610 Mon Sep 17 00:00:00 2001 From: Arafat Zahan Date: Mon, 18 Oct 2021 12:03:42 +0600 Subject: [PATCH 2/8] Improve reauthenticate message for 'access_denied' error. --- .../Core/Authentication/Authentication.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/includes/Core/Authentication/Authentication.php b/includes/Core/Authentication/Authentication.php index 0340e99fc89..2ca5561f4a0 100644 --- a/includes/Core/Authentication/Authentication.php +++ b/includes/Core/Authentication/Authentication.php @@ -1079,18 +1079,27 @@ private function get_authentication_oauth_error_notice() { $message = $auth_client->get_error_message( $error_code ); $access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); + + $setup_url = ''; + if ( $this->credentials->using_proxy() ) { + $setup_url = esc_url( $auth_client->get_proxy_setup_url( $access_code ) ); + $this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); + } else { + $setup_url = esc_url( $this->context->admin_url( 'splash' ) ); + } + + if ( 'access_denied' === $error_code ) { $message .= ' ' . sprintf( - /* translators: %s: URL to re-authenticate */ - __( 'To fix this, redo the plugin setup.', 'google-site-kit' ), - esc_url( $auth_client->get_proxy_setup_url( $access_code ) ) + /* translators: %s: setup screen URL */ + __( 'To use Site Kit, you’ll need to redo the plugin setup – make sure to approve all permissions at the authentication stage.', 'google-site-kit' ), + $setup_url ); - $this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); } else { $message .= ' ' . sprintf( /* translators: %s: setup screen URL */ __( 'To fix this, redo the plugin setup.', 'google-site-kit' ), - esc_url( $this->context->admin_url( 'splash' ) ) + $setup_url ); } From eda6388c3f1b29b51a8cd2594e0e4bc9db1c4d95 Mon Sep 17 00:00:00 2001 From: Arafat Zahan Date: Tue, 19 Oct 2021 14:54:25 +0600 Subject: [PATCH 3/8] Fix `esc_url` position. --- includes/Core/Authentication/Authentication.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/Core/Authentication/Authentication.php b/includes/Core/Authentication/Authentication.php index 2ca5561f4a0..3b8563d7cf0 100644 --- a/includes/Core/Authentication/Authentication.php +++ b/includes/Core/Authentication/Authentication.php @@ -1080,26 +1080,24 @@ private function get_authentication_oauth_error_notice() { $message = $auth_client->get_error_message( $error_code ); $access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); - $setup_url = ''; - if ( $this->credentials->using_proxy() ) { - $setup_url = esc_url( $auth_client->get_proxy_setup_url( $access_code ) ); + $setup_url = $auth_client->get_proxy_setup_url( $access_code ); $this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); } else { - $setup_url = esc_url( $this->context->admin_url( 'splash' ) ); + $setup_url = $this->context->admin_url( 'splash' ); } if ( 'access_denied' === $error_code ) { $message .= ' ' . sprintf( /* translators: %s: setup screen URL */ __( 'To use Site Kit, you’ll need to redo the plugin setup – make sure to approve all permissions at the authentication stage.', 'google-site-kit' ), - $setup_url + esc_url( $setup_url ) ); } else { $message .= ' ' . sprintf( /* translators: %s: setup screen URL */ __( 'To fix this, redo the plugin setup.', 'google-site-kit' ), - $setup_url + esc_url( $setup_url ) ); } From d87082fd70ee449718dacc4a8759528ed75bf16a Mon Sep 17 00:00:00 2001 From: Arafat Zahan Date: Tue, 19 Oct 2021 20:20:22 +0600 Subject: [PATCH 4/8] Fix url for already authenticated users. --- includes/Core/Authentication/Authentication.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/Core/Authentication/Authentication.php b/includes/Core/Authentication/Authentication.php index 3b8563d7cf0..8555f950693 100644 --- a/includes/Core/Authentication/Authentication.php +++ b/includes/Core/Authentication/Authentication.php @@ -1077,14 +1077,22 @@ private function get_authentication_oauth_error_notice() { return ''; } - $message = $auth_client->get_error_message( $error_code ); - $access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); + $message = $auth_client->get_error_message( $error_code ); - if ( $this->credentials->using_proxy() ) { + if ( $this->is_authenticated() ) { + + $setup_url = $this->get_connect_url(); + + } elseif ( $this->credentials->using_proxy() ) { + + $access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); $setup_url = $auth_client->get_proxy_setup_url( $access_code ); $this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); + } else { + $setup_url = $this->context->admin_url( 'splash' ); + } if ( 'access_denied' === $error_code ) { From c1d90eaa69bfe1dacc99c1e0166f65c558d44360 Mon Sep 17 00:00:00 2001 From: Asvin Balloo Date: Tue, 19 Oct 2021 18:31:51 +0400 Subject: [PATCH 5/8] Remove padding from ad blocker widget. --- .../adsense/components/dashboard/AdBlockerWarningWidget.js | 2 +- .../sass/widgets/_googlesitekit-widget-adBlockerWarning.scss | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js b/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js index afc2a25ce84..24c4de22663 100644 --- a/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js +++ b/assets/js/modules/adsense/components/dashboard/AdBlockerWarningWidget.js @@ -40,7 +40,7 @@ function AdBlockerWarningWidget( { Widget } ) { } return ( - + ); diff --git a/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss b/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss index 032bfa1e219..0fee90d8ad4 100644 --- a/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss +++ b/assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss @@ -21,10 +21,5 @@ .googlesitekit-widget--adBlockerWarning { background-color: transparent; box-shadow: none; - - .googlesitekit-widget__body { - padding-left: 0; - padding-right: 0; - } } } From 7cba23dd1e9e50667047e15d8d795c1778f9da39 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Tue, 19 Oct 2021 17:46:49 +0300 Subject: [PATCH 6/8] Remove surrounding blank lines. --- includes/Core/Authentication/Authentication.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/includes/Core/Authentication/Authentication.php b/includes/Core/Authentication/Authentication.php index 8555f950693..e9534ae96e3 100644 --- a/includes/Core/Authentication/Authentication.php +++ b/includes/Core/Authentication/Authentication.php @@ -1080,19 +1080,13 @@ private function get_authentication_oauth_error_notice() { $message = $auth_client->get_error_message( $error_code ); if ( $this->is_authenticated() ) { - $setup_url = $this->get_connect_url(); - } elseif ( $this->credentials->using_proxy() ) { - $access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); $setup_url = $auth_client->get_proxy_setup_url( $access_code ); $this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE ); - } else { - $setup_url = $this->context->admin_url( 'splash' ); - } if ( 'access_denied' === $error_code ) { From 40d6d9108c0362c94943cb02eb6ead013937cf2d Mon Sep 17 00:00:00 2001 From: Asvin Balloo Date: Wed, 20 Oct 2021 12:21:40 +0400 Subject: [PATCH 7/8] Update AdSense blocker warning messages. --- assets/js/modules/adsense/datastore/adblocker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/modules/adsense/datastore/adblocker.js b/assets/js/modules/adsense/datastore/adblocker.js index 45659e62ef2..bf02b12f67f 100644 --- a/assets/js/modules/adsense/datastore/adblocker.js +++ b/assets/js/modules/adsense/datastore/adblocker.js @@ -171,13 +171,13 @@ export const selectors = { if ( isModuleConnected ) { return __( - 'Ad blocker detected, you need to disable it to get the latest AdSense data.', + 'Ad blocker detected; please disable it to get the latest AdSense data', 'google-site-kit' ); } return __( - 'Ad blocker detected, you need to disable it to set up AdSense.', + 'Ad blocker detected; please disable it to set up AdSense', 'google-site-kit' ); } From 312f37831f7962ebbf2f2df99e8ff4801b090247 Mon Sep 17 00:00:00 2001 From: "Matthew Riley MacPherson (tofumatt)" Date: Wed, 20 Oct 2021 10:31:53 +0100 Subject: [PATCH 8/8] Only load Analytics widget when Analytics is active. --- .../components/module/ModulePopularPagesWidget/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/js/modules/analytics/components/module/ModulePopularPagesWidget/index.js b/assets/js/modules/analytics/components/module/ModulePopularPagesWidget/index.js index 78bcf308ecc..a8859774e28 100644 --- a/assets/js/modules/analytics/components/module/ModulePopularPagesWidget/index.js +++ b/assets/js/modules/analytics/components/module/ModulePopularPagesWidget/index.js @@ -43,11 +43,12 @@ import TableOverflowContainer from '../../../../../components/TableOverflowConta import DetailsPermaLinks from '../../../../../components/DetailsPermaLinks'; import ReportTable from '../../../../../components/ReportTable'; import PreviewTable from '../../../../../components/PreviewTable'; +import whenActive from '../../../../../util/when-active'; import Header from './Header'; import Footer from './Footer'; const { useSelect } = Data; -export default function ModulePopularPagesWidget( props ) { +function ModulePopularPagesWidget( props ) { const { Widget, WidgetReportError, WidgetReportZero } = props; const isGatheringData = useSelect( ( select ) => @@ -212,3 +213,7 @@ ModulePopularPagesWidget.propTypes = { WidgetReportError: PropTypes.elementType.isRequired, WidgetReportZero: PropTypes.elementType.isRequired, }; + +export default whenActive( { moduleName: 'analytics' } )( + ModulePopularPagesWidget +);