-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: feature/GOOWOO-172-pmax-assets-improvements
Are you sure you want to change the base?
Add PMaxImproveAssetsBanner component #2983
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this 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.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'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.', |
There was a problem hiding this comment.
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
set( PREFERENCES_STORE_NAMESPACE, PREFERENCE_BANNER_KEY, { | ||
expiry: undefined, // Reset to undefined to show the banner again | ||
} ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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 ] | ||
); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Updated @joemcgill
@joemcgill I've noticed that although the 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:
I believe we can avoid fetching campaigns if there are no recommendations (or vice versa). To streamline this, I’m proposing a new hook: This hook would:
This approach would eliminate one unnecessary request and make the logic easier to manage in a single place. Curious to hear your thoughts! |
Thanks @asvinb I like your suggestion for the |
@joemcgill Let me handle it in the current PR. Thanks! |
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:
Detailed test instructions:
/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.campaign_id
in the mock response to match one your highest spending PMax campaign.ads/recommendations
endpoint returns an empty array, the banner should not be displayed.ads/recommendations
endpoint returns an error, the banner should not be displayed.Additional details:
Mocked response:
Changelog entry