site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Fix refactored AdSense module screen to behave similar to legacy one

Open felixarntz opened this issue 5 years ago β€’ 6 comments

Bug Description

The refactored version of the AdSense module screen is missing one specific required behavior that is present in the legacy version: If there is no data available, it should show a special state, rather than the regular CTA summary that other module screens show.

In addition, there is another thing that is simply a bug: It attempted to show me Analytics data for my AdSense account, even though I don't have Analytics connected.

For reference about both of these issues, two screenshots here:

Legacy state (expected behavior) Screen Shot 2021-07-02 at 9 58 15 AM

Refactored state (incorrect behavior about both things above) Screen Shot 2021-07-02 at 9 58 30 AM

To replicate:

  1. Use an AdSense account/site where you don't have any impressions (yet).
  2. Connect AdSense, but not Analytics.
  3. Toggle the widgets.moduleScreens feature flag. If enabled, you see the above incorrect UI. If disabled, you see the expected UI.

While those two bugs are somewhat decoupled, they should be small enough and are in a related place so it should be good to fix them both as part of this issue.


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

Acceptance criteria

With the widgets.moduleScreens flag enabled:

  • The refactored AdSense widgets which require Analytics should only request data if the Analytics module is also active and connected, in addition to AdSense.
  • If the AdSense module screen is in a complete "zero data" state, instead of showing the blue CTA, the same UI that is present in the first screenshot above should be displayed.
  • Essentially, the user-facing experience should be similar to the one with the feature flag disabled.

Implementation Brief

Only request Analytics data when Analytics module is active and connected

In assets/js/modules/adsense/components/module/ModuleTopEarningPagesWidget/index.js:

  • wrap the exported component in the WhenActive HOC, passing 'analytics' as the moduleName prop, so that it is only loaded if the Analytics module is both connected and active

Show special state component when there is no AdSense data

In assets/js/modules/adsense/components/module/ModuleOverviewWidget/index.js

  • In the zero data case, modify the returned code so that the DashboardZeroData component is returned as well as WidgetReportZero.

  • WidgetReportZero should be hidden using the HIDDEN_CLASS CSS class from widgets/util.

  • Both should be wrapped in a <Widget noPadding> wrapper.

    For example:

    if ( /* zero data */ ) {
      return (
      	<Widget noPadding>
      		<DashboardZeroData />
      		<div class={ HIDDEN_CLASS }>
      			<WidgetReportZero moduleSlug="adsense" />
      		</div>
      	</Widget>
      )
    }
    

Peripheries

Test Coverage

  • No new tests required; existing tests should pass.

Visual Regression Changes

  • VRT images will need updating to reflect these two new scenarios.

QA Brief

  • You'll need to compare the legacy UI with the new one, so open a tab with the widgets.moduleScreens feature enabled, and follow the steps to reproduce above. The UI in question is on the AdSense module page.
  • Open a second tab, switch the widgets.moduleScreens off, and navigate to the AdSense module page to see the legacy UI.
  • Compare the tabs: the new UI should be the same as the legacy UI.

Changelog entry

  • Fix message for AdSense account with no data in new widget-based screen.

felixarntz avatar Jul 02 '21 17:07 felixarntz

Refactor these two files so that the data is only requested from Analytics if the Analytics module is both connected and active

@johnPhillips – the outlined approach for this part sounds a bit manual. Let's use the whenActive HOC for this as that's exactly what we need. No fallback or incomplete components needed πŸ‘

if there is no data, rather than displaying the WidgetReportZero component, display the DashboardZeroData component

This is correct, but it's important to note that the DashboardZeroData component shouldn't be wrapped with a Widget as the WidgetReportZero currently is.

Also, I don't think this would hide the other widget on the page if Analytics was connected. We should either update DashboardZeroData so that it sets the same widget state as WidgetReportZero, or render them both (using WidgetReportZero from props) but hiding WidgetReportZero so that only DashboardZeroData is visible. Then the other widget would check the widget state and return WidgetNull if the main widget's state was ReportZero. Does that make sense?

aaemnnosttv avatar Jul 06 '21 12:07 aaemnnosttv

Let's use the whenActive HOC for this as that's exactly what we need. No fallback or incomplete components needed

