Any reason why Google Tag manager uses hidden IFrame solution? I am referring to this page https://developers.google.com/tag-manager/quickstart. Why does it not use the script DOM element approach, like the one described here http://www.stevesouders.com/blog/2008/12/27/coupling-async-scripts/? Thanks.
Google代码管理器使用隐藏IFrame解决方案的原因是什么?我指的是此页面https://developers.google.com/tag-manager/quickstart。为什么它不使用脚本DOM元素方法,如此处描述的那样http://www.stevesouders.com/blog/2008/12/27/coupling-async-scripts/?谢谢。
1 个解决方案
#1
2
I thought the same thing when I first saw it. The IFrame is actually wrapped in a <noscript>
, meaning it will only be used when JavaScript is disabled.
我第一眼看到它时就想到了同样的事情。 IFrame实际上包含在
I added spacing for illustrative purposes:
为了说明目的,我添加了间距:
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-ABCD"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABCD');
</script>
#1
2
I thought the same thing when I first saw it. The IFrame is actually wrapped in a <noscript>
, meaning it will only be used when JavaScript is disabled.
我第一眼看到它时就想到了同样的事情。 IFrame实际上包含在
I added spacing for illustrative purposes:
为了说明目的,我添加了间距:
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-ABCD"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABCD');
</script>