尝试在Google跟踪代码管理器中发布对讲机代码的更改时,为什么会出现JavaScript编译器错误? [英] Why am I getting a JavaScript compiler error when trying to publish changes to my intercom tag in Google Tag Manager?

查看:102
本文介绍了尝试在Google跟踪代码管理器中发布对讲机代码的更改时,为什么会出现JavaScript编译器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的标签:

<script>
    window.intercomSettings = {
        app_id: "fanwstw2"
    };
</script>
<script>
    (function() {
        var w = window;
        var ic = w.Intercom;
        if (typeof ic === "function") {
            ic('reattach_activator');
            ic('update', intercomSettings);
        } else {
            var d = document;
            var i = function() {
                i.c(arguments)
            };
            i.q = [];
            i.c = function(args) {
                i.q.push(args)
            };
            w.Intercom = i;

            function l() {
                var s = d.createElement('script');
                s.type = 'text/javascript';
                s.async = true;
                s.src = 'https://widget.intercom.io/widget/fanwstw2';
                var x = d.getElementsByTagName('script')[0];
                x.parentNode.insertBefore(s, x);
            }
            if (w.attachEvent) {
                w.attachEvent('onload', l);
            } else {
                w.addEventListener('load', l, false);
            }
        }
    })()
</script>

这是错误消息

推荐答案

我也遇到了这个问题,我相信这是因为基于ES5引擎的GTM正在查看ES6代码,并试图将其解析为ES5. .它可能来自if块中的l()函数声明.尝试将其移出if块,就像在它之前一样,然后再次编译标签,如下所示:

I had this issue as well, and I believe it's because GTM, which is based on the ES5 engine, is seeing ES6 code and trying to parse it as ES5. It is likely coming from your l() function declaration within the if block. Try to move that out of the if block, like just before it and compile the tag again, like this:

(function() {
    var w = window;
    var ic = w.Intercom;

    // moved this out of if block
    function l() {
        var s = d.createElement('script');
        s.type = 'text/javascript';
        s.async = true;
        s.src = 'https://widget.intercom.io/widget/fanwstw2';
        var x = d.getElementsByTagName('script')[0];
        x.parentNode.insertBefore(s, x);
    }

    if (typeof ic === "function") {
        ic('reattach_activator');
        ic('update', intercomSettings);
    } else {
        var d = document;
        var i = function() {
            i.c(arguments)
        };
        i.q = [];
        i.c = function(args) {
            i.q.push(args)
        };
        w.Intercom = i;

        if (w.attachEvent) {
            w.attachEvent('onload', l);
        } else {
            w.addEventListener('load', l, false);
        }
    }
})()

这篇关于尝试在Google跟踪代码管理器中发布对讲机代码的更改时,为什么会出现JavaScript编译器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