Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

472
Views
Código JS genera error en Google Tag Manager

Estoy tratando de agregar el siguiente código en GTM para medir 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>

Este código funciona en la consola, pero cuando intento publicarlo en GTM, genera un mensaje de error como el que se muestra a continuación.

No estoy seguro de qué está mal con el código, ya que debería ser compatible con ECMA16 para GTM

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sí, GTM es bastante lento en lo que respecta a la adopción de ES6. Lo adoptó parcialmente para cosas como plantillas, pero ni siquiera allí. Y obviamente no lo adoptó para las etiquetas html personalizadas.

Lo que tendrá que hacer es reescribir su código para que sea compatible con ES5. O puede usar babel para hacer una transición automática. se verá así:

 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 });

Probablemente no necesites todo el try catch y finalmente, pero babel está siendo honesto con lo que hace.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!