Google标签Manger / Inframe在Div / Div / Works Preview模式下工作,但在生产中不使用
我正在尝试将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:
and then for the tag, I have this:
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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试使其成为匿名,自我执行的功能?
Have you tried making it an anonymous, self-executing function?