Google标签管理器中的自定义JavaScript变量返回false forts for test()

发布于 2025-02-14 00:27:38 字数 586 浏览 0 评论 0原文

我正在尝试在Google标签管理器中编写自定义JavaScript变量。我想看看页面代码的正文部分中是否出现某个单词,以区分子类别。到目前为止,我已经:

function(){
{var hasStellar = (document.body);
var result = /stellar/.test(hasStellar);
return result}}

document.body。

".project-template-template-stellar-project.project-template-viewstem" +
"plate-stellar-project.single.single-project.postid-20597.--nav-trans" +
"parent.app-data.index-data.singular-data.s" +
"ingle-data.single-project-data.single-project-data.template-stellar-project-data"

使用 如果有人知道如何解决这个问题,或者是一种更好的方法来解决这个问题,我将不胜感激!

I'm attempting to write a Custom JavaScript variable in Google Tag Manager. I want to see if a certain word appears in the body section of pages' code in order to distinguish subcategories. So far I have:

function(){
{var hasStellar = (document.body);
var result = /stellar/.test(hasStellar);
return result}}

with document.body being:

".project-template-template-stellar-project.project-template-viewstem" +
"plate-stellar-project.single.single-project.postid-20597.--nav-trans" +
"parent.app-data.index-data.singular-data.s" +
"ingle-data.single-project-data.single-project-data.template-stellar-project-data"

When I preview the Custom JavaScript Variable, it returns false. If anyone knows how to fix this, or a better way to do this, I'd appreciate it!

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

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

发布评论

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

评论(1

沩ん囻菔务 2025-02-21 00:27:38

document.body不是字符串。在这里,尝试以下操作:document.body.outerhtml

另外,请确保您的GTM不会被CSP阻止。检查控制台是否错误。

最后,确保您检查变量值的时间在正确填充身体之后。

document.body is not a string. Here, try this out: document.body.outerHTML instead.

Also make sure that your GTM isn't being blocked by CSP. Check the console for errors.

Finally, make sure the time at which you check the value of the variable is after the body is properly populated.

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