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:

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()

It does return "0.00/month".

149 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 https://herreramedical.org/hydroxychloroquine

    Reply
  2. I have been exploring for a little for any high quality articles or weblog posts in this kind of space . Exploring in Yahoo I finally stumbled upon this web site. Studying this information So i’m happy to convey that I have an incredibly good uncanny feeling I found out just what I needed. I so much for sure will make sure to don’t disregard this site and provides it a glance on a continuing basis.

    Reply

Leave a Comment