You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在GTM中添加Web Core Vitals监测JS代码报错该如何处理?

你提供的代码存在变量名拼写错误,这是触发GTM发布报错的核心原因:

  • PerformanceObserver 回调的入参名为 entryList,但你在 for 循环调用 getEntries() 方法时,误写为 entrytList,多了一个多余的 t 字符
  • GTM 的静态语法校验规则会检测所有未声明的变量,拼写错误的 entrytList 属于未定义变量,因此直接触发发布拦截。你在浏览器控制台测试时未报错,大概率是测试时的代码没有出现该拼写失误,或是运行环境中刚好存在同名全局变量

修正后的代码如下,替换到GTM中即可正常发布:

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

内容的提问来源于stack exchange,提问作者Learning

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 14:45:03