Google标签Manger / Inframe在Div / Div / Works Preview模式下工作,但在生产中不使用

发布于 2025-02-05 21:09:23 字数 1484 浏览 0 评论 0原文

我正在尝试将iframe插入带有父级UTM参数的DIV中。为了实现这一目标,我有一个简单的触发器,基于类似的页面网址:

,然后是标签,我有一个:

代码如下,我删除了iframe URL:

​<script type="text/javascript">
  console.log('insert iframe');
 var iframeurl = 'xxx';
 var params = window.location.search.replace('?','');

 var thisScript = document.scripts[document.scripts.length - 1];
 var iframe = document.createElement('iframe');

 iframe.setAttribute('src', iframeurl +'&'+ params);
 iframe.setAttribute('width', '100%');
 iframe.setAttribute('height', '700px');
 iframe.setAttribute('type', 'text/html');
 iframe.setAttribute('frameborder', 0);
 iframe.setAttribute('allowTransparency', 'true');
 iframe.style.border = '0';

getRef = document.getElementById("contest_iframe");
parentDiv = getRef.parentNode;
parentDiv.insertBefore(iframe, getRef);
 

</script>

当我在浏览器控制台中执行代码时,它可以正常工作。当我执行标签助手时,它可以正常工作,但是当我在生产中尝试它时,它不起作用,标签不会触发。

这就是我在助手中看到的:

一切似乎都可以,我不明白为什么它不起作用,我可能错过了某个地方。

你有什么想法吗?

谢谢 劳伦特

I'm trying to insert an iframe into a div with the UTM parameters of the parent URL. In order to achieve this, I have a simple trigger based on page URL like this:
enter image description here

and then for the tag, I have this:
enter image description here

The code is the following, I have removed the iframe url:

​<script type="text/javascript">
  console.log('insert iframe');
 var iframeurl = 'xxx';
 var params = window.location.search.replace('?','');

 var thisScript = document.scripts[document.scripts.length - 1];
 var iframe = document.createElement('iframe');

 iframe.setAttribute('src', iframeurl +'&'+ params);
 iframe.setAttribute('width', '100%');
 iframe.setAttribute('height', '700px');
 iframe.setAttribute('type', 'text/html');
 iframe.setAttribute('frameborder', 0);
 iframe.setAttribute('allowTransparency', 'true');
 iframe.style.border = '0';

getRef = document.getElementById("contest_iframe");
parentDiv = getRef.parentNode;
parentDiv.insertBefore(iframe, getRef);
 

</script>

When I execute the code in my browser console, it works. When I execute the Tag Assistant it works but when I try it in production, it doesn't work, the tag is not fired.

This is what I see in the assistant:
enter image description here

Everything seems to be ok, I don't understand why it doesn't work, I probably have missed something somewhere.

Do you have any idea?

Thanks
Laurent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2025-02-12 21:09:23

您是否尝试使其成为匿名,自我执行的功能?

(function(){
  //your code
})();

Have you tried making it an anonymous, self-executing function?

(function(){
  //your code
})();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文