Javascript: This language feature is only supported for ECMASCRIPT_2015

230 Views Asked by At

I have simple script in new version of Javascript which I need to use in Google Tag Manager.

Google Tag Manager not supporting new Javascript so my script is necessary to be in older version of Javascript.

I already changed all my const's and let's to var's and script still not working.

How I can change it to older version of Javascript and make it functional in Google Tag Manager?

My Script:

function getFromDataLayer(key) { 
    var result = null; 
    dataLayer.push(function() { 
        var value = this.get(key);
        if (value) {
            result = value;
        }
    });
    return result;    
};

var ecom = getFromDataLayer('ecommerce.purchase.products');

var filterValue = "Krups";
var filteredProducts = ecom.filter(val.brand.includes(filterValue));
//console.log(filteredProducts);
return filteredProducts.reduce((n, {price}) => n + parseInt(price), 0)
0

There are 0 best solutions below