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

Check whether a post has Analytics data to determine whether to show admin bar menu

Open bjackson27 opened this issue 7 years ago • 4 comments

Current: Admin bar does not display if search console doesn't have stats.

66bc86d899d7a2e54f5a2f02ccb0c080 66bc7836cc0ffb1836cbe77b9fcdb154

Expected: G logo should appear in the admin bar and expand upon hover if there are stats from any modules (eg. Analytics). This should appear on the Front end and in the admin.


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

Acceptance criteria

  • In order to determine whether to display the Admin bar:
    • check that there are GA stats available for that specific post
    • check that both these stats are not zero

If we have a situation where SC is "gathering data", GA stats are both zero, but we still show the Admin bar, that would be rather underwhelming for users.

Screenshot 2019-07-18 at 18 12 38 (this screenshot is from the main dashboard, but the stats would look similar in the Admin bar)

Implementation Brief

Analytics specific

Add action googlesitekit_show_admin_bar_menu in analytics module to check if analytics has data for the post, the same way search console calls has_data_for_post() https://github.com/google/site-kit-wp/blob/develop/includes/Modules/Search_Console.php#L578 in this hook, add similar method in Analytics module by requesting overview datapoint with permalink argument and save result in transient.

Update delete_all_transients() in Reset.php to remove added transient when reseting Site Kit.

Opportunity for abstraction (possibly separate ticket?)

Modules could be Admin bar aware, and able to inform the Admin Bar whether or not it is active for the current URL and thus better inform the Site Kit admin bar item if it should render or not.

  • Add a new Module_With_Admin_Bar interface
    • Defines a public is_active_in_admin_bar( $url ) : bool method
    • Each module displayed in the admin bar could implement its own logic for whether or not it should be active in the admin bar
  • Add a new with_admin_bar() : Module[] method to Modules
    • Returns an array of all active Module instances that are filtered to only those that implement the Module_With_Admin_Bar interface
  • Add a new set_modules( $modules ) : void method on Admin_Bar where $modules : Module_With_Admin_Bar[]
    • After instantiating Admin_Bar in Plugin, pass the active modules to the instance
    $admin_bar = ( new Core\Admin_Bar\Admin_Bar( $this->context, $assets ) )->register();
    $admin_bar->set_modules( $modules->with_admin_bar() )
    
  • In \Google\Site_Kit\Core\Admin_Bar\Admin_Bar::is_active, check if any of the provided modules is_active_in_admin_bar( $url )
  • No change would likely be necessary on the front yet, but this could be exposed in each module's JS info array if useful

Changelog entry

  • Ensure admin bar displays when at least Search Console or Analytics have stats for the current URL.

bjackson27 avatar Jul 10 '19 19:07 bjackson27

@lucymtc The implementation brief should contain information on how the filter in the Analytics module behaves in relation to the Search_Console module, in regards to the following:

  • If both modules have data for the post, the overall filter result should be true.
  • If none of the two modules have data for the post > result false.
  • If only Search Console has data for the post > result true.
  • If only Analytics has data for the post > result true.

In order to properly handle that while still keeping the filters in isolation, potentially a single centralized filter in the core Modules class would be better suited, calling the respective has_data_for_post() methods of each active module and making the necessary logic concatenation.

The implementation brief will furthermore need some adjustments after #312. We should consider this issue blocked by #312, and revisit the implementation brief once the work on that has been completed.

felixarntz avatar Aug 12 '19 11:08 felixarntz

Moving this to "Revisit Later" as it's currently blocked by #312; since we'll want to revise the IB after #312 is completed, we should hold off on this IB so we don't write it 1.5 times 😉

tofumatt avatar Sep 02 '19 22:09 tofumatt

@aaemnnosttv I really like the suggested abstraction, let's put that in place as part of this issue (this will clearly increase the size of this issue, but that's okay). IB ✅

This issue doesn't have super-high priority, let's just tackle it whenever we find some time for it after the critical bugs have been fixed.

felixarntz avatar Nov 27 '19 06:11 felixarntz

Tested

Confirmed on pages without analytics data and no search console info the admin bar menu isn't displayed

image

Confirmed alternate scenario of no SC data but with Analytics during testing of https://github.com/google/site-kit-wp/issues/314

image

Passed QA ✅

cole10up avatar Feb 27 '20 04:02 cole10up