我应该如何在 Google 标签管理器的自定义 javascript 代码中包含 cdnjs 库?
How should I include cdnjs libraries in custom javascript codes in Google tag manager?
我是 Google 分析和 Google 跟踪代码管理器的新手,目前我对使用外部 JS 库感到困惑。任何帮助将不胜感激。
我需要在 google 标签管理器的自定义 javascript 代码中使用“https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.1.0/fingerprint2.min.js”。我试图将脚本作为 自定义 html 甚至 自定义模板 包含在内。脚本成功添加到头部,我在检查中看到了。但是在我的自定义 JS 代码中,当我尝试调用和使用库函数时,它会抛出异常,提示未定义 lib 对象。
我也尝试了排序标签,以确保在我的自定义 js 代码执行之前触发脚本加载标签。但这并没有解决问题。
关于如何在 GTM 自定义 JS 代码中包含外部 JS 库的任何建议?我希望我能正确解释问题。
谢谢!
jwest75674 发布的这个示例应该有所帮助。因为您需要在脚本中声明 var = fingerprint 以允许 Google 跟踪代码管理器在脚本具有 运行
后捕获数据
简而言之,您可以复制下面的脚本并将其添加为 GTM 中的自定义 HTML 标记 (https://github.com/Valve/fingerprintjs2)
<script src="https://cdn.jsdelivr.net/npm/fingerprintjs2@2.1.0/dist/fingerprint2.min.js"></script>
<script type="text/javascript">
var fingerprint; // Variable to allow the Google Tag Manager to capture the data after this script has run.
if (window.requestIdleCallback) {
requestIdleCallback(function () {
Fingerprint2.get(function (components) {
console.log(components) // an array of components: {key: ..., value: ...}
})
})
} else {
setTimeout(function () {
Fingerprint2.get(function (components) {
console.log(components) // an array of components: {key: ..., value: ...}
})
}, 500)
}
</script>
我是 Google 分析和 Google 跟踪代码管理器的新手,目前我对使用外部 JS 库感到困惑。任何帮助将不胜感激。
我需要在 google 标签管理器的自定义 javascript 代码中使用“https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.1.0/fingerprint2.min.js”。我试图将脚本作为 自定义 html 甚至 自定义模板 包含在内。脚本成功添加到头部,我在检查中看到了。但是在我的自定义 JS 代码中,当我尝试调用和使用库函数时,它会抛出异常,提示未定义 lib 对象。
我也尝试了排序标签,以确保在我的自定义 js 代码执行之前触发脚本加载标签。但这并没有解决问题。
关于如何在 GTM 自定义 JS 代码中包含外部 JS 库的任何建议?我希望我能正确解释问题。
谢谢!
jwest75674 发布的这个示例应该有所帮助。因为您需要在脚本中声明 var = fingerprint 以允许 Google 跟踪代码管理器在脚本具有 运行
后捕获数据简而言之,您可以复制下面的脚本并将其添加为 GTM 中的自定义 HTML 标记 (https://github.com/Valve/fingerprintjs2)
<script src="https://cdn.jsdelivr.net/npm/fingerprintjs2@2.1.0/dist/fingerprint2.min.js"></script>
<script type="text/javascript">
var fingerprint; // Variable to allow the Google Tag Manager to capture the data after this script has run.
if (window.requestIdleCallback) {
requestIdleCallback(function () {
Fingerprint2.get(function (components) {
console.log(components) // an array of components: {key: ..., value: ...}
})
})
} else {
setTimeout(function () {
Fingerprint2.get(function (components) {
console.log(components) // an array of components: {key: ..., value: ...}
})
}, 500)
}
</script>