Custom Evaluator Not Working

Comments

2 comments

  • Ronen Tamari

    The reason that although the plain code (from the console) seems to run as expected while the targeting condition of your notification campaign does not work as you desire is that the evaluator's code runs without waiting for the "CartJS.cart.items" variable.


    There are a few ways for how this issue can be resolved, but here are the common two approaches:

    1. The simpler way that doesn't require any adjustments in the evaluator's code is to simply set a waiting condition to the notification campaign itself. This will delay the targeting conditions' evaluation until the condition you will specify is going to be triggered. 

      Specifically in your case, you can make the campaign wait for the "CartJS.cart.items" variable to be available:
      ​​
      The limitation of using this method is that no experiences under this campaign are going to be served if "CartJS.cart.items" is not going to get defined. 
      Otherwise, it is a perfectly good path to take. 

    2. The second approach is to account for the waiting of this variable directly in the evaluator's code itself (async code or a JS promise). You can do this by using a method like the following:

    DYO.CoreUtils.waitForVariable('CartJS.cart.items', 50).then(function(){
    // Write your callback function here!
    })

    To learn more about the best practices in using evaluators feel free to refer to this Knowledge Base article.

    Comment actions Permalink
  • Eli Stevens

    Ronen, thank you so much for your extremely well written response.

    I suspected it was something with timing and the evaluator firing before elements were loaded. I learned a lot about the DY system.

    I took the 1st approach, and it worked perfectly. Thanks!

    Comment actions Permalink

Please sign in to leave a comment.