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.

JS errors if Analytics is disabled via googlesitekit_available_modules

See original GitHub issue

Bug Description

Now that we have the googlesitekit_available_modules filter available (https://github.com/google/site-kit-wp/issues/3993) some administrators may run into various dashboard errors if Google Analytics is disabled, possibly due to Analytics dependency or due the module having already been connected before then being programmatically disabled.

https://user-images.githubusercontent.com/41326532/162795661-a044d95e-d17b-4ecb-82cd-a000dd033db9.mp4

Example of JS errors include the below:

Error one: An error occurred while running 'mapSelect': Cannot read properties of null (reading 'getServiceReportURL')

Occurs if Analytics was already connected before being programaticaly disabled

`An error occurred while running ‘mapSelect’: Cannot read properties of null (reading ‘getServiceReportURL’) The error may be correlated with this previous error: TypeError: Cannot read properties of null (reading ‘getServiceReportURL’) at Object.eval [as current] (webpack-internal:///./assets/js/modules/search-console/components/dashboard/SearchFunnelWidget/Footer.js:120:101) at onStoreChange (webpack-internal:///./node_modules/@wordpress/data/build-module/components/use-select/index.js:135:46) at eval (webpack-internal:///./node_modules/@wordpress/data/build-module/components/use-select/index.js:155:7) at commitHookEffectList (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:22030:26) at commitLifeCycles (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:22080:9) at commitLayoutEffects (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:25344:7) at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:336:14) at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:385:16) at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:440:31) at commitRootImpl (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:25082:9)

Original stack trace:

in Footer (created by WidgetFooter)
in WidgetFooter (created by Widget)
in div (created by Widget)
in div (created by Widget)
in Widget (created by WithWidgetSlug(Widget))
in WithWidgetSlug(Widget) (created by SearchFunnelWidget)
in SearchFunnelWidget (created by WidgetRenderer)
in WidgetRenderer (created by WidgetAreaRenderer)
in div (created by Cell)
in Cell (created by WidgetCellWrapper)
in WidgetCellWrapper (created by WidgetAreaRenderer)
in div (created by Row)
in Row (created by WidgetAreaRenderer)
in div (created by WidgetAreaRenderer)
in div (created by ForwardRef)
in ForwardRef (created by WidgetAreaRenderer)
in WidgetAreaRenderer (created by WidgetContextRenderer)
in div (created by WidgetContextRenderer)
in WidgetContextRenderer (created by DashboardMainApp)
in DashboardMainApp (created by DashboardEntryPoint)
in DashboardEntryPoint
in RestoreSnapshots (created by Root)
in ErrorHandler (created by Root)
in Root`

image

Error two: Cannot read properties of undefined (reading 'hasGTMAnalyticsPropertyID')

Occurs With a GTM placed snippet

Cannot read properties of undefined (reading 'hasGTMAnalyticsPropertyID')

image

image

Steps to reproduce

  1. Connect Site Kit and also GA
  2. Apply the below filter, to ensure only SC is available
  3. Visit your Site Kit dashboard
  4. Error 1 from above will appear
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

  • Any references to modules/analytics or modules/analytics-4 store selectors or actions from a component or store that is part of another module should only occur after verifying that the module is available (available, regardless of whether it is active or not).
    • In other words, this issue should cover all accesses within assets/js/modules/* other than assets/js/modules/analytics and assets/js/modules/analytics-4.
    • A good way to tackle this is to search for any MODULES_ANALYTICS / MODULES_ANALYTICS_4 references in those other module directories and adjust/wrap them accordingly.
    • At a minimum, the check needs to ensure that the respective MODULES_ANALYTICS / MODULES_ANALYTICS_4 datastore is available before calling a selector or action on it.
    • Use reasonable fallback values (e.g. false for a boolean, null for an object, etc.).
  • 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.

Implementation Brief

  • Find all instances of select( MODULES_ANALYTICS )/dispatch( MODULES_ANALYTICS ) and select( MODULES_ANALYTICS_4 )/dispatch( MODULES_ANALYTICS_4 ) and ensure that isModuleAvailable( MODULES_ANALYTICS ) (or isModuleAvailable( MODULES_ANALYTICS_4 ) is true before using those selectors/dispatching those actions.
  • Find instances of isModuleActive( MODULES_ANALYTICS ) and first check for isModuleAvailable( MODULES_ANALYTICS ) (do the same with MODULES_ANALYTICS_4).

Test Coverage

  • Add tests to any components with existing tests that disable Analytics; ensure they still render without errors/console warnings.

QA Brief

  • Set up Site Kit (without activating Analytics).
  • Add the filter below to your WordPress site, e.g. in your theme’s functions.php.
  • Access the Site Kit main dashboard and entity dashboard and ensure there are no errors due to Analytics not being available.

Filter

add_filter(
	'googlesitekit_available_modules',
	function( $modules ) {
		$index = array_search( 'analytics', $modules, true );
		if ( false !== $index ) {
			unset( $modules[ $index ] );
			return array_values( $modules );
		}
		return $modules;
	}
);

Changelog entry

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
felixarntzcommented, Apr 11, 2022

@jamesozzie I’ve also created #5074 to further break this down, as there are also problems when not having Tag Manager available. I believe your “Error two” above actually occurs when removing Tag Manager from the list of modules rather than Analytics.

1reaction
jamesozziecommented, Apr 11, 2022

@felixarntz @aaemnnosttv Just tagging you here for visibility based on our discussion last week. I also created #5071 in relation to the same filter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Analytics Errors - Tag Assistant Help
Solution: Update the tracking code to the asynchrnous version of tracking code to ensure the most relaible Google Analytics data. Detected both ga.js...
Read more >
Track when users have JavaScript disabled with Google ...
Web developers constantly prepare websites to work with JavaScript disabled, so how can we tell if our users are disabling JavaScript with ......
Read more >
Capturing JavaScript Error in Google Analytics ... - Optizent
Enabling Variable to Track JavaScript Errors · 1. Click on Variables options on the links on the left-hand side. · 2. Click on...
Read more >
Hello Analytics API: JavaScript quickstart for web applications
If you run into this issue you should check the Client Library's documentation and if needed see the help documentation. Step 1: Enable...
Read more >
How do I enable basic JavaScript error tracking and reporting ...
Events will have the following details: Event category = JavaScript Errors; Event action = the URL of the page where the error occured,...
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