Rely strictly on AdSense API to determine account status
See original GitHub issueFollow-up to #4758, #4759, #5106: The logic in the AdSense setup is now generally correct, however there is something we need to enhance: Currently, some of the states are determined based on the accountID
and clientID
settings, and there are a few situations where we don’t update them based on the current API responses. This can lead to inconsistent behavior, especially when mocking different statuses with the tester plugin.
It can certainly have real-world implications though too: for example if you first start the AdSense setup with an account that has an AFC client set up but then delete it, when you go back to the AdSense setup, Site Kit still has that old clientID
set, which is incorrect and leads to the wrong status being set and the wrong UI showing up.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- In the AdSense V2
SetupMain
component:- If there are no accounts in the API response, but
accountID
is set to a non-empty value, the setting should be updated to be an empty string again (in the respectiveuseEffect
).
- If there are no accounts in the API response, but
- In the AdSense V2
SetupAccount
component:- If there is no AFC client in the API response, but
clientID
is set to a non-empty value, the setting should be updated to be an empty string again (in the respectiveuseEffect
). - Cleanup: The component should no longer use
getClients
which is unnecessary. That selector is internally used bygetAFCClient
, and its return value alone is sufficient for any of the conditions where thegetClients
result is currently used (e.g. loading state).
- If there is no AFC client in the API response, but
Implementation Brief
- In
assets/js/modules/adsense/components/setup/v2/SetupMain.js
:- Update the existing
useEffect
hook that sets theaccountID
setting to set an empty string for theaccountID
setting ifaccounts
is an empty array and current value of theaccountID
setting is not empty. https://github.com/google/site-kit-wp/blob/00a2fdf067e3931df0ba20a20f7df3ff1f8789a1/assets/js/modules/adsense/components/setup/v2/SetupMain.js#L138-L148
- Update the existing
- In
assets/js/modules/adsense/components/setup/v2/SetupAccount.js
:- Update the existing
useEffect
hook that sets theclientID
setting to set an empty string for theclientID
setting ifafcClient
isnull
and the current value of theclientID
setting is not empty. https://github.com/google/site-kit-wp/blob/00a2fdf067e3931df0ba20a20f7df3ff1f8789a1/assets/js/modules/adsense/components/setup/v2/SetupAccount.js#L77-L81 - Remove the
getClients
selector call and all checks of theclients
variable.
- Update the existing
- Update corresponding storybook stories if any is broken due to the aforementioned changes.
Test Coverage
- N/A
QA Brief
For all tests below: Set the tester plugin AdSense site status to “ready”.
Ensure you have at least 1.8.2 of the Tester plugin installed.
Ensuring that account is reset
- Set the tester plugin AdSense account status to “needs-attention”. Go to the AdSense setup (it should show the correct UI, but that’s not the point here).
- Set the tester plugin AdSense account status to “none”. Go to the AdSense setup (it should show the correct UI as well, still not the thing to mostly look for).
- Set the tester plugin AdSense account status to “multiple”. Go to the AdSense setup. You should now see the dropdown to select an account. If you land in another situation (where your account seems as if it was already selected), it would mean the problem was not fixed as expected.
Ensuring the client is reset
- Set the tester plugin AdSense account status to “needs-attention”. Go to the AdSense setup (it should show the correct UI, but that’s not the point here).
- Set the tester plugin AdSense account status to “no-client”. Go to the AdSense setup. You should now see the UI where it says that you need to upgrade your AdSense account to support “AdSense for Content”. If you land in another situation (where your client seems as if it was set), it would mean the problem was not fixed as expected.
Changelog entry
- Ensure AdSense account ID and client ID are always set based on API response during setup.
Issue Analytics
- State:
- Created a year ago
- Comments:18 (7 by maintainers)
@wpdarren Apologies, I think that small but crucial detail about the site status to set in the tester plugin was wrong the way I had originally specified it in the QA Brief. What you’re seeing is in fact expected because not having a site takes precedence over some of the other relevant criteria. So I’ve now updated the QA Brief to have the site status always set to “ready”, so that the site status cannot “conflict” with the account status you set here, which is what this issue is exclusively about.
@eugene-manuilov Replied on the PR.