An evaluator is custom JavaScript code that runs on the page and returns a value based on data that exists on the page. You can create evaluators to use for:
- Custom targeting conditions: For example, if a user's age exists on your data layer, an evaluator can return this information so that you can target experiences based on the user's age.
- Variable values in templates: For example, if a user's name exists on the page, an evaluator can return the name and use it in a template. This lets you render the name in a variation and create a more personalized user experience.
- Real-time values in custom filtering rules: For example, an evaluator can return the difference between the current cart value and the free-shipping threshold, and request products with a higher price than the evaluator value.
See our Developer Docs for technical information and evaluator code examples.
Creating an evaluator for websites
- Go to Assets › Evaluators and click Add New.
- Enter a name and notes (optional).
- Define the value type and expected values. These will affect how conditions built on the evaluator will behave:
- Value type: Specify String or Number. If you select Number, the targeting conditions will enable you to specify greater than or less than values. If you select String, you can only target based on values that contain the string.
- Expected values (optional): This limits the available values when using the evaluator as a targeting condition. The specified values are added in a dropdown menu. For example, if your evaluator checks whether the user is logged in or not, you can set expected values to True or False.
- Use the preview to review how the targeting condition will look and behave.
- Click Next, and write your JavaScript code in the editor. See our Developer Docs for more information.
- Click Save. Creating, editing, and deleting evaluators can take up to 5 minutes to take effect.
Targeting based on evaluator values
As soon as an evaluator is created, it appears under the Custom Evaluator condition, under the Where? category. A list of all evaluators is available as part of creating the condition. Depending on the type of value set for the evaluator, you can select the operator and values in the condition. Learn more about targeting conditions.
Rendering the evaluator value in a template
It is sometimes useful to render an evaluator value in a template. For example, if user's first name exists on the page, and you want to show a personal message with the user's first name. You can do this by changing the variable type to Evaluator.
This replaces the variable with the evaluator value. You can also set a fallback text, in case the evaluator doesn't return any data.
Note that for an evaluator value to display inside a template, the evaluator can't run asynchronously. See the code example earlier in this article.
See Creating Templates to learn more about variables and templates.
Filtering recommendations based on evaluator values
You can use evaluators as rule values in strategy custom filters to get recommended products based on dynamic data. For example, you can set an evaluator to request recommended products that match information about a user that is available in the session, such as gender or location.
To use an evaluator, select Use real-time value in the rule settings. All relevant evaluators are displayed in a dropdown menu.
For more information about strategy rules, see Recommendation Custom Filter Rules.
Copying evaluators between sites
You can copy any evaluator to a different site in the same Dynamic Yield account. Hover over the evaluator, click the Copy button, and select the destination.
Viewing experiences affected by each evaluator
In the evaluator list, you can see how many experiences and strategies are using each evaluator as a targeting condition or custom filtering rule in the Used by column. Click the number to drill down and see every experience or strategy that is using the evaluator. This is important to check before editing or deleting an evaluator, to make sure you are aware of how the change will affect your site.