Search

Mar 28, 2023

Magento 2.3.3 Bug Javascript on Google Tag Manager module

We are using Google tag manager and got a bug on product detail page. After click add to cart button, the mini cart didn't update qty. The main reason is by google tag manager js. 


Step by step:

1. Go to detail page

2. Choose Color, Size and click add to cart 

3. Item is added but the mini cart didn't update qty 

4. Open web console log via F12 button and saw javascript error Uncaught TypeError: Cannot read property 'forEach' of undefined at the file /Magento_GoogleTagManager/js/google-tag-manager-cart.js


SOLUTION:

Please follow the patch file

diff --git a/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js b/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js
index 2d6e9ac7..2a9c115b 100644
--- a/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js
+++ b/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js
@@ -172,15 +172,17 @@ define([
             var product;

             this.options.temporaryEventStorage.forEach(function (item, index) {
-                item.productIds.forEach(function (productId) {
-                    product = this.getProductById(productId);
+                if (item.productIds) {
+                    item.productIds.forEach(function (productId) {
+                        product = this.getProductById(productId);

-                    if (!_.isUndefined(product['product_sku']) && parseInt(product.qty, 10) > 0) {
-                        this.options.actions[item.type](product);
-                    }
+                        if (!_.isUndefined(product['product_sku']) && parseInt(product.qty, 10) > 0) {
+                            this.options.actions[item.type](product);
+                        }

-                    this.options.temporaryEventStorage.splice(index, 1);
-                }.bind(this));
+                        this.options.temporaryEventStorage.splice(index, 1);
+                    }.bind(this));
+                }
             }.bind(this));
         },

How to increase caching time for the third-party script links by using FASTLY config

Question: 

How to increase caching time for the third-party script links by using FASTLY config?

How to setup cache long time for the 3rd scripts? We want increase caching for them?

Do fastly support to do this?


Answer: 

Is it not possible for control caching for third party scripts. Even if those scripts were using Fastly, their TTLs is something that is controlled by the owners.

Maybe some of those scripts can be hosted locally on your website, but it would require you to keep them updated and probably could run into many compatibility issues.

This has been a known issue for a long time because people want to score 100% in PageSpeed: https://stackoverflow.com/questions/29162881/pagespeed-insights-99-100-because-of-google-analytics-how-can-i-cache-ga