Skip to content

Add PMaxImproveAssetsBanner component #2983

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

Open
wants to merge 12 commits into
base: feature/GOOWOO-172-pmax-assets-improvements
Choose a base branch
from

Conversation

asvinb
Copy link
Collaborator

@asvinb asvinb commented Jun 24, 2025

Changes proposed in this Pull Request:

Closes https://linear.app/a8c/issue/GOOWOO-184/show-notification-when-there-is-an-ads-recommendation

Replace this with a good description of your changes & reasoning.

Screenshots:

image

Detailed test instructions:

  1. Navigate to the plugin main dashboard.
  2. Ensure you have some PMax campaigns.
  3. Mock the /wp-json/wc/gla/ads/recommendations?type=IMPROVE_PERFORMANCE_MAX_AD_STRENGTH endpoint with the following in Devtools. See below in "Additional details" section for mocked response.
  4. Update the campaign_id in the mock response to match one your highest spending PMax campaign.
  5. Refresh the page, the banner should now be visible if the conditions are met.
  6. The name of the highest spending campaign should be visible in the banner.
  7. Clicking the "Improve Assets" button from the banner should redirect you to the campaign edit assets page for the specified campaign.
  8. If there are no PMax campaigns or the ads/recommendations endpoint returns an empty array, the banner should not be displayed.
  9. If the recommendations endpoint does not return the highest spending campaign, the banner should not be displayed.
  10. If the ads/recommendations endpoint returns an error, the banner should not be displayed.
  11. If the user has dismissed the banner, it should not be displayed again upon page reload until 30 days have passed since the dismissal.

Additional details:

Mocked response:

[
	{
		"id": 1,
		"type": "IMPROVE_PERFORMANCE_MAX_AD_STRENGTH",
		"resource_name": "customers/{customer_id}/recommendations/{recommendation_id}",
		"campaign_id": 22689268469,
		"campaign_name": "Spring Campaign",
		"campaign_status": "ENABLED",
		"last_synced": "2024-06-01T12:34:56Z"
	}
]

Changelog entry

@asvinb asvinb requested a review from joemcgill June 24, 2025 07:33
@github-actions github-actions bot added type: enhancement The issue is a request for an enhancement. changelog: add A new feature, function, or functionality was added. labels Jun 24, 2025
@asvinb asvinb changed the base branch from develop to feature/GOOWOO-172-pmax-assets-improvements June 24, 2025 07:33
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 80.64516% with 12 lines in your changes missing coverage. Please review.

Project coverage is 66.7%. Comparing base (fe9f311) to head (c5d07d3).
Report is 1 commits behind head on feature/GOOWOO-172-pmax-assets-improvements.

Files with missing lines Patch % Lines
js/src/data/resolvers.js 0.0% 5 Missing ⚠️
js/src/data/reducer.js 0.0% 3 Missing ⚠️
js/src/data/actions.js 0.0% 2 Missing ⚠️
js/src/data/selectors.js 50.0% 0 Missing and 1 partial ⚠️
js/src/hooks/useRecommendedPMaxCampaign.js 96.3% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                               Coverage Diff                                @@
##             feature/GOOWOO-172-pmax-assets-improvements   #2983      +/-   ##
================================================================================
+ Coverage                                           66.2%   66.7%    +0.5%     
================================================================================
  Files                                                828     340     -488     
  Lines                                              25729    5284   -20445     
  Branches                                            1276    1290      +14     
