这是我的标签:
<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
block 中的 l()
函数声明。尝试将其移出 if
block ,就像它之前一样,然后再次编译标记,如下所示:
(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);
}
}
})()
关于javascript - 当我尝试在 Google 跟踪代码管理器中发布对讲机代码的更改时,为什么会出现 JavaScript 编译器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48440623/