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

Analytics widgets not displaying in view-only dashboard without UA connected #6824

Closed
nfmohit opened this issue Apr 5, 2023 · 8 comments
Closed
Labels
Exp: SP Module: Analytics Google Analytics module related issues P0 High priority Type: Bug Something isn't working

Comments

@nfmohit
Copy link
Collaborator

nfmohit commented Apr 5, 2023

Bug Description

When the Analytics module is connected in Site Kit with only GA4 without UA, we've encountered issues with Dashboard Sharing not working as expected. #6745 aims to solve the module sharing settings synchronisation for the module owners, but there's another issue where the Analytics widgets do not show up in the view-only dashboard at all if UA is not connected.

Steps to reproduce

  1. Set up Analytics in Site Kit with only GA4 entities, not connecting UA (or connecting it!).
  2. Using the Dashboard Sharing settings modal, share the Analytics 4 module with other admins.
  3. Log into the site as another admin user. Access the Site Kit view-only dashboard.
  4. Notice that no Analytics widgets show up.

Screenshots

image

Additional Context

This happens because the widgets registered for Analytics are specified to the analytics module. Example:

widgets.registerWidget(
'analyticsAllTraffic',
{
Component: ( widgetProps ) => (
<GA4DashboardWidgetSwitcher
UA={ DashboardAllTrafficWidget }
GA4={ DashboardAllTrafficWidgetGA4 }
{ ...widgetProps }
/>
),
width: widgets.WIDGET_WIDTHS.FULL,
priority: 1,
wrapWidget: false,
modules: [ 'analytics' ],
},
[
AREA_MAIN_DASHBOARD_TRAFFIC_PRIMARY,
AREA_ENTITY_DASHBOARD_TRAFFIC_PRIMARY,
]
);

Without UA connected, the analytics module doesn't come up as a shareable and a viewable module. We need to update the modules array so that it conditionally sets analytics or analytics-4 based on the current dashboard view.


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

Acceptance criteria

  • The Analytics widgets should show up correctly in the view-only dashboard, regardless of how they're set up (with or without UA & GA4).

Implementation Brief

Allow the dashboardView setting to be retrieved in view-only mode.

Update client-side settings to allow initial values to be passed in.

Within assets/js/googlesitekit/data/create-settings-store.js:

  • Update createSettingsStore() to support an additional optional settings property passed in options.
  • settings should be an object of setting keys to values, and it should be used as the value of settings in initialState.

Within assets/js/googlesitekit/modules/create-module-store.js:

  • Extend createModuleStore() to allow settings to optionally be passed in, and pass this through to createSettingsStore().

Add the current dashboardView setting to the _googlesitekitDashboardSharingData global.

Within includes/Modules/Analytics.php:

  • Add a filter hook for googlesitekit_dashboard_sharing_data.
  • Within the filter hook callback, check if the current mode is view-only, by checking $this->authentication->is_authenticated() - if it returns false, the mode is view-only.
  • If the mode is view-only, add a dashboardView key to the data object with the value of the current dashboardView setting.

Provide the dashboardView setting to client-side Analytics settings when in view-only mode.

Within assets/js/modules/analytics/datastore/base.js:

  • Check to see if dashboardView is defined on the global _googlesitekitDashboardSharingData object.
  • If so, pass a settings object with dashboardView as the only property to the createModuleStore() call.

Replace GA4DashboardWidgetSwitcher with an approach that allows the module list for a widget to be defined with the correct Analytics module.

Allow widget definitions to include an optional isActive() callback which is passed a registry select function.

Within assets/js/googlesitekit/widgets/datastore/widgets.js:

  • Update registerWidget() to allow an optional isActive() callback to be passed as part of settings.
    • Ensure this is passed through as part of the payload.
  • Update getWidgets() to use createRegistrySelector(), and update the filtering of the widgets to include a check for widget.isActive( select ) if the isActive() callback is defined.

Remove GA4DashboardWidgetSwitcher and instead create two definitions for each of the widgets, only one of which will be active based on the value of isGA4DashboardView().

For each widget that currently uses GA4DashboardWidgetSwitcher:

  • Revert the definition passed to registerWidget() to directly use the UA version of the widget component instead of using GA4DashboardWidgetSwitcher.
  • Add an isActive( select ) callback to the definition that returns the result of ! isGA4DashboardView().
  • Duplicate the registerWidget() call and modify it to make a GA4 version:
    • Append GA4 to the widget slug.
    • Use the GA4 version of the widget component.
    • Change analytics to analytics-4 in the module list.
    • Invert the returned value of the isActive() callback.

Remove GA4DashboardWidgetSwitcher.

Update GA4 widget shared module checks

Within each of the relevant GA4 widgets, update the call to canViewSharedModule( 'analytics' ) to instead check the analytics-4 module. These calls can be found in the following files:

  • assets/js/modules/analytics/components/dashboard/DashboardAllTrafficWidgetGA4/index.js
  • assets/js/modules/search-console/components/dashboard/SearchFunnelWidgetGA4/index.js
  • assets/js/modules/search-console/components/dashboard/SearchFunnelWidgetGA4/Overview/index.js

Test Coverage

  • Add test coverage for all of the changes apart from the widget definition updates and the shared module checks in the components.

