magento2: Blocking Google Analytics prevents Checkout
Preconditions
- Magento 2.2.1
- PHP 7.0.25-1~dotdeb+8.1
- mysql Ver 15.1 Distrib 10.0.32-MariaDB
- uBlock Origin 1.14.18 on client
Steps to reproduce
- Enable Google Analytics in Stores > Settings > Configuration > Sales >Google API
- Install uBlock Origin on client, or block Google Analytics in any other AdBlocker
- Go to Checkout
Expected result
- Checkout is working
Actual result
- Checkout is loading infinitely
The rest of the site works fine. Apparantly the checkout just cannot handle any errors and will stop functioning immediately.
GET http://example.com/pub/static/frontend/Magento/luma/en_US/Magento_GoogleAnalytics/js/google-analytics.js net::ERR_BLOCKED_BY_CLIENT
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 13
- Comments: 34 (13 by maintainers)
We should be able to control if we want to be tracked or not. If the final user want to have an ad blocker he’s free. Actually a third party as the google analytics shouldn’t broke the core functionality. It’s a major issue because we can’t control (and we never should) if our customers has an AdBlocker or not…
This seems to be related to magento/magento2#13061 and #12828 . The pr doesn’t appear to fix this issue though.
Even if you replace the x-magento-init block in Magento_GoogleAnalytic\view\frontend\templates\ga.phtml with…
…which shouldn’t be able to kill any javascript flow, checkout-loader is still not cleared and the checkout doesn’t work.
Error thrown is:
Caught error (printed as a warning is:
I’m not sure I understand requirejs enough to work out whats going wrong. I assume the error thrown by require.js:1895 which is not caught (?) is the culprit but I can’t see how.
Just commenting out the script fixes the cart, so it doesn’t have to load to work.
Fixed in 2.2.6; https://github.com/magento/magento2/blob/2.2.6/lib/web/mage/requirejs/resolver.js#L51
For enterprise maintainers using
Magento_GoogleTagManager, #14874 does not fix the problem.I applied the latest version of resolver.js and this does fix the problem as the whole
isPendinglogic was revised by Magento core team.Another solution is to just set the
require.onErrorhandler.You just need to create a template and add it before everything in the
after.body.startblock.The added benefit of this solution is that it’ll catch any uncaught error during the requireJS process.
I am not suggesting this should be the actual solution, but here is a work around, since I don’t understand where the blocking comes from (although @andrewhowdencom seems to have an idea).
It just tries to load the .js file using jquery first, only if this is successful does it allow require to have a run at it. If the jquery request fails there appears to be no adverse effects. If require fails there are, so don’t let it even try until we know it works.
Thank You So Much @peterjaap
Hi!
Can you try if this helps? https://github.com/magento/magento2/pull/14874
@spectravp problem is, you don’t always want bundling enabled. And it should not matter if it’s enabled or disabled.
I’ll try to find out what the cause is and how to fix the loader thing.
I think adding the requireJS onError handler is a permanent solution.
This certainly is an issue. I can confirm it for the 2.2.3 version.
For anyone having the same Issue:
Check your Ad-Blocker settings 😉