This is really helpful, thanks. Looks like DashboardTopEarningPagesWidget is already using it and requires both Analytics and AdSense to be active. Should ModuleTopEarningPagesWidget require both modules to be active as well, or just Analytics?

update DashboardZeroData so that it sets the same widget state as WidgetReportZero

Do you mean literally the same state, i.e. with ReportZero as the Component?


useWidgetStateEffect( 
 'adsenseModuleTopEarningPages', 
  ReportZero, 
  { moduleSlug: 'adsense' },
);

There seem to be a few layers of abstraction with WidgetReportZero and I'm not sure how many to replicate. If I take this approach:

  • should I use the same pattern as with ReportZero / WidgetReportZero, i.e. leave DashboardZeroData as-is, and create a wrapper (the analogue of WidgetReportZero) that calls useWidgetStateEffect? Or should I just add the effect to DashboardZeroData (I'm wary of breaking something - it does seem to be used in a couple of places, but I think they are all legacy...)?
  • I'm guessing I should create a constant for the widget slug ('adsenseModuleTopEarningPages') so that it can be passed to useWidgetStateEffect, and then use it to replace the string in the index file?

Then the other widget would check the widget state and return WidgetNull if the main widget's state was ReportZero. Does that make sense?

I'm unclear on what 'the other widget' and 'the main widget' refer to here, sorry. πŸ™ˆ

johnPhillips avatar Jul 06 '21 15:07 johnPhillips

Looks like DashboardTopEarningPagesWidget is already using it and requires both Analytics and AdSense to be active. Should ModuleTopEarningPagesWidget require both modules to be active as well, or just Analytics?

@johnPhillips DashboardTopEarningPagesWidget requires both because it's a (main) dashboard widget. Widgets are always registered regardless of module activation so the HOC includes both there because users will be able to access the dashboard before activating any additional modules. ModuleTopEarningPagesWidget is for the module dashboard only which is only reachable if AdSense is connected, so we don't need to include AdSense for that too, just like we don't check if Analytics is active for its Module*Widget components.

There seem to be a few layers of abstraction with WidgetReportZero and I'm not sure how many to replicate

I think the better route is to not replicate any of it, and render both – the only caveat is that we need to hide the report zero component so that we get the benefit of its effect without the display.

E.g.

// const ModuleOverviewWidget = ( { Widget, WidgetReportZero, WidgetReportError } ) => {
// ... 
	if ( /* zero data */ ) {
		return (
			<Fragment>
				<DashboardZeroData />

				<div class={ HIDDEN_CLASS }>
					<WidgetReportZero moduleSlug="adsense" />
				</div>
			</Fragment>
		)
	}

I'm unclear on what 'the other widget' and 'the main widget' refer to here, sorry. πŸ™ˆ

Yeah, sorry for the ambiguity there. By "other widget" here I meant on the module screen, i.e. ModuleTopEarningPagesWidget – the one other than the overview above πŸ™‚

I hope that clarifies things a bit more. Let me know if you have any other questions though.

aaemnnosttv avatar Jul 06 '21 17:07 aaemnnosttv

@aaemnnosttv Thanks for this, it clarifies things.

I agree, I think route B is the more sensible one. I've edited the IB accordingly. The only divergence is from this:

it's important to note that the DashboardZeroData component shouldn't be wrapped with a Widget as the WidgetReportZero currently is.

I found that adding <Widget noPadding> looked pretty identical to the legacy UI (which uses a div with googlesitekit-layout googlesitekit-layout--fill classes applied. Was there another reason to avoid Widget, or was it just for the padding?

johnPhillips avatar Jul 07 '21 13:07 johnPhillips

Was there another reason to avoid Widget, or was it just for the padding?

I don't think so. If it looks right then that should be fine πŸ‘ Thanks!

IB βœ…

aaemnnosttv avatar Jul 08 '21 10:07 aaemnnosttv

QA Update: Pass βœ…

Tested this with a site that has active AdSense account but no data.

With the widgets.moduleScreens flag enabled:

  • The AdSense module screen is in a complete "zero data" state, instead of showing the blue CTA as per the screenshot.

Comparing this with the widgets.moduleScreens flag disabled:

The user-facing experience is the same to the one with the feature flag enabled.

image

wpdarren avatar Jul 14 '21 15:07 wpdarren