我可以通过Javascript动态插入Google标签管理器<script>吗?

问题描述 投票:0回答:1

所以我有一个用 VueJS 编写的多租户应用程序,我需要根据数据库中以字符串形式存储的内容插入这些像素。

数据库上的谷歌标签管理器脚本仅用于显示。在生产中 XXXX 被替换为实际 ID

database printscreen showing the code

我已经尝试过这种方式:

// client being the database info.
     
var head = document.getElementsByTagName("head")[0];
head.insertAdjacentHTML("afterbegin", client.customScripts);

它显示在 HTML 上,但无法识别 Google Tag Assitant 上的像素 ID。

javascript vuejs3 google-tag-manager
1个回答
0
投票

您可以:

document.head.innerHTML = client.customScripts + document.head.innerHTML;

但这是一个非常hacky的解决方案。您可能想回顾一下为什么要通过 Javascript 来执行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.