Sponsored Content
The Wayback Machine - https://web.archive.org/web/20220409073113/https://github.com/google/site-kit-wp/issues/427
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

Simplify AdSense account status detection function getAdSenseAccountStatus #427

Closed
adamsilverstein opened this issue Aug 21, 2019 · 12 comments
Closed
Labels
P0 Type: Enhancement
Milestone

Comments

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Aug 21, 2019 •

Feature Description

In the AdSense module, the function getAdSenseAccountStatus is responsible for determining the user's AdSense account status after AdSense is activated. Once the status is determined, the function currently returns all of the data needed to display the final state.

We can simplify this function by returning only the status data, moving the strings to the components where they are displayed.

The AdSenseModuleStatus component calls getAdSenseAccountStatus passing the resulting status data and displaying one of two sub-components AdSenseSetupInstructions and AdSenseInProcessStatus which then take responsibility for displaying the correct strings based on the status/reason.

Action items for this Issue:

  • Adjust the getAdSenseAccountStatus function to only return clientId, accountStatus & issue data points (client id is required to construct deep links).
  • Ensure each logic scenario returns a unique accountStatus & issue combination (some may need adjusting to make them unique).
  • Remove the data point returns for statusMessage, profile, ctaLink, ctaLinkText, ctaTarget, helpLink, helpLinkText, setupComplete, statusHeadline, notice, icon, buttonLink, footerText, footerAppendedText, footerCTA, footerCTALink, continueAction, accountTagMatch, switchLabel, tracking, switchOffMessage & switchOnMessage
  • Each string/data value should instead be moved to AdSenseSetupInstructions or AdSenseInProcessStatus.
  • Use a switch statement at component mount to construct strings/data based on status/reason
  • Also move calls to sendAnalyticsTrackingEvent out of the utility function up into AdSenseModuleStatus where a single call can handle sending the tracking status

Verification

  • For each test user the final state display should exactly match the current display
  • Verify all AdSense status strings are in the components where they are displayed (AdSenseSetupInstructions and AdSenseInProcessStatus)
  • For each flow/resulting status, correct events should be sent to analytics tracking

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The getAdSenseAccountStatus() function in JS should only return clientId (AdSense client ID), accountStatus (slug such as no-account or ads-display-pending for example), and issue (a user-facing string with information about the problem if there is one).
  • The issue variable must always be a user-facing string with a reason, or alternatively false. It must never be a camelCase string or another string that is not user-facing (since it is displayed to the user in the AdSenseSetupInstructions component).
  • Other variables currently returned by the function should be set conditionally on the above variables (probably in a switch clause in the AdSenseInProcessStatus component).
  • The current functionality should be fully maintained. The goal of this issue is solely to simplify the getAdSenseAccountStatus() function.

Implementation Brief

  • { ...this.state } spread ( ) should be removed—it should not be needed but can also lead to unexpected behaviours if the state of that component changes. The spread should be replaced with only the props AdSenseSetupInstructions requires.
  • getAdSenseAccountStatus should return an object with only the following keys: accountStatus, clientId, issue.
  • Do not set WP translation strings (eg: __()) in getAdSenseAccountStatus(). Only issue should be set, but this is user-facing content returned from the AdSense API. Other user-facing messages/strings generated in that function should be moved closer to the components that output the strings.
  • Move sendAnalyticsTrackingEvent() calls to the component that actually renders the scenario they are tracking instead of in one large function.
  • A nice-to-have: if Adsense E2E tests are not written yet but can be written with test data, it would be wise to test their existing output first and then verify the newly-architected solution still outputs the same thing.

Changelog entry

  • Simplify AdSense account status detection as a base for easier future enhancements and fixes.
@adamsilverstein adamsilverstein added the Type: Enhancement label Aug 21, 2019
@felixarntz felixarntz added the P0 label Aug 26, 2019
@felixarntz felixarntz assigned felixarntz and unassigned felixarntz Aug 26, 2019
@tofumatt tofumatt self-assigned this Sep 2, 2019
@tofumatt
Copy link
Collaborator

@tofumatt tofumatt commented Sep 2, 2019

The action item for this issue that specifies "messages should be moved to AdSenseSetupInstructions" concerns me a bit; that's already a reasonably large component, and moving a lot of the extra props it expects to receive into this component is going to make it pretty intense and hard to manage.

This seems another good candidate for moving things into a data store rather than just to a different component.


There's also the specification to "Use a switch statement at component mount to construct strings/data based on status/reason", but I don't know why we would only set this data on component mount. What's the reason for this specificity? I think we can construct the strings on render, not only on mount.


I'm also unsure about "Also move calls to sendAnalyticsTrackingEvent out of the utility function up into AdSenseModuleStatus where a single call can handle sending the tracking status"—looking at the code base, it seems there are a lot of different branches with different statuses to send, but moving that up to the component means replicating all that if/else branching logic just a level up. Maybe those events should be attached to the components rendering that step?


The main issue with that function—to my eyes—is how detached it is from the component rendering its content. I started an IB for this one, but that function seems to be doing a lot and isn't too documented so I might be missing things. 😓

@tofumatt tofumatt assigned tofumatt and felixarntz and unassigned tofumatt Sep 2, 2019
@felixarntz
Copy link
Member

