无法让 "if statement" 在 google 标签管理器中工作
Cant get "if statement" to work in in google tag manager
正在尝试将 if 语句添加到我在 google 标签管理器中的自定义 javascript 变量以从结帐购物车中检索值。
根据客户是否输入促销代码,价值的抓取位置出现在两个不同的位置。我正在尝试使用 if 函数对它们进行排序,但它不起作用。
有人找到解决方案吗?
这是代码:
function() {
var MBA = document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[3].innerText.match(/^.{1}(.*).{0}/i)[1].trim();
var YB = document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[5].innerText.match(/^.{1}(.*).{0}/i)[1].trim();
var YA = document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[3].innerText.match(/^.{1}(.*).{0}/i)[1].trim();
if (MBA = "0.00/month") {
return YB;
} else {
return YA;
}
}
澄清一下,当我在控制台中输入这个变量时:
document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[3].innerText.match(/^.{1}(.*).{0}/i)[1].trim()
确实 return“0.00/月”。
您可以使用比较运算符代替赋值:
(MBA === "0.00/月") 或 (MBA == "0.00/月") 如果你不需要严格的平等检查。
现在你做的是赋值操作,而不是比较。 (MBA = "0.00/月")
正在尝试将 if 语句添加到我在 google 标签管理器中的自定义 javascript 变量以从结帐购物车中检索值。
根据客户是否输入促销代码,价值的抓取位置出现在两个不同的位置。我正在尝试使用 if 函数对它们进行排序,但它不起作用。
有人找到解决方案吗?
这是代码:
function() {
var MBA = document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[3].innerText.match(/^.{1}(.*).{0}/i)[1].trim();
var YB = document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[5].innerText.match(/^.{1}(.*).{0}/i)[1].trim();
var YA = document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[3].innerText.match(/^.{1}(.*).{0}/i)[1].trim();
if (MBA = "0.00/month") {
return YB;
} else {
return YA;
}
}
澄清一下,当我在控制台中输入这个变量时:
document.querySelectorAll(".xc-base>main>.add-subscription-page>.xc-form.add-subscription-page>.receipt-container>div>span")[3].innerText.match(/^.{1}(.*).{0}/i)[1].trim()
确实 return“0.00/月”。
您可以使用比较运算符代替赋值:
(MBA === "0.00/月") 或 (MBA == "0.00/月") 如果你不需要严格的平等检查。 现在你做的是赋值操作,而不是比较。 (MBA = "0.00/月")