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
determineAccountStatusanddetermineSiteStatus. Instead, it needs to look at theaccountStatusandsiteStatussettings from the AdSense module. - The component must no longer use
determineAccountID. Instead, custom logic in theuseEffecthook should set theaccountIDsetting, 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 theclientIDsetting. The setting should be set through another component (SetupAccount, to be specific). - The usage of
getURLChannelsshould be entirely removed, as that endpoint is no longer relevant as part of the V2 setup flow. The call toresetURLChannelsshould also be removed for the same reason.
In the AdSense V2 SetupAccount component:
- The component must no longer use
determineClientID. Instead, custom logic in theuseEffecthook should set theclientIDsetting, based on the logic defined in the ACs for #4759. - There needs to be an additional
useEffecthook that setssiteStatustoSITE_STATUS_NONEif 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 separateSetupAccountSitecomponent.
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
determineAccountStatuswith a call to theMODULES_ADSENSEstore’sgetAccountStatusselector. viauseSelect. - Similarly, replace the call to
determineSiteStatuswith a call to thegetSiteStatusselector, and the call todetermineClientIDwith a call to thegetClientIDselector. - Rename the existing
previousAccountIDvariable which is retrieved viagetAccountIDtoaccountID. Remove the call todetermineAccountID. - Within the
useEffectblock 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 eitheraccountIDis not set, or the_idproperty 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 ofacfClientIDwithclientID. - Within the
useEffectblock that invokessetClientID:- Modify the condition to check that there is one AFC in
clients, and eitherclientIDis not set, or the_idproperty of the single AFC client inclientsdoes not matchclientID.- A client is an AFC client if its
productCodeproperty is'AFC’. See here for an example.
- A client is an AFC client if its
- Replace the
clientIDargument tosetClientID( clientID )with the_idproperty of the single AFC client inclients.
- Modify the condition to check that there is one AFC in
- Add a
useEffectwith 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)

Top Related StackOverflow Question
@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
adsenseSetupV2flag 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.