@felixarntz felixarntz commented Sep 3, 2019

@tofumatt

Do not set strings in getAdSenseAccountStatus(); any messages/strings generated in that function should be moved closer to the components that output the strings.

Just a minor clarification, the issue variable should contain user-facing strings, however these would come directly from AdSense APIs. So you might wanna clarify this to "not set WP translation strings".

The action item for this issue that specifies "messages should be moved to AdSenseSetupInstructions" concerns me a bit; that's already a reasonably large component, and moving a lot of the extra props it expects to receive into this component is going to make it pretty intense and hard to manage.

That's a fair point, however all these messages depend on the accountStatus / issue props passed. I agree this is not optimal, but the AdSense process is in itself fairly complex in the requirements of all the different scenarios we need to support. I'm not sure it makes sense to rely on a data store to get user-facing translation strings and links etc. that depend on the account status. I think, while a big switch clause based on accountStatus increases the size of this component quite a bit, it's still easy enough to follow for now and a more decoupled solution than having all this logic intertwined with the detection of the actual accountStatus.

There's also the specification to "Use a switch statement at component mount to construct strings/data based on status/reason"

I can't comment on this since I didn't write this (note that the "Acceptance criteria" are the "official" list of things to look out for), but I agree with you, this should happen in render().

looking at the code base, it seems there are a lot of different branches with different statuses to send, but moving that up to the component means replicating all that if/else branching logic just a level up. Maybe those events should be attached to the components rendering that step?

Agreed, that makes more sense to me.

The main issue with that function—to my eyes—is how detached it is from the component rendering its content. I started an IB for this one, but that function seems to be doing a lot and isn't too documented so I might be missing things.

Indeed, and this is only the start to making it easier to follow and understand. Because of the complexity, I want to keep this issue fairly constrained to only moved all the variables dependent on the actual "source of truth" variables (accountStatus and issue, plus clientId although it's weird that also comes from there, but let's not worry about that now) out of it. It's a start and will already make the function a bit easier to follow. Once that is done we can start actually simplifying the logic in it.

@felixarntz felixarntz assigned tofumatt and unassigned felixarntz Sep 3, 2019
@felixarntz
Copy link
Member

@felixarntz felixarntz commented Sep 3, 2019 •

Btw the rest of the IB that you already wrote looks good (except for the detail about the strings being set, which I mentioned at the top of the above comment). Would be great if you could update it based on the discussion.

@tofumatt tofumatt assigned felixarntz and unassigned tofumatt Sep 3, 2019
@felixarntz
Copy link
Member

@felixarntz felixarntz commented Sep 3, 2019

IB ✅

@felixarntz felixarntz removed their assignment Sep 3, 2019
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Sep 4, 2019

A nice-to-have: if Adsense E2E tests are not written yet but can be written with test data, it would be wise to test their existing output first and then verify the newly-architected solution still outputs the same thing.

Not yet written unfortunately, but I agree it would be safer to refactor with test coverage in place. Most of these are currently parked in Revisit Later.

@tofumatt tofumatt self-assigned this Sep 11, 2019
@tofumatt
Copy link
Collaborator

@tofumatt tofumatt commented Sep 11, 2019

As mentioned: it would be safer to refactor this after E2E tests are implemented, but even without writing them as part of this PR (before changes are made), this looks to be a considerable/meticulous refactor.

Right now the approach getAdSenseAccountStatus() takes is to return the kitchen sink, so pairing it down will likely require refactoring and a lot of testing.

Because this involves AdSense as well (which we currently have a minimal local development/testing story for), I see this as a medium-sized issue because either development or QA will involve a user without a reliable AdSense account.

@lilybonney lilybonney added this to the 1.0.0-beta.1.0.7 milestone Sep 15, 2019
@tofumatt tofumatt self-assigned this Sep 17, 2019
@felixarntz felixarntz removed this from the 1.0.0-beta.1.0.7 milestone Sep 25, 2019
@felixarntz felixarntz added this to the 1.0.0-beta.1.0.8 milestone Sep 25, 2019
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Oct 15, 2019

@felixarntz CR ✅

@felixarntz felixarntz removed this from the 1.0.0-rc milestone Oct 16, 2019
@lilybonney lilybonney added this to the 1.0.2 milestone Nov 4, 2019
@lilybonney lilybonney removed this from the 1.0.2 milestone Nov 4, 2019
@felixarntz felixarntz assigned tofumatt and unassigned felixarntz Nov 4, 2019
@tofumatt tofumatt assigned felixarntz and unassigned tofumatt Nov 12, 2019
@felixarntz felixarntz added this to the 1.0.4 milestone Nov 12, 2019
@felixarntz felixarntz removed their assignment Nov 12, 2019
@cole10up cole10up self-assigned this Nov 12, 2019
@cole10up
Copy link

@cole10up cole10up commented Nov 15, 2019

Tested

SK01:
Final state:
image

Current state:
image
image

Confirmed multiple Adsense states status haven't changed from final to current.

Refactoring the Adsense test user spreadsheet utilizing a test management tool going forward.

Passed QA ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 Type: Enhancement
Projects
None yet
Development

No branches or pull requests

7 participants