Need help with custom evaluators

Comments

10 comments

  • Meira Farber

    Hi Johan,
    It sounds like

    headerScripts.getUserData().active_products;

    returns an array, and not a string.
    Is this the case? and if so, do you always need value from index 1 ?
    If so, you can try and return

    headerScripts.getUserData().active_products[1]
    Comment actions Permalink
  • Johan Linnarsson

    Thanks for your help.

    Yes it should be an array when you mention it. I tried your suggestion, just to output for instance " gp_digital_bas_product".

    But the condition doesn’t trigger here either.

    But the thing is that a user can have multiple products. And I need to find a way to output them all, and in my targeting condition select the one I would like to target.

    I tried like this:

    headerScripts.getUserData().active_products.toString();

    That outputs:
    gpdigitalny,gp_digital_bas_product

    But that did not seem to work either. What preferred output should I get when I use:

    DYO.Q(DYO.CoreUtils.safeEval(DYO.oevals[EVALUATOR_ID].code))
    .then(function(result) {
    console.log(“Returned value from evaluator:”, result);
    });

    Thanks for your help. I upload some screenshots on how it looks like now:

     

    Comment actions Permalink
  • Meira Farber

     

    Since the result of toString() is:
    gpdigitalny,gp_digital_bas_product
    Targeting by the value IS gp_digital_bas_product will not work.
    You can try using CONTAINS instead of IS (since gp_digital_bas_product is contained in gpdigitalny,gp_digital_bas_product).

    There is also a possibility that the evaluator is running before the object
    headerScripts.getUserData().active_products
    is loaded to the page (since evaluators usually run very early on the page load)

    Comment actions Permalink
  • Johan Linnarsson

    Thanks for your awesome help!! You are correct on booth. 

    It seems to work now, when I also set an delay for the notification to display.

    Let us say a customer have these product codes:
    gp_digital_bas_product,gp_digital_bas_product_campaign

    As i see it, using “contains” as target condition will trigger them booth? 

    Kind regards
    Johan

    Comment actions Permalink
  • Meira Farber

    Happy to help. and yes, that’s correct

    Comment actions Permalink
  • Johan Linnarsson

    I assume there is no way to seperate them? I can’t see any possible issue here, just asking in case of.

    Comment actions Permalink
  • Meira Farber

    Hi Johan,
    How about returning a string, something like:

    '|' + headerScripts.getUserData().active_products.join('|') + '|';


    Then you can target by Evaluator contains ‘|gp_digital_bas_product|’, knowing that all the elements will be surrounded by pipes.

    You can also use Asynchronous Evaluators to build the delay into the targeting.

    Comment actions Permalink
  • Johan Linnarsson

    Ahh yes of course! That is a solution! Thanks for amazing help! 

    Comment actions Permalink
  • Meira Farber

    Just an idea, wrap each item with brackets

    headerScripts.getUserData().active_products.map(function(i){
    return '['+i+']'
    }).toString();

    Now the result will be [gp_digital_bas_product],[gp_digital_bas_product_campaign]
    if you target by CONTAINS [gp_digital_bas_product] it will fall only on the correct one

    Comment actions Permalink
  • Johan Linnarsson

    Thanks I will try that out! 

    Comment actions Permalink

Please sign in to leave a comment.