================================================================================
- Hits                                               17040    3526   -13514     
+ Misses                                              8536    1604    -6932     
- Partials                                             153     154       +1     
Flag Coverage Δ
js-unit-tests 66.7% <80.6%> (+0.2%) ⬆️
php-unit-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rc/components/pmax-improve-assets-banner/banner.js 100.0% <100.0%> (ø)
...src/components/pmax-improve-assets-banner/index.js 100.0% <100.0%> (ø)
js/src/constants.js 100.0% <100.0%> (ø)
js/src/data/action-types.js 100.0% <ø> (ø)
js/src/pages/dashboard/index.js 83.3% <ø> (ø)
js/src/utils/urls.js 55.3% <ø> (ø)
js/src/data/selectors.js 52.6% <50.0%> (-<0.1%) ⬇️
js/src/hooks/useRecommendedPMaxCampaign.js 96.3% <96.3%> (ø)
js/src/data/actions.js 15.1% <0.0%> (-0.1%) ⬇️
js/src/data/reducer.js 73.7% <0.0%> (-1.0%) ⬇️
... and 1 more

... and 491 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joemcgill joemcgill added changelog: none Skip changelog entry for this PR and removed changelog: add A new feature, function, or functionality was added. labels Jun 27, 2025
Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

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

Just a few suggestions, but this is looking good.

One thing to keep in mind for the future is that any API calls that automatically get made by this component will need to either be mocked in E2E tests to avoid API errors or we need to figure out how to disable these notifications (maybe by pre-setting the preferences state) during the setup process for the Playwright tests.

{ sprintf(
// translators: %s: The PMAX campaign name with the highest spending.
__(
'Unlock more sales for your campaign, %s, by focusing on improving your campaign assets.Better assets directly increase your ad strength, allowing for a wider variety of ad combinations to be shown across Google.',
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
'Unlock more sales for your campaign, %s, by focusing on improving your campaign assets.Better assets directly increase your ad strength, allowing for a wider variety of ad combinations to be shown across Google.',
'Unlock more sales for your campaign, %s, by focusing on improving your campaign assets. Better assets directly increase your ad strength, allowing for a wider variety of ad combinations to be shown across Google.',

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤦 Forgot to push my changes before to address this. Fixed @joemcgill

Comment on lines 56 to 58
set( PREFERENCES_STORE_NAMESPACE, PREFERENCE_BANNER_KEY, {
expiry: undefined, // Reset to undefined to show the banner again
} );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be in a useEffect() hook to avoid unnecessary re-renders?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, just updated it. When I tested there were no re-renders but just to make sure, I've used useEffect

Comment on lines 65 to 77
const pmaxCampaigns = adsCampaignsData.filter(
( { type, status } ) =>
type === CAMPAIGN_TYPE_PMAX && status === 'enabled'
);

if ( ! pmaxCampaigns.length ) {
return null;
}

const highestAmountCampaign = pmaxCampaigns.reduce(
( max, campaign ) => ( campaign.amount > max.amount ? campaign : max ),
pmaxCampaigns[ 0 ]
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic could be sped up by wrapping it in a useMemo()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Updated @joemcgill

@asvinb
Copy link
Collaborator Author

asvinb commented Jul 2, 2025

@joemcgill I've noticed that although the Notice component is not rendered due to the expiry, requests to various endpoints were still being made. To address this, I introduced a new component, Banner, which is only rendered if the expiry value is expired or not set, thus preventing unnecessary requests when it’s not.

You can review the changes in this commit.

Another area for optimization is within the Banner component itself - we're currently making two separate requests:

  1. Fetching ad campaigns
  2. Fetching recommendations

I believe we can avoid fetching campaigns if there are no recommendations (or vice versa). To streamline this, I’m proposing a new hook: usePMaxCampaignRecommendation.

This hook would:

  • Use the getAdsRecommendations selector to retrieve recommendations
  • Bail early and return null if no recommendations exist
  • Otherwise, use getAdsCampaigns to fetch campaigns and return the one with the highest spend

This approach would eliminate one unnecessary request and make the logic easier to manage in a single place. Curious to hear your thoughts!

@joemcgill
Copy link
Collaborator

Thanks @asvinb I like your suggestion for the usePMaxCampaignRecommendation() hook. Do you want to make those updates in this PR?

@asvinb
Copy link
Collaborator Author

asvinb commented Jul 2, 2025

@joemcgill Let me handle it in the current PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: none Skip changelog entry for this PR type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants