Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

470
Vistas
JS code generates error in Google Tag Manager

I am trying to add following code in GTM to measure Web Core Vitals

<script type="text/javascript">
new PerformanceObserver((entryList) => {    
    for (const entry of entrytList.getEntries()) {
        const elm = entry.element;
        console.log(elm);
    }   
}).observe({type: 'largest-contentful-paint', buffered:true});
</script>

This code works in Console but when i try to publish it in GTM it generates error message as below

Not sure what is wrong with the code as it should support ECMA16 for GTM

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Yes, GTM is pretty slow when it comes to ES6 adoption. It partially adopted it for things like templates, but not fully even there. And obviously it didn't adopt it for custom html tags.

What you'll have to do is rewrite your code to be ES5 compliant. Or you can use babel to do an automated transition. it will look like this:

new PerformanceObserver(function (entryList) {
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
        for (var _iterator = entrytList.getEntries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
            var entry = _step.value;

            var elm = entry.element;
            console.log(elm);
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally {
        try {
            if (!_iteratorNormalCompletion && _iterator.return) {
                _iterator.return();
            }
        } finally {
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
}).observe({ type: 'largest-contentful-paint', buffered: true });

You probably don't need all the try catch and finally, but babel is being honest with what it does.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda