question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow Analytics to be removed as an available module without breaking Site Kit

See original GitHub issue

Bug Description

If Google Analytics has been disabled via googlesitekit_available_modules (https://github.com/google/site-kit-wp/issues/3993) ensure that the option to setup Analytics isn’t included for other admins who decide to set up the plugin.

Screenshots

image

https://user-images.githubusercontent.com/41326532/162797693-acce4a38-0451-48a3-be7c-a4c84fcff6d3.mp4

Steps to reproduce

  1. Disable Analytics via the below filter
  2. Install and setup SK
  3. The option to add GA remains

Note that GA is never added to the setup steps, so the setup flow does complete successfully if a user proceeds. Google Analytics isn’t connected at any stage, and the option to connect doesn’t appear, nor for the setup CTAs.

add_filter(
	'googlesitekit_available_modules',
	function ( $modules ) {
		return array( 'search-console' );
	}
);

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

Acceptance criteria

  • Site Kit should not raise errors due to the Analytics module being programatically removed as an available module
  • It is okay not to worry about potentially “weird” looking UI due to not showing certain Analytics information, since this is a special case that we are not going to specifically support through clean UI. In other words, e.g. the Analytics setup CTAs are perfectly fine to be replaced with nothing, i.e. simply white-space. The same applies to the Analytics notice on the splash screen, which should simply not show and therefore behave in a similar way as if Analytics was already active (in which case it already doesn’t show today).

Implementation Brief

As outlined in my comment below, I think the ACs need adjusting because they suggest a particular implementation, but in this case I think we can simplify the approach a fair bit. 🙂

The issue above stems from the fact that we’re using false-y checks for isModuleConnected instead of explicitly checking for === false. As @felixartnz mentioned below, rather than “simply” adding a === null check we should add a new selector: isModuleAvailable( slug ) that allows us to check whether a module is at all available before selecting anything from its store or rendering data related to it.

Everywhere else the sole isModuleConnected(slug) (“false-y”) checks are accurate and can remain.

  • We should also adjust places where we’re checking for isModuleActive( slug ) and first check isModuleAvailable( slug ) to ensure the module is available before we check if it’s active. This can be done everywhere we use isModuleActive()

Test Coverage

  • Add tests to the setup file (and components that render CTAs) that check to see if the Analytics CTAs are output when Analytics is not available.
  • If the datastore approach is taken, we should test to make sure we don’t make fetch requests when Analytics selectors with resolvers are called when Analytics is disabled.

QA Brief

  • Add the filter below to your WordPress site, e.g. in your theme’s functions.php.
  • Set up Site Kit and ensure the Analytics CTA doesn’t show on the splash screen.
  • Access the various Site Kit areas (main dashboard, entity dashboard, WP dashboard widget, admin bar menu), and ensure there are no errors due to Analytics not being available.
  • Check the Tag Manager module still works.
  • Note that the Optimize module will also be removed due to its dependence on Analytics.

Filter

add_filter( 'googlesitekit_available_modules', function ( $modules ) {
	return array_diff( $modules, array( 'analytics' ) );
} );

Changelog entry

  • Decouple core and modules from Analytics module availability.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
felixarntzcommented, May 2, 2022

@tofumatt IB mostly looks good, a few small notes:

  • Add a new selector to the CORE_MODULES data store: isModuleAvailable( slug ). It should accept a module slug as the sole argument, and return:
  • undefined if isModuleConnected( slug ) === undefined
  • false if isModuleConnected( slug ) === null
  • true if neither of the above conditions are met

It strikes me a bit odd to rely on isModuleConnected here. This is simply about whether the module exists, and while I’m all for reusing code, I think using getModule here instead better represents its purpose. isModuleConnected also checks something else in addition to whether the module exists, we essentially don’t care about its true vs false state. Hence relying on getModule here is sufficient and a bit closer to the purpose.

  • Adjust components to not output Analytics component when the module is not available. Here’s a list of places we’re checking for a false-y isModuleConnected

I think we may want to also reference any false-y isModuleActive selector calls here, since that can also apply in a few places. Like anywhere that we render some sort of CTA for Analytics when it’s not active, we should also not render such a thing, i.e. add the isModuleAvailable check to the condition.

0reactions
mohitwpcommented, Oct 3, 2022

QA Update ✅

  • Verified on dev and latest environment.
  • I’m able to reproduce issue on latest environment.
  • Verified following steps mentioned under QAB.
  • Verified that the Analytics CTA doesn’t show on the splash screen.
  • Verified that user is able to access site kit dashboard successfully.
  • Verified that successful message for analytics set up is not showing.
  • Verified that analytics and optimize module removed successfully.
  • Verified that Site Kit not raising errors due to the Analytics module being programmatically removed as an available module.
  • Verified that main, entity dashboard, WP dashboard and WP menu bar not showing any error.
  • Verified tag manager is connected successfully, not showing any error and working.
  • Verified GTM snippet in page source.

https://user-images.githubusercontent.com/94359491/193585244-0f6cd10f-d8e6-4b1e-b106-c5eabcbd4d8c.mp4

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Site Kit breaks my pages - WordPress.org
Hi whenever I activate Site Kit this is what happens to my sites pages. See the link – https://imgur.com/a/vTJFbF0. The site as it...
Read more >
Fixing common issues with Site Kit - Google
General questions or issues about the services that connect to Site Kit (AdSense, Analytics, Optimize, PageSpeed Insights, Search Console, and Tag Manager) are ......
Read more >
Drupal-Friendly Google Tag Manager Configuration with the ...
Collect richer analytics data using Google Tag Manager with the Drupal 8 dataLayer Module.
Read more >
Add Page Break - Qualtrics
If you are using timing questions, you will not want to set automatic page breaks in the Look and feel menu, and should...
Read more >
Google Analytics Spreadsheet Add-on
Query and report data from multiple views. Compute and display custom calculations. Create visualizations and embed those visualizations on third-party websites ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found