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 Tag Manager is disabled via googlesitekit_available_modules

See original GitHub issue

Bug Description

Similar to #5072, but for covering the case that the Tag Manager module is not available (e.g. via googlesitekit_available_modules filter): There will be JS errors at least in the Analytics setup as it unconditionally calls modules/tagmanager selectors.


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

Acceptance criteria

  • Any references to modules/tagmanager 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/tagmanager.
    • A good way to tackle this is to search for any MODULES_TAGMANAGER references in those other module directories and adjust/wrap them accordingly.
    • At a minimum, the check needs to ensure that the respective MODULES_TAGMANAGER datastore is available before calling a selector or action on it.

Implementation Brief

  • Find all instances of select( MODULES_TAGMANAGER )/dispatch( MODULES_TAGMANAGER ) and ensure that isModuleAvailable( MODULES_TAGMANAGER ) is true before using those selectors/dispatching those actions.
  • Find instances of isModuleActive( MODULES_TAGMANAGER ) and check for isModuleAvailable( MODULES_TAGMANAGER ).

Note: any code in any module should be checked, not just Tag Manager specific code. Be sure to look for Tag Manager selectors/action dispatches across the whole plugin when making these changes.

Test Coverage

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

QA Brief

  • Add the filter below to your WordPress site, e.g. in your theme’s functions.php.
  • Set up the Analytics module and ensure there are no errors due to Tag Manager not being available.

Filter

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

Changelog entry

  • Fix bug that caused errors to appear in Analytics module when Tag Manager module is not available.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
tofumattcommented, Jun 13, 2022

@hussain-t I see this was assigned a month ago before the IB/approach in #5071 was finalised. Since I wrote up that IB I’m going to handle this and #5072, because there’s a lot of overlap 🙂

0reactions
mohitwpcommented, Nov 1, 2022

QA Update ✅

  • Verified on both latest and dev environment using QAB.
  • On latest environment I’m able to reproduce issue.
  • On dev environment errors are not showing if Tag Manager module is not available.

https://user-images.githubusercontent.com/94359491/199218497-59bdd92f-7bef-4b13-9c96-0e87a969d4f2.mp4

Read more comments on GitHub >

github_iconTop Results From Across the Web

JS errors if Analytics is disabled via ...
Bug Description Now that we have the googlesitekit_available_modules filter available (#3993) some administrators may run into various ...
Read more >
Google Tag Manager Errors - Tag Assistant Help
Invalid or missing account ID. Data layer fields should be quoted. Consolidate your tags with Google Tag Manager. Code found outside of <body>...
Read more >
Google Tag Manager 404 error (gtm.js 404)
A quick solution to Google Tag Manager 404 error (gtm.js 404), also known as 404 not found for GET: GET ...
Read more >
Disable google tag manager according to the decision of ...
My understanding is that the <noscript> tag is present for cases where Javascript is disabled. Then the tracking will be done via an...
Read more >
Use Tag Manager with a Content Security Policy
Enable the container tag to use CSP; Custom JavaScript Variables ... Then use the nonce-aware version of the inline Tag Manager container code....
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