Google标签管理器中的自定义JavaScript变量返回false forts for test()
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.