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

Add minimum budget limit #2583

Open
wants to merge 55 commits into
base: update/2535-consolidate-ad-creation-ccf-merged
Choose a base branch
from

Conversation

dsawardekar
Copy link
Collaborator

@dsawardekar dsawardekar commented Sep 5, 2024

Changes proposed in this Pull Request:

Closes #2503

This PR updates the campaign flow to include validation of minimum daily limits. An error message is shown if the amount is less than the daily limit.

Screenshots:

With an insufficient amount:
image

With a sufficient amount:
image

Detailed test instructions:

  1. On the final step of the onboarding flow, Click create a campaign
  2. You should see the Set your budget section
  3. In the Daily avg cost, enter 1 < value < 5
  4. You should see the above error below the input (red styling TBD)

Additional details:

Update - Enforce the daily limit of 30% in setup your budget section

Changelog entry

Update - Adjust the minimum average daily cost of a campaign to 30% of the highest recommended value among audience countries.

@github-actions github-actions bot added the changelog: update Big changes to something that wasn't broken. label Sep 5, 2024
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 36.84211% with 48 lines in your changes missing coverage. Please review.

Project coverage is 61.6%. Comparing base (34c53d7) to head (ce9ad99).

Files with missing lines Patch % Lines
js/src/data/resolvers.js 0.0% 13 Missing and 3 partials ⚠️
...s/src/hooks/useValidateCampaignWithCountryCodes.js 50.0% 7 Missing ⚠️
js/src/utils/getHighestBudget.js 0.0% 5 Missing and 2 partials ⚠️
...s/paid-ads/ads-campaign/paid-ads-setup-sections.js 0.0% 4 Missing and 1 partial ⚠️
js/src/hooks/useFetchBudgetRecommendation.js 16.7% 5 Missing ⚠️
js/src/components/paid-ads/campaign-assets-form.js 66.7% 2 Missing ⚠️
js/src/data/selectors.js 33.3% 1 Missing and 1 partial ⚠️
js/src/data/utils.js 0.0% 2 Missing ⚠️
...-ads/budget-section/budget-recommendation/index.js 0.0% 1 Missing ⚠️
js/src/components/paid-ads/budget-section/index.js 50.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                               Coverage Diff                                @@
##           update/2535-consolidate-ad-creation-ccf-merged   #2583     +/-   ##
================================================================================
+ Coverage                                            61.0%   61.6%   +0.5%     
================================================================================
  Files                                                 330     331      +1     
  Lines                                                5183    5233     +50     
  Branches                                             1254    1268     +14     
================================================================================
+ Hits                                                 3162    3221     +59     
+ Misses                                               1832    1820     -12     
- Partials                                              189     192      +3     
Flag Coverage Δ
js-unit-tests 61.6% <36.8%> (+0.5%) ⬆️

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

Files with missing lines Coverage Δ
js/src/components/paid-ads/validateCampaign.js 100.0% <100.0%> (ø)
js/src/data/action-types.js 100.0% <ø> (ø)
js/src/data/reducer.js 83.8% <100.0%> (+0.3%) ⬆️
...-ads/budget-section/budget-recommendation/index.js 4.0% <0.0%> (ø)
js/src/components/paid-ads/budget-section/index.js 11.1% <50.0%> (+0.6%) ⬆️
js/src/components/paid-ads/campaign-assets-form.js 76.2% <66.7%> (-1.6%) ⬇️
js/src/data/selectors.js 48.0% <33.3%> (+0.6%) ⬆️
js/src/data/utils.js 94.1% <0.0%> (-3.8%) ⬇️
...s/paid-ads/ads-campaign/paid-ads-setup-sections.js 3.3% <0.0%> (+0.2%) ⬆️
js/src/hooks/useFetchBudgetRecommendation.js 16.7% <16.7%> (ø)
... and 3 more

... and 5 files with indirect coverage changes

@dsawardekar
Copy link
Collaborator Author

@asvinb We need a styling update to the error message shown when a minimum limit is shown to the user. The input box also needs to be updated when in that invalid input state. Can you please take a look? Thanks!

image

@dsawardekar
Copy link
Collaborator Author

@joemcgill As part of this work, I extracted the getHighestBudget into a utility.

  • Should we update js/src/components/paid-ads/budget-section/budget-recommendation/index.js to use this utility
    • If yes, should those changes be part of this PR or a separate one

@joemcgill
Copy link
Collaborator

Thanks @dsawardekar. Re:

