Fix refactored AdSense module screen to behave similar to legacy one
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)

Refactored state (incorrect behavior about both things above)

To replicate:
- Use an AdSense account/site where you don't have any impressions (yet).
- Connect AdSense, but not Analytics.
- Toggle the
widgets.moduleScreensfeature 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
WhenActiveHOC, passing'analytics'as themoduleNameprop, 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
DashboardZeroDatacomponent is returned as well asWidgetReportZero. -
WidgetReportZeroshould be hidden using theHIDDEN_CLASSCSS class fromwidgets/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
- Double check Storybook - the 'Data Unavailable' story for the module overview component should show the new zero data component.
- VRT images may need updating.
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.moduleScreensfeature 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.moduleScreensoff, 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.
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
WidgetReportZerocomponent, display theDashboardZeroDatacomponent
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?
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. leaveDashboardZeroDataas-is, and create a wrapper (the analogue ofWidgetReportZero) that callsuseWidgetStateEffect? Or should I just add the effect toDashboardZeroData(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. π
Looks like
DashboardTopEarningPagesWidgetis already using it and requires both Analytics and AdSense to be active. ShouldModuleTopEarningPagesWidgetrequire 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
WidgetReportZeroand 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 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?
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 β
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.
