简体   繁体   English

尝试在Google跟踪代码管理器中发布对讲机代码的更改时,为什么会出现JavaScript编译器错误?

[英]Why am I getting a JavaScript compiler error when trying to publish changes to my intercom tag in Google Tag Manager?

This is my tag: 这是我的标签:

<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>

This is the error message 这是错误消息

在此处输入图片说明

I can't see any issue with your code, maybe it's the parser being overly awkward. 我看不到您的代码有任何问题,也许是解析器过于笨拙。 It could also be caused by you wrapping within an IIFE. 它也可能是由您将IIFE包裹而引起的。

How about changing this line below (just to rule it out being weird).. 如何在下面更改此行(只是为了排除它的怪异)。

ic('update', intercomSettings);

To this... 为此...

ic('update', w.intercomSettings);

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. 我也遇到了这个问题,我相信这是因为基于ES5引擎的GTM正在查看ES6代码,并试图将其解析为ES5。 It is likely coming from your l() function declaration within the if block. 它可能来自if块中的l()函数声明。 Try to move that out of the if block, like just before it and compile the tag again, like this: 尝试将它移出if块,就像之前一样,然后再次编译标签,如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在Colfusion中使用JavaScript将src属性添加到img标签时,为什么会出现错误? - Why am I getting an error when trying to add the src attribute to an img tag using JavaScript within Colfusion? JavaScript 编译器错误 - Google 跟踪代码管理器 - JavaScript compiler error - Google Tag Manager JavaScript Google 标签管理器中的编译器错误 - JavaScript compiler error in Google tag manager 对讲ECMASCRIPT6标签管理器错误 - Intercom ECMASCRIPT6 Tag Manager Error Google 标签管理器中的 Javascript 编译器错误:解析错误。 预期的主要表达 - Javascript Compiler Error in Google Tag Manager: Parse error. primary expression expected Google跟踪代码管理器自定义JavaScript解析错误 - Google Tag Manager Custom JavaScript Parse Error 自定义Google跟踪代码管理器JavaScript错误 - Error in Custom Google Tag Manager JavaScript JavaScript解析错误-Google跟踪代码管理器 - Javascript parse error - Google Tag Manager Google跟踪代码管理器中的Javascript编译器错误:仅ECMASCRIPT6模式或更高版本支持此语言功能 - Javascript Compiler Error in Google Tag Manager: this language feature is only supported for ECMASCRIPT6 mode or better 尝试使用StageWebView在AIR Android应用程序中实现Google Maps JavaScript API时,为什么会出现“ InvalidValueError”错误? - Why am I getting “InvalidValueError” error when trying to implement Google Maps JavaScript API in an AIR Android application using StageWebView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM