From 169b5aee2ec4fcd9de8a7273e953f42ef4a4ce6e Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:06:12 +0530 Subject: [PATCH 01/27] =?UTF-8?q?=E2=9C=A8=20Register=20Tracking=20Handler?= =?UTF-8?q?=20Setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Settings.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/includes/Settings.php b/includes/Settings.php index 9c2b0f736c10..d61e424c977e 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -144,6 +144,11 @@ class Settings implements Service, Registerable, PluginUninstallAware { */ public const SETTING_NAME_DEFAULT_PAGE_DURATION = 'web_stories_default_page_duration'; + /** + * GA Tracking Handler. + */ + public const SETTING_NAME_TRACKING_HANDLER = 'web_stories_ga_tracking_handler'; + /** * Shopping_Vendors instance. * @@ -403,6 +408,22 @@ public function register(): void { 'show_in_rest' => true, ] ); + + register_setting( + self::SETTING_GROUP, + self::SETTING_NAME_TRACKING_HANDLER, + [ + 'description' => __( 'Tracking Handler', 'web-stories' ), + 'type' => 'string', + 'default' => 'site-kit', + 'show_in_rest' => [ + 'schema' => [ + 'type' => 'string', + 'enum' => [ 'site-kit', 'web-stories', 'both' ], + ], + ], + ] + ); } /** @@ -495,6 +516,7 @@ public function on_plugin_uninstall(): void { delete_option( self::SETTING_NAME_SHOPIFY_ACCESS_TOKEN ); delete_option( self::SETTING_NAME_DEFAULT_PAGE_DURATION ); delete_option( self::SETTING_NAME_AUTO_ADVANCE ); + delete_option( self::SETTING_NAME_TRACKING_HANDLER ); } /** From ae0b9f9bb97f8c0a3257452bf9b2cd161681f248 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:07:55 +0530 Subject: [PATCH 02/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20SiteKit?= =?UTF-8?q?=20`actions`=20and=20`filters`=20on=20`register`=20for=20flexib?= =?UTF-8?q?le=20tracking=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Integrations/Site_Kit.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/includes/Integrations/Site_Kit.php b/includes/Integrations/Site_Kit.php index 837f94c99434..3012a86bd3d8 100644 --- a/includes/Integrations/Site_Kit.php +++ b/includes/Integrations/Site_Kit.php @@ -31,6 +31,7 @@ use Google\Web_Stories\Analytics; use Google\Web_Stories\Context; use Google\Web_Stories\Service_Base; +use Google\Web_Stories\Settings; /** * Class Site_Kit. @@ -64,6 +65,13 @@ class Site_Kit extends Service_Base { */ private Plugin_Status $plugin_status; + /** + * Settings instance. + * + * @var Settings Settings instance. + */ + private Settings $settings; + /** * Constructor. * @@ -71,10 +79,11 @@ class Site_Kit extends Service_Base { * @param Context $context Context instance. * @param Plugin_Status $plugin_status Plugin_Status instance. */ - public function __construct( Analytics $analytics, Context $context, Plugin_Status $plugin_status ) { + public function __construct( Analytics $analytics, Context $context, Plugin_Status $plugin_status, Settings $settings ) { $this->analytics = $analytics; $this->context = $context; $this->plugin_status = $plugin_status; + $this->settings = $settings; } /** @@ -85,7 +94,19 @@ public function __construct( Analytics $analytics, Context $context, Plugin_Stat public function register(): void { add_filter( 'googlesitekit_amp_gtag_opt', [ $this, 'filter_site_kit_gtag_opt' ] ); - if ( $this->is_analytics_module_active() ) { + $handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER ); + + if ( 'web-stories' === $handler ) { + add_filter( + 'googlesitekit_analytics-4_tag_amp_blocked', + function ( $blocked ) { + if ( $this->context->is_web_story() ) { + return true; + } + return $blocked; + } + ); + } elseif ( 'site-kit' === $handler && $this->is_analytics_module_active() ) { remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] ); } } From e45af01054ecac644b406643662804bd2e8fb222 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:09:24 +0530 Subject: [PATCH 03/27] =?UTF-8?q?=E2=9C=A8=20Register=20Tracking=20Handler?= =?UTF-8?q?=20API=20for=20`wp-dashboard`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/wp-dashboard/src/api/reducers/settings.js | 3 +++ packages/wp-dashboard/src/api/settings.js | 6 ++++++ packages/wp-dashboard/src/constants/settings.js | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/packages/wp-dashboard/src/api/reducers/settings.js b/packages/wp-dashboard/src/api/reducers/settings.js index c59ce1d23ffe..26c5cb780792 100644 --- a/packages/wp-dashboard/src/api/reducers/settings.js +++ b/packages/wp-dashboard/src/api/reducers/settings.js @@ -20,6 +20,7 @@ import { AD_NETWORK_TYPE, ARCHIVE_TYPE, SHOPPING_PROVIDER_TYPE, + GOOGLE_ANALYTICS_HANDLER_TYPE, } from '../../constants'; export const ACTION_TYPES = { @@ -49,6 +50,7 @@ export const defaultSettingsState = { shopifyAccessToken: '', autoAdvance: true, defaultPageDuration: 7, + googleAnalyticsHandler: GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT, }; function settingsReducer(state, action) { @@ -89,6 +91,7 @@ function settingsReducer(state, action) { shopifyAccessToken: action.payload.shopifyAccessToken, autoAdvance: action.payload.autoAdvance, defaultPageDuration: action.payload.defaultPageDuration, + googleAnalyticsHandler: action.payload.googleAnalyticsHandler, }; } diff --git a/packages/wp-dashboard/src/api/settings.js b/packages/wp-dashboard/src/api/settings.js index 0566079d7df4..faaef4e44362 100644 --- a/packages/wp-dashboard/src/api/settings.js +++ b/packages/wp-dashboard/src/api/settings.js @@ -46,6 +46,7 @@ const transformSettingResponse = (response) => ({ shopifyAccessToken: response.web_stories_shopify_access_token, autoAdvance: Boolean(response.web_stories_auto_advance), defaultPageDuration: response.web_stories_default_page_duration, + googleAnalyticsHandler: response.web_stories_ga_tracking_handler, }); /** @@ -86,6 +87,7 @@ export function updateSettings(apiPath, queryParams) { shopifyAccessToken, autoAdvance, defaultPageDuration, + googleAnalyticsHandler, } = queryParams; const query = {}; @@ -154,6 +156,10 @@ export function updateSettings(apiPath, queryParams) { query.web_stories_default_page_duration = defaultPageDuration; } + if (googleAnalyticsHandler !== undefined) { + query.web_stories_ga_tracking_handler = googleAnalyticsHandler; + } + const path = addQueryArgs(apiPath, query); return apiFetch({ diff --git a/packages/wp-dashboard/src/constants/settings.js b/packages/wp-dashboard/src/constants/settings.js index 57b267d12014..652ee7c3996a 100644 --- a/packages/wp-dashboard/src/constants/settings.js +++ b/packages/wp-dashboard/src/constants/settings.js @@ -54,3 +54,9 @@ export const SHOPPING_PROVIDER_TYPE = { WOOCOMMERCE: 'woocommerce', SHOPIFY: 'shopify', }; + +export const GOOGLE_ANALYTICS_HANDLER_TYPE = { + SITE_KIT: 'site-kit', + WEB_STORIES: 'web-stories', + BOTH: 'both', +}; From 7eb0e5a68355a67b3de7c23acad1f712c45f3a24 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:10:46 +0530 Subject: [PATCH 04/27] =?UTF-8?q?=F0=9F=96=8D=20Register=20new=20setting?= =?UTF-8?q?=20UI=20with=20dropdown=20for=20flexible=20Tracking=20Handler?= =?UTF-8?q?=20selection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This dropdown will only be visible when SiteKit is installed & active. --- .../editorSettings/editorSettings.js | 13 ++ .../editorSettings/googleAnalytics/index.js | 199 +++++++++++------- 2 files changed, 134 insertions(+), 78 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/editorSettings.js b/packages/wp-dashboard/src/components/editorSettings/editorSettings.js index 3c9645fd643b..faf8acc5003a 100644 --- a/packages/wp-dashboard/src/components/editorSettings/editorSettings.js +++ b/packages/wp-dashboard/src/components/editorSettings/editorSettings.js @@ -85,6 +85,7 @@ function EditorSettings() { shopifyAccessToken, autoAdvance, defaultPageDuration, + googleAnalyticsHandler, } = useEditorSettings( ({ actions: { @@ -117,6 +118,7 @@ function EditorSettings() { shopifyAccessToken, autoAdvance, defaultPageDuration, + googleAnalyticsHandler, }, media: { isLoading: isMediaLoading, newlyCreatedMediaIds }, publisherLogos: { publisherLogos }, @@ -155,6 +157,7 @@ function EditorSettings() { shopifyAccessToken, autoAdvance, defaultPageDuration, + googleAnalyticsHandler, }) ); @@ -329,6 +332,12 @@ function EditorSettings() { [setPublisherLogoAsDefault] ); + const handleUpdateGoogleAnalyticsHandler = useCallback( + (newGoogleAnalyticsHandler) => + updateSettings({ googleAnalyticsHandler: newGoogleAnalyticsHandler }), + [updateSettings] + ); + return ( @@ -346,6 +355,10 @@ function EditorSettings() { usingLegacyAnalytics={usingLegacyAnalytics} handleMigrateLegacyAnalytics={handleMigrateLegacyAnalytics} siteKitStatus={siteKit} + googleAnalyticsHandler={googleAnalyticsHandler} + handleUpdateGoogleAnalyticsHandler={ + handleUpdateGoogleAnalyticsHandler + } /> { + setAnalyticsHandler(googleAnalyticsHandler); + }, [googleAnalyticsHandler]); + const onUpdateAnalyticsId = useCallback((event) => { const { value } = event.target; setAnalyticsId(value); @@ -136,6 +156,14 @@ function GoogleAnalyticsSettings({ setInputError(TEXT.INPUT_ERROR); }, []); + const onUpdateAnalyticsHandler = useCallback( + (value) => { + setAnalyticsHandler(value); + handleUpdateGoogleAnalyticsHandler(value); + }, + [handleUpdateGoogleAnalyticsHandler] + ); + const handleOnSave = useCallback(() => { if (canSave) { handleUpdateAnalyticsId(analyticsId); @@ -247,97 +275,110 @@ function GoogleAnalyticsSettings({ )}
- {analyticsActive ? ( - - {TEXT.SITE_KIT_IN_USE} - - ) : ( + + + {TEXT.ARIA_LABEL} + + + + {TEXT.SUBMIT_BUTTON} + + + + + ), + }} + > + {TEXT.CONTEXT} + + + {analyticsActive && ( <> - - - {TEXT.ARIA_LABEL} - - - - {TEXT.SUBMIT_BUTTON} - - + + {__('Note: ', 'web-stories')} + + {TEXT.SITE_KIT_IN_USE} + + + { + onUpdateAnalyticsHandler(newValue); + }} + selectedValue={analyticsHandler} + /> + + + )} + {!googleAnalyticsId || googleAnalyticsId.startsWith('UA-') ? ( + + + + trackClick(evt, 'click_ua_deprecation_docs') + } + /> + ), + a2: ( + trackClick(evt, 'click_ga4_docs')} /> ), }} > - {TEXT.CONTEXT} + {__( + 'As previously announced, Universal Analytics will stop processing new visits starting July 1, 2023. We recommend switching to Google Analytics 4 (GA4), our analytics product of record.', + 'web-stories' + )} - - {!googleAnalyticsId || googleAnalyticsId.startsWith('UA-') ? ( - - - - - trackClick(evt, 'click_ua_deprecation_docs') - } - /> - ), - a2: ( - trackClick(evt, 'click_ga4_docs')} - /> - ), - }} - > - {__( - 'As previously announced, Universal Analytics will stop processing new visits starting July 1, 2023. We recommend switching to Google Analytics 4 (GA4), our analytics product of record.', - 'web-stories' - )} - - - - ) : null} - - )} + + + ) : null}
); @@ -355,6 +396,8 @@ GoogleAnalyticsSettings.propTypes = { analyticsActive: PropTypes.bool, analyticsLink: PropTypes.string, }), + googleAnalyticsHandler: PropTypes.string, + handleUpdateGoogleAnalyticsHandler: PropTypes.func, }; export default GoogleAnalyticsSettings; From 1272da372bab969e93d7f3d78e956af70b13a612 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:29:26 +0530 Subject: [PATCH 05/27] =?UTF-8?q?=F0=9F=8F=97=20Add=20missing=20doc=20comm?= =?UTF-8?q?ent=20for=20parameter=20`$settings`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Integrations/Site_Kit.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/Integrations/Site_Kit.php b/includes/Integrations/Site_Kit.php index 3012a86bd3d8..145a05e5ccbc 100644 --- a/includes/Integrations/Site_Kit.php +++ b/includes/Integrations/Site_Kit.php @@ -78,6 +78,7 @@ class Site_Kit extends Service_Base { * @param Analytics $analytics Analytics instance. * @param Context $context Context instance. * @param Plugin_Status $plugin_status Plugin_Status instance. + * @param Settings $settings Settings instance. */ public function __construct( Analytics $analytics, Context $context, Plugin_Status $plugin_status, Settings $settings ) { $this->analytics = $analytics; From 9b6eae35104450ac3c530dc2c04f9d0c7c2acb7f Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:31:57 +0530 Subject: [PATCH 06/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20messages?= =?UTF-8?q?=20for=20translation=20markup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editorSettings/googleAnalytics/index.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index fc5e998a56c4..8b493827f943 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -80,15 +80,23 @@ export const TEXT = { 'web-stories' ), SITE_KIT_IN_USE: __( - 'Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.', + 'Note: Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.', 'web-stories' ), + ANALYTICS_DROPDOWN_LABEL: __('Analytics Type', 'web-stories'), + ANALYTICS_DROPDOWN_PLACEHOLDER: __('Select Analytics Type', 'web-stories'), }; const ANALYTICS_DROPDOWN_OPTIONS = [ - { value: 'site-kit', label: 'Use Site Kit for analytics (default)' }, - { value: 'web-stories', label: 'Use only Web Stories for analytics' }, - { value: 'both', label: 'Use both' }, + { + value: 'site-kit', + label: __('Use Site Kit for analytics (default)', 'web-stories'), + }, + { + value: 'web-stories', + label: __('Use only Web Stories for analytics', 'web-stories'), + }, + { value: 'both', label: __('Use both', 'web-stories') }, ]; const DropdownContainer = styled.div` @@ -288,6 +296,7 @@ function GoogleAnalyticsSettings({ placeholder={TEXT.PLACEHOLDER} hasError={Boolean(inputError)} hint={inputError} + disabled={analyticsActive} /> - - {__('Note: ', 'web-stories')} - - {TEXT.SITE_KIT_IN_USE} + {TEXT.SITE_KIT_IN_USE} { onUpdateAnalyticsHandler(newValue); From cba190c248ab37363cb0b586b28afbff103a6e8f Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:36:57 +0530 Subject: [PATCH 07/27] =?UTF-8?q?=F0=9F=A7=AA=20Update=20`editorSettings`?= =?UTF-8?q?=20unit-test=20to=20support=20for=20analytics=20dropdown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editorSettings/googleAnalytics/test/googleAnalytics.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index aa0edcec9e79..8c10cc13469a 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -76,7 +76,7 @@ describe('Editor Settings: Google Analytics ', () => { expect(label).toBeInTheDocument(); }); - it('should not display any input field when analytics module is active', () => { + it('should display input field and dropdown when analytics module is active', () => { renderWithProviders( ', () => { ); const input = screen.queryByRole('textbox'); - expect(input).not.toBeInTheDocument(); + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + expect(input).toBeInTheDocument(); + expect(dropdown).toBeInTheDocument(); }); it('should allow the input to be active when Site Kit is installed but analytics module is not active', () => { From 7049147f7c97c1a949c502fafb0218c9e2c3d1f8 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:37:53 +0530 Subject: [PATCH 08/27] =?UTF-8?q?=F0=9F=A7=AA=20Update=20`Site=5FKit`=20un?= =?UTF-8?q?it-test=20to=20support=20for=20newly=20added=20`Setting`=20para?= =?UTF-8?q?meter=20to=20the=20constructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/phpunit/integration/tests/Integrations/Site_Kit.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/integration/tests/Integrations/Site_Kit.php b/tests/phpunit/integration/tests/Integrations/Site_Kit.php index 878ee8e63e1b..165ce4717282 100644 --- a/tests/phpunit/integration/tests/Integrations/Site_Kit.php +++ b/tests/phpunit/integration/tests/Integrations/Site_Kit.php @@ -25,6 +25,7 @@ use Google\Web_Stories\Integrations\Plugin_Status; use Google\Web_Stories\Story_Post_Type; use Google\Web_Stories\Tests\Integration\DependencyInjectedTestCase; +use Google\Web_Stories\Settings; /** * @coversDefaultClass \Google\Web_Stories\Integrations\Site_Kit @@ -130,7 +131,8 @@ public function test_filter_site_kit_gtag_opt_single_story(): void { $this->instance = new \Google\Web_Stories\Integrations\Site_Kit( $analytics, $this->injector->make( Context::class ), - $this->injector->make( Plugin_Status::class ) + $this->injector->make( Plugin_Status::class ), + $this->injector->make( Settings::class ), ); $actual = $this->instance->filter_site_kit_gtag_opt( $gtag ); From 0d8d898a4ffdbc153249f52ca347e78e31691956 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:40:23 +0530 Subject: [PATCH 09/27] =?UTF-8?q?=F0=9F=A7=AA=20Add=20unit-test=20to=20`Si?= =?UTF-8?q?te=5FKit`=20to=20support=20for=20switching=20between=20SiteKit?= =?UTF-8?q?=20and=20GA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/Integrations/Site_Kit.php | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/tests/phpunit/integration/tests/Integrations/Site_Kit.php b/tests/phpunit/integration/tests/Integrations/Site_Kit.php index 165ce4717282..f61f8f534d5d 100644 --- a/tests/phpunit/integration/tests/Integrations/Site_Kit.php +++ b/tests/phpunit/integration/tests/Integrations/Site_Kit.php @@ -55,6 +55,103 @@ public function test_register(): void { $this->assertSame( 10, has_action( 'web_stories_print_analytics', [ $analytics, 'print_analytics_tag' ] ) ); } + /** + * @covers ::register + */ + public function test_analytics_tracking_handler_webstories(): void { + // Init Analytics Module. + \define( 'GOOGLESITEKIT_VERSION', '1.2.3' ); + + // Update flexible switching option. + update_option( 'web_stories_ga_tracking_handler', 'web-stories', false ); + + // Get Analytics Module. + $analytics = $this->container->get( 'analytics' ); + add_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ); + + // Register Site_Kit integration. + $this->instance->register(); + + // Check for filters & actions. + $this->assertSame( + 10, + has_filter( + 'googlesitekit_analytics-4_tag_amp_blocked', + function ( $blocked ) { + if ( $this->instance->context->is_web_story() ) { + return true; + } + return $blocked; + } + ) + ); + $this->assertSame( 10, has_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ) ); + } + + /** + * @covers ::register + */ + public function test_analytics_tracking_handler_site_kit(): void { + // Init Analytics Module. + \define( 'GOOGLESITEKIT_VERSION', '1.2.3' ); + + // Update flexible switching option. + update_option( 'web_stories_ga_tracking_handler', 'site-kit', false ); + + // Get Analytics Module. + $analytics = $this->container->get( 'analytics' ); + add_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ); + + // Register Site_Kit integration. + $this->instance->register(); + + // Check for filters & actions. + $this->assertFalse( + has_filter( + 'googlesitekit_analytics-4_tag_amp_blocked', + function ( $blocked ) { + if ( $this->instance->context->is_web_story() ) { + return true; + } + return $blocked; + } + ) + ); + $this->assertFalse( has_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ) ); + } + + /** + * @covers ::register + */ + public function test_analytics_tracking_handler_both(): void { + // Init Analytics Module. + \define( 'GOOGLESITEKIT_VERSION', '1.2.3' ); + + // Update flexible switching option. + update_option( 'web_stories_ga_tracking_handler', 'site-kit', false ); + + // Get Analytics Module. + $analytics = $this->container->get( 'analytics' ); + add_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ); + + // Register Site_Kit integration. + $this->instance->register(); + + // Check for filters & actions. + $this->assertFalse( + has_filter( + 'googlesitekit_analytics-4_tag_amp_blocked', + function ( $blocked ) { + if ( $this->instance->context->is_web_story() ) { + return true; + } + return $blocked; + } + ) + ); + $this->assertSame( 10, has_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ) ); + } + /** * @covers ::register * @covers ::is_analytics_module_active From 860c1b0324ae4ae95e8a6b55b18cad24b82d278e Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:19:53 +0530 Subject: [PATCH 10/27] =?UTF-8?q?=E2=8F=AA=20Revert=20added=20PHPUnit=20te?= =?UTF-8?q?sts=20in=20`Site=5FKit`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/Integrations/Site_Kit.php | 97 ------------------- 1 file changed, 97 deletions(-) diff --git a/tests/phpunit/integration/tests/Integrations/Site_Kit.php b/tests/phpunit/integration/tests/Integrations/Site_Kit.php index f61f8f534d5d..165ce4717282 100644 --- a/tests/phpunit/integration/tests/Integrations/Site_Kit.php +++ b/tests/phpunit/integration/tests/Integrations/Site_Kit.php @@ -55,103 +55,6 @@ public function test_register(): void { $this->assertSame( 10, has_action( 'web_stories_print_analytics', [ $analytics, 'print_analytics_tag' ] ) ); } - /** - * @covers ::register - */ - public function test_analytics_tracking_handler_webstories(): void { - // Init Analytics Module. - \define( 'GOOGLESITEKIT_VERSION', '1.2.3' ); - - // Update flexible switching option. - update_option( 'web_stories_ga_tracking_handler', 'web-stories', false ); - - // Get Analytics Module. - $analytics = $this->container->get( 'analytics' ); - add_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ); - - // Register Site_Kit integration. - $this->instance->register(); - - // Check for filters & actions. - $this->assertSame( - 10, - has_filter( - 'googlesitekit_analytics-4_tag_amp_blocked', - function ( $blocked ) { - if ( $this->instance->context->is_web_story() ) { - return true; - } - return $blocked; - } - ) - ); - $this->assertSame( 10, has_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ) ); - } - - /** - * @covers ::register - */ - public function test_analytics_tracking_handler_site_kit(): void { - // Init Analytics Module. - \define( 'GOOGLESITEKIT_VERSION', '1.2.3' ); - - // Update flexible switching option. - update_option( 'web_stories_ga_tracking_handler', 'site-kit', false ); - - // Get Analytics Module. - $analytics = $this->container->get( 'analytics' ); - add_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ); - - // Register Site_Kit integration. - $this->instance->register(); - - // Check for filters & actions. - $this->assertFalse( - has_filter( - 'googlesitekit_analytics-4_tag_amp_blocked', - function ( $blocked ) { - if ( $this->instance->context->is_web_story() ) { - return true; - } - return $blocked; - } - ) - ); - $this->assertFalse( has_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ) ); - } - - /** - * @covers ::register - */ - public function test_analytics_tracking_handler_both(): void { - // Init Analytics Module. - \define( 'GOOGLESITEKIT_VERSION', '1.2.3' ); - - // Update flexible switching option. - update_option( 'web_stories_ga_tracking_handler', 'site-kit', false ); - - // Get Analytics Module. - $analytics = $this->container->get( 'analytics' ); - add_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ); - - // Register Site_Kit integration. - $this->instance->register(); - - // Check for filters & actions. - $this->assertFalse( - has_filter( - 'googlesitekit_analytics-4_tag_amp_blocked', - function ( $blocked ) { - if ( $this->instance->context->is_web_story() ) { - return true; - } - return $blocked; - } - ) - ); - $this->assertSame( 10, has_action( 'web_stories_print_analytics', array( $analytics, 'print_analytics_tag' ) ) ); - } - /** * @covers ::register * @covers ::is_analytics_module_active From 82a7b4a4147494487e8b44948e70675cc99c35be Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:20:36 +0530 Subject: [PATCH 11/27] =?UTF-8?q?=F0=9F=A7=AA=20Add=20E2E=20unit=20tests?= =?UTF-8?q?=20for=20`Site=5FKit`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/specs/integrations/sitekit.js | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/e2e-tests/src/specs/integrations/sitekit.js b/packages/e2e-tests/src/specs/integrations/sitekit.js index 7783935c49ff..7b5d228bf330 100644 --- a/packages/e2e-tests/src/specs/integrations/sitekit.js +++ b/packages/e2e-tests/src/specs/integrations/sitekit.js @@ -27,6 +27,15 @@ import { trashAllPosts, } from '@web-stories-wp/e2e-test-utils'; +const DROPDOWN_LABELS = { + SITE_KIT: 'Use Site Kit for analytics (default)', + WEB_STORIES: 'Use only Web Stories for analytics', + BOTH: 'Use both', +}; + +const SITE_KIT_MESSAGE = + 'Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.'; + jest.retryTimes(3, { logErrorsBeforeRetry: true }); describe('Site Kit plugin integration', () => { @@ -34,12 +43,30 @@ describe('Site Kit plugin integration', () => { withPlugin('e2e-tests-site-kit-analytics-mock'); describe('Dashboard', () => { - it('should see Site Kit specific message', async () => { + beforeAll(async () => { await visitSettings(); + await page.click('button[aria-label="Analytics Type"]'); + }); - await expect(page).toMatchTextContent( - 'Site Kit by Google has already enabled Google Analytics for your Web Stories' - ); + it('should Site Kit specific message on selecting Site Kit', async () => { + await expect(page).toClick('[role="listbox"] li', { + text: DROPDOWN_LABELS.SITE_KIT, + }); + await expect(page).toMatchTextContent(SITE_KIT_MESSAGE); + }); + + it('should not see Site Kit specific message on selecting web stories', async () => { + await expect(page).toClick('[role="listbox"] li', { + text: DROPDOWN_LABELS.WEB_STORIES, + }); + await expect(page).not.toMatchTextContent(SITE_KIT_MESSAGE); + }); + + it('should not see Site Kit specific message on selecting both', async () => { + await expect(page).toClick('[role="listbox"] li', { + text: DROPDOWN_LABELS.BOTH, + }); + await expect(page).not.toMatchTextContent(SITE_KIT_MESSAGE); }); }); @@ -69,7 +96,7 @@ describe('Site Kit plugin integration', () => { withPlugin('e2e-tests-site-kit-adsense-mock'); describe('Dashboard', () => { - it('should see Site Kit specific message', async () => { + it('should see Google AdSense specific message', async () => { await visitSettings(); await expect(page).toMatchTextContent( From 9481a773fa39e88779c822472176a1504b398b5c Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:28:33 +0530 Subject: [PATCH 12/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Display=20`Site=5FKi?= =?UTF-8?q?t`=20note=20only=20when=20it=20is=20active?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editorSettings/googleAnalytics/index.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index 8b493827f943..d1432cfdba2e 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -36,6 +36,7 @@ import { Link, DropDown, } from '@googleforcreators/design-system'; +import { GOOGLE_ANALYTICS_HANDLER_TYPE } from '../../../constants/settings'; import styled from 'styled-components'; /** @@ -89,14 +90,17 @@ export const TEXT = { const ANALYTICS_DROPDOWN_OPTIONS = [ { - value: 'site-kit', + value: GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT, label: __('Use Site Kit for analytics (default)', 'web-stories'), }, { - value: 'web-stories', + value: GOOGLE_ANALYTICS_HANDLER_TYPE.WEB_STORIES, label: __('Use only Web Stories for analytics', 'web-stories'), }, - { value: 'both', label: __('Use both', 'web-stories') }, + { + value: GOOGLE_ANALYTICS_HANDLER_TYPE.BOTH, + label: __('Use both', 'web-stories'), + }, ]; const DropdownContainer = styled.div` @@ -326,9 +330,13 @@ function GoogleAnalyticsSettings({ {analyticsActive && ( <> - - {TEXT.SITE_KIT_IN_USE} - + {analyticsHandler === GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT && ( + + + {TEXT.SITE_KIT_IN_USE} + + + )} Date: Fri, 9 Feb 2024 15:40:30 +0530 Subject: [PATCH 13/27] Remove e2e tests that check if SiteKit message is displayed --- .../src/specs/integrations/sitekit.js | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/packages/e2e-tests/src/specs/integrations/sitekit.js b/packages/e2e-tests/src/specs/integrations/sitekit.js index 7b5d228bf330..42484abef727 100644 --- a/packages/e2e-tests/src/specs/integrations/sitekit.js +++ b/packages/e2e-tests/src/specs/integrations/sitekit.js @@ -42,34 +42,6 @@ describe('Site Kit plugin integration', () => { describe('Google Analytics', () => { withPlugin('e2e-tests-site-kit-analytics-mock'); - describe('Dashboard', () => { - beforeAll(async () => { - await visitSettings(); - await page.click('button[aria-label="Analytics Type"]'); - }); - - it('should Site Kit specific message on selecting Site Kit', async () => { - await expect(page).toClick('[role="listbox"] li', { - text: DROPDOWN_LABELS.SITE_KIT, - }); - await expect(page).toMatchTextContent(SITE_KIT_MESSAGE); - }); - - it('should not see Site Kit specific message on selecting web stories', async () => { - await expect(page).toClick('[role="listbox"] li', { - text: DROPDOWN_LABELS.WEB_STORIES, - }); - await expect(page).not.toMatchTextContent(SITE_KIT_MESSAGE); - }); - - it('should not see Site Kit specific message on selecting both', async () => { - await expect(page).toClick('[role="listbox"] li', { - text: DROPDOWN_LABELS.BOTH, - }); - await expect(page).not.toMatchTextContent(SITE_KIT_MESSAGE); - }); - }); - describe('Editor', () => { afterAll(async () => { await trashAllPosts('web-story'); From 383dee834e79fec6a7ed8ea3d7cf1a2ea3c1a95f Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Fri, 9 Feb 2024 15:44:45 +0530 Subject: [PATCH 14/27] Add component tests for ``: 1. Check if dropdown has rendered 2. Check if SiteKit specific message is displayed 3. Check if `handleUpdateGoogleAnalyticsHandler` is called with the appropriate values --- .../googleAnalytics/test/googleAnalytics.js | 102 +++++++++++++++++- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index 8c10cc13469a..adc8039a09f8 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -16,17 +16,34 @@ /** * External dependencies */ -import { fireEvent, screen } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; /** * Internal dependencies */ -import GoogleAnalyticsSettings, { TEXT } from '..'; +import GoogleAnalyticsSettings, { TEXT, ANALYTICS_DROPDOWN_OPTIONS } from '..'; import { renderWithProviders } from '../../../../testUtils'; +import { describe } from 'node:test'; + +const DROPDOWN_LABELS = { + SITE_KIT: 'Use Site Kit for analytics (default)', + WEB_STORIES: 'Use only Web Stories for analytics', + BOTH: 'Use both', +}; + +const SITE_KIT_MESSAGE = + 'Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.'; + +const SITE_KIT_MESSAGE_TEST_DATA = [ + ['show', DROPDOWN_LABELS.SITE_KIT, true], + ['not show', DROPDOWN_LABELS.WEB_STORIES, false], + ['not show', DROPDOWN_LABELS.BOTH, false], +]; describe('Editor Settings: Google Analytics ', () => { let googleAnalyticsId; let mockUpdate; + let mockHandleUpdateGoogleAnalyticsHandler; const defaultSiteKitStatus = { installed: false, analyticsActive: false, @@ -38,6 +55,7 @@ describe('Editor Settings: Google Analytics ', () => { mockUpdate = jest.fn((id) => { googleAnalyticsId = id; }); + mockHandleUpdateGoogleAnalyticsHandler = jest.fn(); }); afterEach(() => { @@ -76,7 +94,7 @@ describe('Editor Settings: Google Analytics ', () => { expect(label).toBeInTheDocument(); }); - it('should display input field and dropdown when analytics module is active', () => { + it('should display input field when analytics module is active', () => { renderWithProviders( ', () => { ); const input = screen.queryByRole('textbox'); - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); expect(input).toBeInTheDocument(); + }); + + it('should display analytics type dropdown when analytics module is active', () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); expect(dropdown).toBeInTheDocument(); }); @@ -214,4 +248,64 @@ describe('Editor Settings: Google Analytics ', () => { expect(mockUpdate).toHaveBeenCalledTimes(2); }); + + it.each(SITE_KIT_MESSAGE_TEST_DATA)( + 'should %s specific message on selecting %s', + (_, optionLabel, shouldDisplayMessage) => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); + + const optionElement = screen.getByText(optionLabel); + fireEvent.click(optionElement); + + if (shouldDisplayMessage) { + expect(screen.queryByText(SITE_KIT_MESSAGE)).toBeInTheDocument(); + } else { + expect(screen.queryByText(SITE_KIT_MESSAGE)).not.toBeInTheDocument(); + } + } + ); + + it('should call handleUpdateGoogleAnalyticsHandler when the dropdown value changes', () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); + + ANALYTICS_DROPDOWN_OPTIONS.forEach((option) => { + const optionElement = screen.getByText(option.label); + fireEvent.click(optionElement); + expect(mockHandleUpdateGoogleAnalyticsHandler).toHaveBeenCalledWith( + option.value + ); + }); + }); }); From 5fbcae4b4deaea841b63015c42593cee97498272 Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Fri, 9 Feb 2024 15:45:08 +0530 Subject: [PATCH 15/27] Export `ANALYTICS_DROPDOWN_OPTIONS` to be used in tests --- .../src/components/editorSettings/googleAnalytics/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index d1432cfdba2e..38151a01386d 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -88,7 +88,7 @@ export const TEXT = { ANALYTICS_DROPDOWN_PLACEHOLDER: __('Select Analytics Type', 'web-stories'), }; -const ANALYTICS_DROPDOWN_OPTIONS = [ +export const ANALYTICS_DROPDOWN_OPTIONS = [ { value: GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT, label: __('Use Site Kit for analytics (default)', 'web-stories'), From 00d77d1fc2be79db62f5e157eb6447d6dce78d41 Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Fri, 9 Feb 2024 15:50:15 +0530 Subject: [PATCH 16/27] Remove unused constants --- packages/e2e-tests/src/specs/integrations/sitekit.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/e2e-tests/src/specs/integrations/sitekit.js b/packages/e2e-tests/src/specs/integrations/sitekit.js index 42484abef727..59fe07717d09 100644 --- a/packages/e2e-tests/src/specs/integrations/sitekit.js +++ b/packages/e2e-tests/src/specs/integrations/sitekit.js @@ -27,15 +27,6 @@ import { trashAllPosts, } from '@web-stories-wp/e2e-test-utils'; -const DROPDOWN_LABELS = { - SITE_KIT: 'Use Site Kit for analytics (default)', - WEB_STORIES: 'Use only Web Stories for analytics', - BOTH: 'Use both', -}; - -const SITE_KIT_MESSAGE = - 'Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.'; - jest.retryTimes(3, { logErrorsBeforeRetry: true }); describe('Site Kit plugin integration', () => { From 06827535ed51c412006633f54adc1988617d3d72 Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Fri, 9 Feb 2024 19:27:24 +0530 Subject: [PATCH 17/27] Fix eslint issues --- .../editorSettings/googleAnalytics/index.js | 6 +- .../googleAnalytics/test/googleAnalytics.js | 108 ++++++++++++------ 2 files changed, 77 insertions(+), 37 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index 38151a01386d..320c90be499d 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -36,7 +36,10 @@ import { Link, DropDown, } from '@googleforcreators/design-system'; -import { GOOGLE_ANALYTICS_HANDLER_TYPE } from '../../../constants/settings'; + +/** + * External dependencies + */ import styled from 'styled-components'; /** @@ -54,6 +57,7 @@ import { TextInputHelperText, VisuallyHiddenLabel, } from '../components'; +import { GOOGLE_ANALYTICS_HANDLER_TYPE } from '../../../constants/settings'; const StyledNotificationBubble = styled(NotificationBubble)` display: inline-block; diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index adc8039a09f8..0000ac1f3150 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -16,14 +16,13 @@ /** * External dependencies */ -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, screen } from '@testing-library/react'; /** * Internal dependencies */ import GoogleAnalyticsSettings, { TEXT, ANALYTICS_DROPDOWN_OPTIONS } from '..'; import { renderWithProviders } from '../../../../testUtils'; -import { describe } from 'node:test'; const DROPDOWN_LABELS = { SITE_KIT: 'Use Site Kit for analytics (default)', @@ -34,12 +33,6 @@ const DROPDOWN_LABELS = { const SITE_KIT_MESSAGE = 'Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.'; -const SITE_KIT_MESSAGE_TEST_DATA = [ - ['show', DROPDOWN_LABELS.SITE_KIT, true], - ['not show', DROPDOWN_LABELS.WEB_STORIES, false], - ['not show', DROPDOWN_LABELS.BOTH, false], -]; - describe('Editor Settings: Google Analytics ', () => { let googleAnalyticsId; let mockUpdate; @@ -249,37 +242,80 @@ describe('Editor Settings: Google Analytics ', () => { expect(mockUpdate).toHaveBeenCalledTimes(2); }); - it.each(SITE_KIT_MESSAGE_TEST_DATA)( - 'should %s specific message on selecting %s', - (_, optionLabel, shouldDisplayMessage) => { - renderWithProviders( - - ); + it(`should show Site Kit specific message on selecting ${DROPDOWN_LABELS.SITE_KIT}`, () => { + renderWithProviders( + + ); - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); - const optionElement = screen.getByText(optionLabel); - fireEvent.click(optionElement); + const optionElement = screen.getByText(DROPDOWN_LABELS.SITE_KIT); + fireEvent.click(optionElement); + + expect(screen.getByText(SITE_KIT_MESSAGE)).toBeInTheDocument(); + }); + + it(`should not show Site Kit specific message on selecting ${DROPDOWN_LABELS.WEB_STORIES}`, () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); - if (shouldDisplayMessage) { - expect(screen.queryByText(SITE_KIT_MESSAGE)).toBeInTheDocument(); - } else { - expect(screen.queryByText(SITE_KIT_MESSAGE)).not.toBeInTheDocument(); - } - } - ); + const optionElement = screen.getByText(DROPDOWN_LABELS.WEB_STORIES); + fireEvent.click(optionElement); + + expect(screen.queryByText(SITE_KIT_MESSAGE)).not.toBeInTheDocument(); + }); + + it(`should not show Site Kit specific message on selecting ${DROPDOWN_LABELS.BOTH}`, () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); + + const optionElement = screen.getByText(DROPDOWN_LABELS.BOTH); + fireEvent.click(optionElement); + + expect(screen.queryByText(SITE_KIT_MESSAGE)).not.toBeInTheDocument(); + }); it('should call handleUpdateGoogleAnalyticsHandler when the dropdown value changes', () => { renderWithProviders( From 38ce65ceb0b1a56fa2bba52c869ae0520b338769 Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Fri, 9 Feb 2024 19:27:44 +0530 Subject: [PATCH 18/27] Fix phpcs issues --- tests/phpunit/integration/tests/Integrations/Site_Kit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/integration/tests/Integrations/Site_Kit.php b/tests/phpunit/integration/tests/Integrations/Site_Kit.php index 165ce4717282..27d22a9cb1a0 100644 --- a/tests/phpunit/integration/tests/Integrations/Site_Kit.php +++ b/tests/phpunit/integration/tests/Integrations/Site_Kit.php @@ -23,9 +23,9 @@ use Google\Web_Stories\Analytics; use Google\Web_Stories\Context; use Google\Web_Stories\Integrations\Plugin_Status; +use Google\Web_Stories\Settings; use Google\Web_Stories\Story_Post_Type; use Google\Web_Stories\Tests\Integration\DependencyInjectedTestCase; -use Google\Web_Stories\Settings; /** * @coversDefaultClass \Google\Web_Stories\Integrations\Site_Kit From c8fe3bd5abbc4e1812a3d54cc4f958e799cd4949 Mon Sep 17 00:00:00 2001 From: AnuragVasanwala <75766877+AnuragVasanwala@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:00:14 +0530 Subject: [PATCH 19/27] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Restrict=20tracking?= =?UTF-8?q?-id=20input=20only=20when=20`analyticsActive`=20is=20active=20a?= =?UTF-8?q?nd=20`analyticsHandler`=20is=20`site-kit`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/editorSettings/googleAnalytics/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index 320c90be499d..df1aefbce152 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -304,7 +304,7 @@ function GoogleAnalyticsSettings({ placeholder={TEXT.PLACEHOLDER} hasError={Boolean(inputError)} hint={inputError} - disabled={analyticsActive} + disabled={analyticsActive && analyticsHandler === GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT} /> Date: Tue, 13 Feb 2024 11:19:28 +0530 Subject: [PATCH 20/27] Fix eslint issues in `googleAnalytics/index.js` --- .../src/components/editorSettings/googleAnalytics/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index df1aefbce152..14e0adc82527 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -304,7 +304,10 @@ function GoogleAnalyticsSettings({ placeholder={TEXT.PLACEHOLDER} hasError={Boolean(inputError)} hint={inputError} - disabled={analyticsActive && analyticsHandler === GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT} + disabled={ + analyticsActive && + analyticsHandler === GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT + } /> Date: Tue, 13 Feb 2024 11:46:08 +0530 Subject: [PATCH 21/27] Add tests to check if the Google Anaytics ID input is enabled/disabled on changing the dropdown option --- .../googleAnalytics/test/googleAnalytics.js | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index 0000ac1f3150..7678dcc8aff5 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -344,4 +344,82 @@ describe('Editor Settings: Google Analytics ', () => { ); }); }); + + it(`should not allow the Google Analytics ID input to be active on selecting ${DROPDOWN_LABELS.SITE_KIT}`, () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); + + const optionElement = screen.getByText(DROPDOWN_LABELS.SITE_KIT); + fireEvent.click(optionElement); + + const input = screen.getByRole('textbox'); + expect(input).toBeDisabled(); + }); + + it(`should allow the Google Analytics ID input to be active on selecting ${DROPDOWN_LABELS.WEB_STORIES}`, () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); + + const optionElement = screen.getByText(DROPDOWN_LABELS.WEB_STORIES); + fireEvent.click(optionElement); + + const input = screen.getByRole('textbox'); + expect(input).toBeEnabled(); + }); + + it(`should allow the Google Analytics ID input on selecting ${DROPDOWN_LABELS.BOTH}`, () => { + renderWithProviders( + + ); + + const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); + fireEvent.click(dropdown); + + const optionElement = screen.getByText(DROPDOWN_LABELS.BOTH); + fireEvent.click(optionElement); + + const input = screen.getByRole('textbox'); + expect(input).toBeEnabled(); + }); }); From b86ae3c8e819e7cbc08d056084e53b5dcf8e3ac2 Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Tue, 13 Feb 2024 19:07:05 +0530 Subject: [PATCH 22/27] Update Site Kit note text and display it regardless of option chosen in dropdown --- .../editorSettings/googleAnalytics/index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index 14e0adc82527..3a9d69e07d41 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -85,7 +85,7 @@ export const TEXT = { 'web-stories' ), SITE_KIT_IN_USE: __( - 'Note: Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.', + 'Note: If Site Kit is active, it will be used to set up Google Analytics by default. However, you can customize the behavior in case you need more flexibility.', 'web-stories' ), ANALYTICS_DROPDOWN_LABEL: __('Analytics Type', 'web-stories'), @@ -337,13 +337,9 @@ function GoogleAnalyticsSettings({ {analyticsActive && ( <> - {analyticsHandler === GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT && ( - - - {TEXT.SITE_KIT_IN_USE} - - - )} + + {TEXT.SITE_KIT_IN_USE} + Date: Tue, 13 Feb 2024 19:07:51 +0530 Subject: [PATCH 23/27] Update tests for the Site Kit note --- .../googleAnalytics/test/googleAnalytics.js | 67 ++----------------- 1 file changed, 4 insertions(+), 63 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index 7678dcc8aff5..209cc76afa81 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -30,8 +30,7 @@ const DROPDOWN_LABELS = { BOTH: 'Use both', }; -const SITE_KIT_MESSAGE = - 'Site Kit by Google has already enabled Google Analytics for your Web Stories, all changes to your analytics tracking should occur there.'; +const SITE_KIT_MESSAGE = TEXT.SITE_KIT_IN_USE.replace('Note: ', ''); describe('Editor Settings: Google Analytics ', () => { let googleAnalyticsId; @@ -242,81 +241,23 @@ describe('Editor Settings: Google Analytics ', () => { expect(mockUpdate).toHaveBeenCalledTimes(2); }); - it(`should show Site Kit specific message on selecting ${DROPDOWN_LABELS.SITE_KIT}`, () => { + it('should display Site Kit message when analytics module is active', () => { renderWithProviders( ); - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); - - const optionElement = screen.getByText(DROPDOWN_LABELS.SITE_KIT); - fireEvent.click(optionElement); - expect(screen.getByText(SITE_KIT_MESSAGE)).toBeInTheDocument(); }); - it(`should not show Site Kit specific message on selecting ${DROPDOWN_LABELS.WEB_STORIES}`, () => { - renderWithProviders( - - ); - - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); - - const optionElement = screen.getByText(DROPDOWN_LABELS.WEB_STORIES); - fireEvent.click(optionElement); - - expect(screen.queryByText(SITE_KIT_MESSAGE)).not.toBeInTheDocument(); - }); - - it(`should not show Site Kit specific message on selecting ${DROPDOWN_LABELS.BOTH}`, () => { - renderWithProviders( - - ); - - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); - - const optionElement = screen.getByText(DROPDOWN_LABELS.BOTH); - fireEvent.click(optionElement); - - expect(screen.queryByText(SITE_KIT_MESSAGE)).not.toBeInTheDocument(); - }); - it('should call handleUpdateGoogleAnalyticsHandler when the dropdown value changes', () => { renderWithProviders( ', () => { expect(input).toBeEnabled(); }); - it(`should allow the Google Analytics ID input on selecting ${DROPDOWN_LABELS.BOTH}`, () => { + it(`should allow the Google Analytics ID input to be active on selecting ${DROPDOWN_LABELS.BOTH}`, () => { renderWithProviders( Date: Thu, 15 Feb 2024 19:37:54 +0530 Subject: [PATCH 24/27] Remove restriction where measurement ID field is disabled when the "Use Site Kit" option is chosen --- .../src/components/editorSettings/googleAnalytics/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index 3a9d69e07d41..b1d95cd4f68e 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -304,10 +304,7 @@ function GoogleAnalyticsSettings({ placeholder={TEXT.PLACEHOLDER} hasError={Boolean(inputError)} hint={inputError} - disabled={ - analyticsActive && - analyticsHandler === GOOGLE_ANALYTICS_HANDLER_TYPE.SITE_KIT - } + disabled={analyticsActive} /> Date: Thu, 15 Feb 2024 19:38:34 +0530 Subject: [PATCH 25/27] Update tests for measurement ID input --- .../googleAnalytics/test/googleAnalytics.js | 84 ------------------- 1 file changed, 84 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index 209cc76afa81..36a3152cee3e 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -24,12 +24,6 @@ import { fireEvent, screen } from '@testing-library/react'; import GoogleAnalyticsSettings, { TEXT, ANALYTICS_DROPDOWN_OPTIONS } from '..'; import { renderWithProviders } from '../../../../testUtils'; -const DROPDOWN_LABELS = { - SITE_KIT: 'Use Site Kit for analytics (default)', - WEB_STORIES: 'Use only Web Stories for analytics', - BOTH: 'Use both', -}; - const SITE_KIT_MESSAGE = TEXT.SITE_KIT_IN_USE.replace('Note: ', ''); describe('Editor Settings: Google Analytics ', () => { @@ -285,82 +279,4 @@ describe('Editor Settings: Google Analytics ', () => { ); }); }); - - it(`should not allow the Google Analytics ID input to be active on selecting ${DROPDOWN_LABELS.SITE_KIT}`, () => { - renderWithProviders( - - ); - - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); - - const optionElement = screen.getByText(DROPDOWN_LABELS.SITE_KIT); - fireEvent.click(optionElement); - - const input = screen.getByRole('textbox'); - expect(input).toBeDisabled(); - }); - - it(`should allow the Google Analytics ID input to be active on selecting ${DROPDOWN_LABELS.WEB_STORIES}`, () => { - renderWithProviders( - - ); - - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); - - const optionElement = screen.getByText(DROPDOWN_LABELS.WEB_STORIES); - fireEvent.click(optionElement); - - const input = screen.getByRole('textbox'); - expect(input).toBeEnabled(); - }); - - it(`should allow the Google Analytics ID input to be active on selecting ${DROPDOWN_LABELS.BOTH}`, () => { - renderWithProviders( - - ); - - const dropdown = screen.getByLabelText(TEXT.ANALYTICS_DROPDOWN_LABEL); - fireEvent.click(dropdown); - - const optionElement = screen.getByText(DROPDOWN_LABELS.BOTH); - fireEvent.click(optionElement); - - const input = screen.getByRole('textbox'); - expect(input).toBeEnabled(); - }); }); From 11334485a88b05bd93880de217292d60163a89a7 Mon Sep 17 00:00:00 2001 From: Swanand Mathekar Date: Thu, 15 Feb 2024 20:47:32 +0530 Subject: [PATCH 26/27] Remove disable restriction for measurement ID input --- .../src/components/editorSettings/googleAnalytics/index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js index b1d95cd4f68e..d402fd60273a 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/index.js @@ -36,10 +36,6 @@ import { Link, DropDown, } from '@googleforcreators/design-system'; - -/** - * External dependencies - */ import styled from 'styled-components'; /** @@ -304,7 +300,6 @@ function GoogleAnalyticsSettings({ placeholder={TEXT.PLACEHOLDER} hasError={Boolean(inputError)} hint={inputError} - disabled={analyticsActive} /> Date: Thu, 15 Feb 2024 20:48:23 +0530 Subject: [PATCH 27/27] Remove redundant test that checked if the measurement ID input is enabled --- .../googleAnalytics/test/googleAnalytics.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js index 36a3152cee3e..249904279797 100644 --- a/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js +++ b/packages/wp-dashboard/src/components/editorSettings/googleAnalytics/test/googleAnalytics.js @@ -116,24 +116,6 @@ describe('Editor Settings: Google Analytics ', () => { expect(dropdown).toBeInTheDocument(); }); - it('should allow the input to be active when Site Kit is installed but analytics module is not active', () => { - renderWithProviders( - - ); - - const input = screen.getByRole('textbox'); - expect(input).toBeEnabled(); - }); - it('should call mockUpdate when enter is keyed on input', () => { const { rerender } = renderWithProviders(