question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix AdSense V2 main logic

See original GitHub issue

Bug 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 and determineSiteStatus. Instead, it needs to look at the accountStatus and siteStatus settings from the AdSense module.
  • The component must no longer use determineAccountID. Instead, custom logic in the useEffect hook should set the accountID 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 the clientID 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 to resetURLChannels 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 the useEffect hook should set the clientID setting, based on the logic defined in the ACs for #4759.
  • There needs to be an additional useEffect hook that sets siteStatus to SITE_STATUS_NONE if the current site (site) is null (not undefined). 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 separate SetupAccountSite 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 the MODULES_ADSENSE store’s getAccountStatus selector. via useSelect.
  • Similarly, replace the call to determineSiteStatus with a call to the getSiteStatus selector, and the call to determineClientID with a call to the getClientID selector.
  • Rename the existing previousAccountID variable which is retrieved via getAccountID to accountID. Remove the call to determineAccountID.
  • Within the useEffect block that invokes setAccountID:
    • 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 either accountID is not set, or the _id property of the single account in accounts (i.e. accounts[0]._id) does not match accountID.
    • Replace the call to setAccountID( accountID ) with setAccountID( 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 of acfClientID with clientID.
  • Within the useEffect block that invokes setClientID:
    • Modify the condition to check that there is one AFC in clients, and either clientID is not set, or the _id property of the single AFC client in clients does not match clientID.
      • A client is an AFC client if its productCode property is 'AFC’. See here for an example.
    • Replace the clientID argument to setClientID( clientID ) with the _id property of the single AFC client in clients.
  • Add a useEffect with a callback that dispatches setSiteStatus( SITE_STATUS_NONE ) when site === 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:closed
  • Created a year ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
felixarntzcommented, Apr 27, 2022

@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.

2reactions
felixarntzcommented, May 2, 2022

@hussain-t @wpdarren @techanvil Thank you all for the observations. Providing some feedback:

  • No accounts error: Before the AdSense API changes last year that facilitate this epic, the accounts endpoint used to return an error in case there were none. I kept this like that in the tester plugin for BC and so that it still works with the V1 flow logic that supports looking for that error. However, just now because of your feedback I realized that I never added this in the V2 logic requirements to also support that error. Given that that error is only there for legacy reasons, I agree with your point though, I will update the tester plugin to return an empty array. We just need to double-check whether that also works with the existing V1 flow, but I think it does because the V1 flow as far as I remember checks for either the error or an empty array. I’ll work on that today so that hopefully we can have the tester plugin version 1.8.2 with that fix out tomorrow.
  • Progress bar oddness: This is indeed odd UX, we should fix it so that the logo heading is always there and only the content below is the progress bar when loading, and it should never switch between one or the other. I will indeed open a separate issue for that though as it’s not really related to this one. That issue will then fix the points 2. and 3.
  • Setup incomplete: +1 to what @hussain-t said here as well, this is expected.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Login troubleshooter - Google AdSense Help
This troubleshooter is designed to help you solve problems with signing in to your ... 1. Sign out of any Google Accounts. 2....
Read more >
Issues for Google AdSense integration | Drupal.org
Title Status Priority Category Version Ads only show on Views pages Closed (works as designed) Normal Bug report 7.x‑1.x... Problem with Drupal 7 Closed (duplicate)...
Read more >
How to Solve you need to fix issue in Adsense - YouTube
In this video I will be discussing about Google AdSense problem where you can fix some issues in Google AdSenseJoin our What's app ......
Read more >
Site Kit by Google – Analytics, Search Console, AdSense ...
Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web....
Read more >
Generating Ads.txt AdSense Code - Playwire
Fortunately, there's an easy fix. To get your publisher ID in AdSense, navigate to Sites from your dashboard. Click the down arrow next...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found