Need help with custom evaluators
Hello.
We have a newssite where customer can buy subscriptions. And they get specific product codes based on what they have bought.
This codesnippet outputs the product codes:
headerScripts.getUserData().active_products;
I saved it just as it is as an evaulator (string).
If I use (with my evaulatorid) in developer tools:
DYO.Q(DYO.CoreUtils.safeEval(DYO.oevals[EVALUATOR_ID].code))
.then(function(result) {
console.log(“Returned value from evaluator:”, result);
});
The output becomes:
Returned value from evaluator: (2) ["gpdigitalny", "gp_digital_bas_product"]
If I understand it correctly, I get in this case two values.
In my targeting condition I select in “where”:
Custom Evaulator > myevaulatorname > is > gp_digital_bas_product
I assume my skills with javascript combined with how it is supposed to work with Dynamic Yield is limited.
Any advice on what to do here? I hope I explained myself as clear as possible here
Kind regards
Johan
-
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_productBut 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:


-
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 (sincegp_digital_bas_productis contained ingpdigitalny,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) -
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_campaignAs i see it, using “contains” as target condition will trigger them booth?
Kind regards
Johan -
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.
-
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
Please sign in to leave a comment.
Comments
10 comments