Should we update js/src/components/paid-ads/budget-section/budget-recommendation/index.js to use this utility

Let's not update the Paid Ads flow at this time. It should end up getting handled as part of #2535.

@dsawardekar dsawardekar changed the base branch from develop to feature/2459-campaign-creation-flow September 11, 2024 05:32
@dsawardekar
Copy link
Collaborator Author

@joemcgill This is ready for code review. Note that I needed to create a new mock helper for the budget recommendation, let me know if that needs to be refactored.

@dsawardekar dsawardekar marked this pull request as ready for review September 11, 2024 06:37
Copy link
Collaborator

@asvinb asvinb left a comment

Choose a reason for hiding this comment

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

@dsawardekar I left some comments on the PR. Can you kindly check please and let me know what you think?

@dsawardekar
Copy link
Collaborator Author

@asvinb I've updated the PR per the feedback. Can you take another look? thanks!

asvinb
asvinb previously requested changes Sep 13, 2024
Copy link
Collaborator

@asvinb asvinb left a comment

Choose a reason for hiding this comment

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

@dsawardekar Thanks for the updates. I think it's very close to approval. Can you check my latest comments please? Thanks!

@asvinb asvinb changed the title Update/2459 add minimum budget limit Add minimum budget limit Sep 16, 2024
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.

@asvinb I have one small tweak for this that I'd like to make, but am pre-approving and this can go to QA.

js/src/components/paid-ads/validateCampaign.js Outdated Show resolved Hide resolved
@asvinb
Copy link
Collaborator

asvinb commented Sep 27, 2024

@joemcgill @ankitguptaindia Raised a valid point for when using decimals which is in WooCommerce settings (Settings -> Currency Options -> Number of decimals). Checking @fblascogarma comment where we wish to round the number automatically, I think it'll add unnecessary complexity since we now have to rely on the number of decimals for the currency. I suggest we use don't round up the numbers and instead rely on the user settings for the decimal numbers. If the decimal place is set to 0, then the amount will be automatically rounded. Furthermore, I now agree with what Darshan originally suggested. If we change the error message from "greater than" to "at least", it'll simplify things as well. Let's say the minimum amount is 5, and the user inputs 5, depending on the decimal options set, we either need to tell the user that the minimum amount is 4 (if decimal places is set to 0) or 4.99 (if decimal places is set to 2). So we'll have additional logic if we use greater than. Whereas if we use at least, we just output the minimum amount, with the appropriate decimal places.
cc @ankitguptaindia

@joemcgill
Copy link
Collaborator

@asvinb I'm not sure I understand the issue we're running into with rounding. My understanding is that we are only rounding the suggested budget in order to set the minimum value, which is what should then be displayed to users as the minimum value in the error message. We should not be rounding the value that the user has input.

I think the text change you suggested makes sense and is more accurate since a value that is === to the minimum should be acceptable.

@eason9487
Copy link
Member

Hi @joemcgill and @asvinb, I would like to chip in two questions about the budget validation.

  1. While I was leaving Add minimum budget limit #2583 (comment), I thought it could be solved by adjusting the message to "Please make sure daily average cost is at least %s." and not changing any other logic, because adjusting the wording shouldn't be a concern. However, with subsequent code changes and discussions, I would like to confirm that the message must be strictly “Please make sure daily average cost is greater than %s.”?

  2. Just noticed Campaign Creation: Add minimum budget limit #2503 (comment) saying:

    30% and rounding up for a nicer number.

    If the final decision still makes it a nicer integer as the minimum budget, then the previous Math.round() needs to be replaced with Math.ceil().

    const minAmount = Math.round( dailyBudget * BUDGET_MIN_PERCENT );

@asvinb
Copy link
Collaborator

asvinb commented Oct 1, 2024

