Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue / 9489 Split Sell Products or Services Answers #9629

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from

Conversation

10upsimon
Copy link
Collaborator

@10upsimon 10upsimon commented Nov 7, 2024

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link

github-actions bot commented Nov 7, 2024

Build files for fd4a7c7 are ready:

Copy link

github-actions bot commented Nov 7, 2024

Size Change: -172 B (-0.01%)

Total Size: 1.88 MB

Filename Size Change
./dist/assets/js/googlesitekit-activation-********************.js 24 kB -2 B (-0.01%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 54.9 kB -21 B (-0.04%)
./dist/assets/js/googlesitekit-adminbar-********************.js 34.6 kB -16 B (-0.05%)
./dist/assets/js/googlesitekit-api-********************.js 10.1 kB -35 B (-0.35%)
./dist/assets/js/googlesitekit-components-gm2-********************.js 6.17 kB -2 B (-0.03%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 8.95 kB -23 B (-0.26%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.5 kB -26 B (-0.13%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 10 kB -30 B (-0.3%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 27.2 kB +22 B (+0.08%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 81.8 kB -26 B (-0.03%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 161 kB +3 B (0%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 33.3 kB -42 B (-0.13%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 117 kB -6 B (-0.01%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 184 kB -3 B (0%)
./dist/assets/js/googlesitekit-modules-********************.js 22.1 kB -62 B (-0.28%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 22.8 kB -9 B (-0.04%)
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 40.8 kB -41 B (-0.1%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 64.9 kB -35 B (-0.05%)
./dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 24.2 kB -135 B (-0.55%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32.1 kB -43 B (-0.13%)
./dist/assets/js/googlesitekit-notifications-********************.js 22.7 kB -128 B (-0.56%)
./dist/assets/js/googlesitekit-settings-********************.js 126 kB +415 B (+0.33%)
./dist/assets/js/googlesitekit-splash-********************.js 68.9 kB +24 B (+0.03%)
./dist/assets/js/googlesitekit-user-input-********************.js 43.7 kB +58 B (+0.13%)
./dist/assets/js/googlesitekit-vendor-********************.js 322 kB -3 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 96.2 kB +12 B (+0.01%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 62.6 kB -18 B (-0.03%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 59.9 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.2 kB
./dist/assets/js/32-********************.js 2.76 kB
./dist/assets/js/33-********************.js 2.25 kB
./dist/assets/js/34-********************.js 3.64 kB
./dist/assets/js/35-********************.js 935 B
./dist/assets/js/36-********************.js 893 B
./dist/assets/js/37-********************.js 1.61 kB
./dist/assets/js/38-********************.js 1.57 kB
./dist/assets/js/39-********************.js 1.61 kB
./dist/assets/js/40-********************.js 1.59 kB
./dist/assets/js/41-********************.js 1.83 kB
./dist/assets/js/42-********************.js 3.11 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 901 B
./dist/assets/js/googlesitekit-components-gm3-********************.js 10.1 kB
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB
./dist/assets/js/googlesitekit-data-********************.js 2.37 kB
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 624 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 712 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 634 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 657 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B
./dist/assets/js/googlesitekit-i18n-********************.js 3.93 kB
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B
./dist/assets/js/runtime-********************.js 1.4 kB

compressed-size-action

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

Thanks @10upsimon almost there, left you few comments

assets/js/components/user-input/UserInputSelectOptions.js Outdated Show resolved Hide resolved
assets/js/components/user-input/UserInputSelectOptions.js Outdated Show resolved Hide resolved
assets/js/components/user-input/UserInputSelectOptions.js Outdated Show resolved Hide resolved
assets/js/components/user-input/UserInputSelectOptions.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

Thanks @10upsimon LGTM

Not to MR reviewer - JS test is failing for flakiness with Audience modal tests, nothing related to this PR

Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

Thanks, @10upsimon. Left the initial feedback for you. Please, take a look.

@@ -20,6 +20,7 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import { useMount } from 'react-use';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know IB was written like this, but we should not change anything in the component because it should not contain business logic. All changes should be made in the UserInputPreview component which should prepare proper data and pass it down to this component.

@@ -257,6 +257,7 @@ const baseSelectors = {
*
* @return {Array<string>|undefined} An array of Key Metric widget slugs, or undefined if the user input settings are not loaded.
*/
/* eslint-disable complexity */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's try to refactor this selector to reduce its complexity instead of disabling the eslint rule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@eugene-manuilov I am going to challenge this one, as I feel we'd be satisfying an eslint rule but worsening the developer experience here, having to constantly check a function located elsewhere just to read (or add to) the list of metrics mapped to answers. This is a perfectly readable array, and I think we can keep the ignore rule. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@10upsimon, here are perfectly readable arrays in two new selectors:

	getRegularKeyMetricsWidgetIDs: createRegistrySelector( ( select ) => () => {
		const postTypes = select( CORE_SITE ).getPostTypes();
		const hasProductPostType = postTypes.some(
			( { slug } ) => slug === 'product'
		);

		return {
			publish_blog: [
				KM_ANALYTICS_RETURNING_VISITORS,
				KM_ANALYTICS_NEW_VISITORS,
				KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
				KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
			],
			publish_news: [
				KM_ANALYTICS_PAGES_PER_VISIT,
				KM_ANALYTICS_VISIT_LENGTH,
				KM_ANALYTICS_VISITS_PER_VISITOR,
				KM_ANALYTICS_MOST_ENGAGING_PAGES,
			],
			monetize_content: [
				KM_ANALYTICS_POPULAR_CONTENT,
				KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
				KM_ANALYTICS_NEW_VISITORS,
				KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
			],
			sell_products_or_service: [
				hasProductPostType
					? KM_ANALYTICS_POPULAR_PRODUCTS
					: KM_ANALYTICS_POPULAR_CONTENT,
				KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
				KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
			],
			sell_products: [
				hasProductPostType
					? KM_ANALYTICS_POPULAR_PRODUCTS
					: KM_ANALYTICS_POPULAR_CONTENT,
				KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
				KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
			],
			provide_services: [
				KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
				KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
				KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				KM_ANALYTICS_POPULAR_CONTENT,
				KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
			],
			share_portfolio: [
				KM_ANALYTICS_NEW_VISITORS,
				KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
				KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
				KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
			],
		};
	} ),

	getConversionTailoredKeyMetricsWidgetIDs: createRegistrySelector(
		( select ) => () => {
			const postTypes = select( CORE_SITE ).getPostTypes();
			const hasProductPostType = postTypes.some(
				( { slug } ) => slug === 'product'
			);

			return {
				publish_blog: [
					KM_ANALYTICS_TOP_CATEGORIES,
					KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
					KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
					KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
					KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
				],
				publish_news: [
					KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
					KM_ANALYTICS_POPULAR_AUTHORS,
					KM_ANALYTICS_TOP_CITIES,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
					KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
					KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
				],
				monetize_content: [
					KM_ANALYTICS_MOST_ENGAGING_PAGES,
					KM_ANALYTICS_POPULAR_CONTENT,
					KM_ANALYTICS_NEW_VISITORS,
					KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
					KM_ANALYTICS_VISIT_LENGTH,
					KM_ANALYTICS_VISITS_PER_VISITOR,
					KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				],
				sell_products_or_service: [
					hasProductPostType
						? KM_ANALYTICS_POPULAR_PRODUCTS
						: KM_ANALYTICS_POPULAR_CONTENT,
					KM_ANALYTICS_TOP_CITIES_DRIVING_PURCHASES,
					KM_ANALYTICS_TOP_DEVICE_DRIVING_PURCHASES,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_ADD_TO_CART,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_PURCHASES,
					KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
					KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				],
				sell_products: [
					hasProductPostType
						? KM_ANALYTICS_POPULAR_PRODUCTS
						: KM_ANALYTICS_POPULAR_CONTENT,
					KM_ANALYTICS_TOP_CITIES_DRIVING_PURCHASES,
					KM_ANALYTICS_TOP_DEVICE_DRIVING_PURCHASES,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_ADD_TO_CART,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_PURCHASES,
					KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
					KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				],
				provide_services: [
					KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS,
					KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
					KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
					KM_ANALYTICS_POPULAR_CONTENT,
					KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
				],
				share_portfolio: [
					KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS,
					KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
					KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
					KM_ANALYTICS_POPULAR_AUTHORS,
					KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
					KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
					KM_ANALYTICS_POPULAR_CONTENT,
					KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
				],
			};
		}
	),

Then the getAnswerBasedMetrics selector becomes pretty simple:

	getAnswerBasedMetrics: createRegistrySelector(
		( select ) => ( state, purposeOverride ) => {
			const userInputSettings =
				select( CORE_USER ).getUserInputSettings();

			if ( userInputSettings === undefined ) {
				return undefined;
			}

			const purpose =
				purposeOverride ?? userInputSettings?.purpose?.values?.[ 0 ];

			const showConversionTailoredMetrics =
				select( CORE_USER ).showConversionTailoredMetrics();

			const widgetIDs = showConversionTailoredMetrics
				? select( CORE_USER ).getRegularKeyMetricsWidgetIDs()
				: select(
						CORE_USER
				  ).getConversionTailoredKeyMetricsWidgetIDs();

			return widgetIDs[ purpose ] || [];
		}
	),

This is much easier to read and maintain without a need to disable the eslint rule.

@@ -164,7 +213,7 @@ export default function UserInputPreview( props ) {
options={ USER_INPUT_ANSWERS_PURPOSE }
loading={ loading }
settingsView={ settingsView }
onChange={ () => toggleIsModalOpen( true ) }
onChange={ () => openModalIfMetricsChanged() }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
onChange={ () => openModalIfMetricsChanged() }
onChange={ openModalIfMetricsChanged }

Copy link
Collaborator

Choose a reason for hiding this comment

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

@10upsimon, looks like you missed this one, right?

Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

Thanks, @10upsimon. Almost looks good to me. Left two last comments.

Comment on lines 166 to 171
checked:
USER_INPUT_QUESTIONS_PURPOSE === slug &&
values.includes( 'sell_products_or_service' ) &&
'sell_products' === optionSlug
? true
: values.includes( optionSlug ),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this change is not longer because we changed the selected value from sell_products_or_service to sell_products in the UserInputPreview component, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @eugene-manuilov this has been resolved in the latest commit.

@@ -164,7 +213,7 @@ export default function UserInputPreview( props ) {
options={ USER_INPUT_ANSWERS_PURPOSE }
loading={ loading }
settingsView={ settingsView }
onChange={ () => toggleIsModalOpen( true ) }
onChange={ () => openModalIfMetricsChanged() }
Copy link
Collaborator

Choose a reason for hiding this comment

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

@10upsimon, looks like you missed this one, right?

Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

Awesome. LGTM

Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

@10upsimon, there is a failing js test. Can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants