[英]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.