我可以在Google标签管理器(GTM)中插入使用document.write()的第三方营销标签吗?

Can I insert 3rd party marketing tags that use document.write() into Google Tag Manager (GTM)?

本文关键字:标签 第三方 write document 插入 管理器 Google GTM 我可以      更新时间:2023-09-26

我正在我的GTM (v2)容器中安装第三方营销标签。标签是一个真正的麻烦,使大量使用document.write。虽然Google标签管理器声称支持document.write,但是这些标签在被触发时会抛出javascript错误。下面是这样一个标签的例子:

<script src="http://ib.adnxs.com/seg?add=1958353,6039160&t=1" type="text/javascript">
</script>

这个脚本seg?add=1958353,6039160&t=1继续调用document.write两次:

document.write('<scr'+'ipt type="text/javascript" src="https://js.b1js.com/tagcontainer.js?id=110386891486949186&type=1"></scr'+'ipt>');
document.write('<scr' + 'ipt src="http://cdn.adnxs.com/ib/async_usersync.js"></scr'+'ipt>');

如果我要求GTM为这个标签支持document.write,并将标签设置为在所有页面上触发,我将在页面加载时得到一个错误:

Uncaught TypeError: Cannot read property 'parentNode' of null
Uncaught #<Object>

如果我取消选中GTM的"支持document.write"标签,我将在我的控制台中得到以下警告:

在'Document'上执行'write'失败:除非显式打开外部脚本,否则无法从异步加载的外部脚本写入文档。

我试过推迟标签发射,直到DOM准备好,这适用于我的另一个标签,但不是这个。

我至少有3个标签配置为以这种方式使用document.write,并且在触发时都会抛出相同的错误。请理解,其他不依赖于document.write的标签工作得很好。谢谢你提供的任何帮助或建议。

不确定是否有帮助,但尝试将触发规则设置为gtm。