@joemcgill @eason9487 Let me try to summarize the "issue" with the decimals (although it's not really an issue 😁 ).
The scenario below is assuming the minimum budget recommendation is 15 and we are changing the number of decimals in Woo settings:
image

With the number of decimals set to 0:

  • Minimum value: 5 (rounded from 4.5)
  • Anything less than 5, i.e 4 is considered invalid.
    image

With the number of decimals set to 1:

  • Minimum value: 4.5 (since we have the number of decimals set to 1)
  • Anything less than 4.5, i.e 4.4 is considered invalid.
    image

With the number of decimals set to 2:

  • Minimum value: 4.50 (since we have the number of decimals set to 1)
    • Anything less than 4.50, i.e 4.49 is considered invalid.
      image

So if we want to use the greater than text, then we must take into account the number of decimal places to do the calculation as well because it'll vary, from 4 to 4.49 (as in the examples above) for the same minimum amount. That's why I suggested we keep the at least since then we just show the minimum value out of the box without the need to calculate the highest invalid amount.
Now about the rounding, as you can see in the examples above, it'll automatically be rounded if the number of decimal places is set to 0. So we rely on Woo settings and the precision and formatAmount from the useAdsCurrency hook to automatically do that for us.

@asvinb asvinb changed the base branch from feature/2459-campaign-creation-flow to update/2535-consolidate-ad-creation-ccf-merged October 1, 2024 13:10
@joemcgill
Copy link
Collaborator

Thanks for the explanation, @asvinb. I think you're correct (if I'm understanding correctly) that using the store setting to control the decimal rounding likely makes sense.

What is still a bit confusing is how this ended up creating a situation like @ankitguptaindia reported here where the minimum budget error shows a number lower than the one the user has actually input. I'm not able to reproduce that error locally.

@asvinb
Copy link
Collaborator

asvinb commented Oct 1, 2024

@joemcgill Actually the error that @ankitguptaindia reported is no longer applicable because it's now fixed 😁 Previously, i.e when not taking into consideration the Woo number of decimals settings, then you could reproduce the issue. However now it's fixed. I changed the target branch to update/2535-consolidate-ad-creation-ccf-merged and fixed the conflicts and also simplified the code. Can you kindly take a look before I send to QA with all those changes? Thanks!

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.

Thanks for explaining. This tested well for me. Thanks

@asvinb
Copy link
Collaborator

asvinb commented Oct 2, 2024

Thanks @joemcgill . Assigning to @ankitguptaindia for another round of QA.

@ankitguptaindia
Copy link
Member

Thanks for the fixes, @asvinb. The issues have been resolved, and the minimum budget requirement message is now appearing correctly when the WooCommerce settings have different decimal configurations.

Quick Demo:

Recording.884.mp4

@eason9487
Copy link
Member

Hi @asvinb @joemcgill

Before starting a new round of code reviews, could you help me clarify the two questions in #2583 (comment)?

Using the current 78fc8bb revision and replacing:

const minAmount = ( dailyBudget * BUDGET_MIN_PERCENT ).toFixed(
precision
);

with:

const minAmount = Math.ceil( dailyBudget * BUDGET_MIN_PERCENT );

Apart from using the greater than wording, It works pretty well and fulfills the rest requirements without the semantic inaccuracies in the error message.

Kapture.2024-10-04.at.18.58.34.mp4

I have read all the relevant discussions in the PR. However, taking the decimals into account when calculating the minimum budget value still confuses me.

@asvinb
Copy link
Collaborator

asvinb commented Oct 4, 2024

Hello @eason9487
I think it's the word "rounding" which is causing some confusion here and what happens when the decimal places are set in the store settings and using Math.round. I think Math.ceil works well as well and we just need to align that we can use the at least instead of greater than (where we'll need to take the decimal points into account. For e.g if "greater than" was to be used, then 5.99 should be displayed if the decimal points setting is set to 2 decimals).

@joemcgill
Copy link
Collaborator

I think Math.ceil works well as well and we just need to align that we can use the at least instead of greater than

I agree and using "at least" is totally appropriate here and more accurate than the original requirements that I had written for the issue.

@eason9487
Copy link
Member

eason9487 commented Oct 4, 2024

Hi @asvinb

I think it's the word "rounding" which is causing some confusion here and what happens when the decimal places are set in the store settings and using Math.round. I think Math.ceil works well as well [...]

This question should not be related to the word "rounding" and it's not the cause of the confusion. I used Math.ceil in the example just because #2503 (comment) mentioned "rounding up".

[...] and we just need to align that we can use the at least instead of greater than (where we'll need to take the decimal points into account. For e.g if "greater than" was to be used, then 5.99 should be displayed if the decimal points setting is set to 2 decimals)

Yes, and the current implementation has already rephrased to at least. So my confusion is, what is the reason for still taking the decimals into account when there is no need?

@asvinb
Copy link
Collaborator

asvinb commented Oct 4, 2024

@eason9487 If we use Math.ceil, then there's no need to take any decimals into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: update Big changes to something that wasn't broken.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Campaign Creation: Add minimum budget limit
5 participants