Fix AdSense V2 main logic
See original GitHub issueBug Description
Follow-up to #4758 and #4759: After a closer inspection of the V2 SetupMain
component, I found that several requirements from the ACs of that issue were not quite correctly implemented in that issue. Most importantly, the determineAccountStatus
, determineSiteStatus
and any of the other determine*
utility function must no longer be used as part of the V2 flow at all. Account status and site status should be determined and set by the new components, and the SetupMain
component needs to look at the accountStatus
and siteStatus
settings, not the determined value using the old function.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
In the AdSense V2 SetupMain
component:
- The component must no longer use
determineAccountStatus
anddetermineSiteStatus
. Instead, it needs to look at theaccountStatus
andsiteStatus
settings from the AdSense module. - The component must no longer use
determineAccountID
. Instead, custom logic in theuseEffect
hook should set theaccountID
setting, based on the logic defined in the ACs for #4758. - The component must no longer use
determineClientID
. That handling should be entirely removed, the component should only look at theclientID
setting. The setting should be set through another component (SetupAccount
, to be specific). - The usage of
getURLChannels
should be entirely removed, as that endpoint is no longer relevant as part of the V2 setup flow. The call toresetURLChannels
should also be removed for the same reason.
In the AdSense V2 SetupAccount
component:
- The component must no longer use
determineClientID
. Instead, custom logic in theuseEffect
hook should set theclientID
setting, based on the logic defined in the ACs for #4759. - There needs to be an additional
useEffect
hook that setssiteStatus
toSITE_STATUS_NONE
if the current site (site
) isnull
(notundefined
). This was also originally defined in the ACs #4759, but missing from the implementation. Note that no other site status should be set here since the other possible site statuses are all being set via the separateSetupAccountSite
component.
All Storybook coverage for the V2 AdSense setup flow should be reviewed to double-check that it shows the correct UI (still temporary placeholders describing the intended state) even with the fixed logic here. Due to the fixes, it is very likely that some of the dummy data for the stories will need adjusting.
Implementation Brief
SetupMain
component
Within file assets/js/modules/adsense/components/setup/v2/SetupMain.js
:
- Replace the call to
determineAccountStatus
with a call to theMODULES_ADSENSE
store’sgetAccountStatus
selector. viauseSelect
. - Similarly, replace the call to
determineSiteStatus
with a call to thegetSiteStatus
selector, and the call todetermineClientID
with a call to thegetClientID
selector. - Rename the existing
previousAccountID
variable which is retrieved viagetAccountID
toaccountID
. Remove the call todetermineAccountID
. - Within the
useEffect
block that invokessetAccountID
:- Remove the first condition and its early return, this will no longer be needed.
- Modify the remaining condition to check that there is one account in
accounts
, and eitheraccountID
is not set, or the_id
property of the single account inaccounts
(i.e.accounts[0]._id
) does not matchaccountID
. - Replace the call to
setAccountID( accountID )
withsetAccountID( accounts[0]._id )
.
- Remove the call to
resetURLChannels
. - Remove all unused variables and related code.
SetupAccount
component
Within file assets/js/modules/adsense/components/setup/v2/SetupAccount.js
:
- Remove the call to
determineClientID
, and replace usage ofacfClientID
withclientID
. - Within the
useEffect
block that invokessetClientID
:- Modify the condition to check that there is one AFC in
clients
, and eitherclientID
is not set, or the_id
property of the single AFC client inclients
does not matchclientID
.- A client is an AFC client if its
productCode
property is'AFC
’. See here for an example.
- A client is an AFC client if its
- Replace the
clientID
argument tosetClientID( clientID )
with the_id
property of the single AFC client inclients
.
- Modify the condition to check that there is one AFC in
- Add a
useEffect
with a callback that dispatchessetSiteStatus( SITE_STATUS_NONE )
whensite === null
.
Storybook
- As per the last point of the AC, ensure the related Storybook stories still display correctly.
Test Coverage
- No new tests needed.
QA Brief
- Ensure the Adsense Setup V2 stories still display correctly as mentioned in the AC.
Changelog entry
- N/A
Issue Analytics
- State:
- Created a year ago
- Comments:18 (5 by maintainers)
@hussain-t @wpdarren I agree that the QA Brief could be more extensive. Yesterday the 1.8.0 version of the tester plugin was published which allows mocking all the API responses to enforce the new AdSense account and site statuses, so we can now test this in a better way than before.
A good QA Brief could be to set all the new account statuses (except the ones marked “legacy”, which are for the V1 AdSense setup) one after the other via the tester plugin, go to the AdSense setup flow each time to check whether the right “temporary UI message” is shown, and then also go to Site Kit’s Site Health info section to check that in fact that expected account status was also detected by Site Kit. All of that with the
adsenseSetupV2
flag enabled of course.@hussain-t @wpdarren @techanvil Thank you all for the observations. Providing some feedback:
So it looks like most of the QA work here is complete, the only thing would be to double-check the accounts error is gone when the new tester plugin version is there.