QA Brief

  • Set up Site Kit and Analytics with the ga4Reporting feature flag disabled.
  • Keeping the ga4Reporting feature flag disabled, test the "Module Sharing Settings" for Analytics within the Dashboard Sharing Settings modal. Verify that the usual Universal Analytics widgets are rendered for both, the logged in admin as well as the view-only user with who the settings have been shared with (via their role).
  • With the ga4Reporting feature flag enabled, ensure the 'Dashboard View' setting toggle is "off" so that Universal Analytics data is still shown on the dashboard. For a new site, this should be the default case anyways. Verify the Universal Analytics widgets are rendered for the admin and view-only user as usual.
  • Switch the 'Dashboard View' setting toggle in Analytics settings to "on" to enable GA4 data on the dashboard. Verify the new GA4 widgets are rendered for both, the admin and view-only user.
  • Switch off the 'Enable Universal Analytics' setting toggle in Analytics settings. Verify that the new GA4 widgets are still rendered for both, the admin and view-only user.

Changelog entry

  • Fix bug that caused Analytics 4 widgets not to appear in shared dashboard.
@nfmohit nfmohit added Type: Bug Something isn't working P0 High priority Module: Analytics Google Analytics module related issues labels Apr 5, 2023
@nfmohit nfmohit self-assigned this Apr 5, 2023
@nfmohit nfmohit removed their assignment Apr 6, 2023
@jimmymadon
Copy link
Collaborator

jimmymadon commented Apr 6, 2023

@nfmohit On the latest develop, in my testing, this behaviour happens even when UA is connected. This is occurring on the latest main branch as well - so it probably hasn't been introduced via #6745 which is only merged into develop for now. Unfortunately, this is now blocking the completion and testing of #6687 which ensures GA4 widgets display data on the Shared Dashboard.

Screen.Recording.2023-04-06.at.23.34.14.mov

c.c. @aaemnnosttv @eclarke1

UPDATE: I can see you've set #6687 as a blocker to this issue. I think this should be the other way round as the errors within #6687 do not appear anymore (and hence cannot be fixed as such) since we are having different permission errors for analytics which are part of this issue.

@aaemnnosttv
Copy link
Collaborator

Thanks @jimmymadon – this one is ready to go if you'd like to write the IB for it. I've removed the blocker that was assigned here since it's in QA now anyways.

@jimmymadon jimmymadon self-assigned this Apr 6, 2023
@jimmymadon
Copy link
Collaborator

jimmymadon commented Apr 7, 2023

In addition to the problem @nfmohit has identified in the Issue Description (conditionally adding analytics or analytics-4 within the widget registration params), we need to somehow fetch the new dashboardView setting on the view only dashboard. This is because the <GA4DashboardWidgetSwitcher> relies on this setting. Currently, no module settings are fetched in the viewOnly dashboard.

I'm not quite sure what the solution should be here. Do we want to somehow store the above setting as part of the "Sharing Settings" or just expose this individual setting on a separate rest endpoint?

@nfmohit
Copy link
Collaborator Author

nfmohit commented Apr 7, 2023

@nfmohit On the latest develop, in my testing, this behaviour happens even when UA is connected.

Thank you for sharing your findings, @jimmymadon. However, in my tests, it seems widgets do show up when UA is connected. Here is a screencast:

1.mp4

However, I completely agree that it hasn't occurred as a result of #6745. I just discovered this issue while testing #6745.

For now, I have removed #6687 as a blocker for this issue. However, the dependency can be adjusted after further testing.

Thanks!

CC: @techanvil @aaemnnosttv

@techanvil techanvil removed their assignment Apr 10, 2023
@tofumatt tofumatt self-assigned this Apr 10, 2023
@tofumatt
Copy link
Collaborator

@techanvil and I chatted about alternative approaches here, like one where we allowed "one of any of these modules" instead of "all of these modules".

Unfortunately that wouldn't work for the adsenseTopEarningPages widget which would need "this module and one of these modules".

So this approach will do the trick, and @techanvil pointed out it's straightforward to remove later as well.

IB ✅

@tofumatt tofumatt removed their assignment Apr 11, 2023
@jimmymadon jimmymadon self-assigned this Apr 11, 2023
@jimmymadon jimmymadon removed their assignment Apr 13, 2023
@tofumatt tofumatt assigned tofumatt and jimmymadon and unassigned tofumatt Apr 13, 2023
@tofumatt tofumatt assigned tofumatt and unassigned jimmymadon and tofumatt Apr 14, 2023
@mohitwp mohitwp self-assigned this Apr 14, 2023
@mohitwp
Copy link
Collaborator

mohitwp commented Apr 14, 2023

QA Update ❌

@jimmymadon

  • Tested on dev.
  • I've notice below issues in widget when 'ga4Reporting' is enabled and Dashboard view is Ga4 and analytics and search console is in gathering data state.
  • Note : If site is not in gathering state then widgets are showing correctly for all scenarios mentioned under QAB.

Issue 1 :
For Admin 1 All traffic widget showing in gathering state but on view only dashboard and for 2nd logged in admin it is showing in zero data state.

Admin 1

image

Admin 2:

image

View only dashboard

image

Issue 2 : Top content over the last 28 days widget not loading for 2nd logged in admin and on view only dashboard.
Note : It is happening with search console widgets also, which are in gathering state.

image

image

image

@aaemnnosttv
Copy link
Collaborator

I opened a follow-up PR which should address some of the issues here.

Regarding the gathering state vs zero state for a view-only user, this may be something that we won't be able to have exactly consistent because the gathering state uses data from the property itself which is not available in a shared context.

Top content over the last 28 days is showing for me on both view-only and non-viewonly dashboards in GA4 mode.

@nfmohit nfmohit assigned nfmohit and unassigned nfmohit Apr 17, 2023
@tofumatt tofumatt assigned tofumatt and mohitwp and unassigned tofumatt Apr 17, 2023
@mohitwp
Copy link
Collaborator

mohitwp commented Apr 18, 2023

QA Update ✅

@jimmymadon @aaemnnosttv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Exp: SP Module: Analytics Google Analytics module related issues P0 High priority Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants