Cant get "if statement" to work in in google tag manager

Trying to add an if statement to my custom javascript variable in google tag manager to retrieve a value from the checkout cart.

Depending on if the customer puts in a promo code or not, the scraping position of the value appears on two different locations. I’m trying to sort those out with an if function, but it doesn’t work.

Anyone finding a solution?

This is the code:

    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;

And just to clarify, when I du put in this var in the console:


It does return "0.00/month".

40 thoughts on “Cant get "if statement" to work in in google tag manager”

  1. Definitely consider that which you said. Your favorite justification appeared to be at the web
    the easiest factor to understand of. I say to you, I certainly get irked while people think about concerns that they
    plainly don’t understand about. You managed to hit
    the nail upon the top and also defined out the entire thing without having side-effects , people could take a signal.

    Will likely be again to get more. Thank you


Leave a Comment