【问题标题】:How to implement custom html into body with Google Tag Manager如何使用 Google Tag Manager 将自定义 html 实现到正文中
【发布时间】:2021-12-23 00:49:00
【问题描述】:

我需要实现

<img src="url" width="1" height="1" style="display:none" />

在 Google 跟踪代码管理器(和你们)的帮助下进入开头。

如何做到这一点?

【问题讨论】:

  • 我想说的是:在body中实现img src标签

标签: google-tag-manager


【解决方案1】:

Javascript 只允许追加到正文的末尾 - 因此,您必须在正文的第一个孩子之前插入,而不是追加到正文。

创建自定义 HTML 标记,然后插入

<script>
// create the image
    var img = document.createElement("img");
// set properties such as a weird example url and style
    img.src = "https://www.kukksi.de/wp-content/uploads/2020/05/19-Disney-13-Goofy-und-Max.jpg";
    img.style = "display:none";
// insert before the first child element of the body, which will place the element at the beginning of the body
    document.body.insertBefore(img, document.body.firstChild);
</script>

我不得不说,很难想象一个有效的用例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2021-12-03
    • 1970-01-01
    • 2018-10-12
    相关资源
    最近更新 更多