# Evaluator Creation Flow

Created: April 13, 2023&#x20;

Updated: April 26, 2023

Author: Anastasia N.

## **What is an Evaluator**

An evaluator is JavaScript code that runs on a page and generates a value based on the available information on that page. The value can be generated from a specific element on the page, or as a result of processing the content of a selected element, information stored in cookies, or data stored in a dataLayer.

The value generated from the evaluator can be used for several purposes:

* **Advanced Targeting:**  Evaluators can extract specific data from a web page. For example, if information about the user's age is stored in <mark style="color:red;">**`data`**</mark>**&#x20;attributes** on the page, the evaluator can return this information, allowing targeting based on the user's age.
* **Variations:** For example, if it's possible to retrieve the user's name from the page, the evaluator can return this name as a value. This value can then be used in personalized communication with the user.
* **Filtering Rules:** Evaluators can help in creating filtering rules. For example, the evaluator can return the difference between the current shopping cart's cost and the free shipping threshold. Then, the user can be offered only those products that cost more than this difference.

The evaluator code runs only when an experience that utilizes the evaluator is loaded on the page. Evaluators can run both synchronously and asynchronously.

The code execution timeout for the evaluator is 4 seconds. If the evaluator doesn't return a value within this time frame, it will return "False".

### **Example**

```jsx
new Promise(function (resolve, reject) {
  if (!window.location.pathname.includes('/search/')) {
    resolve('not search');
  } else {
      GF.waitForElement('h1', () => {
          resolve((document.querySelectorAll('aside').length === 0).toString());
      })
  }
});
```

This evaluator checks whether the performed search is empty.

## **Creating an Evaluator**

<figure><img src="/files/GpdymprC3cgET84sio7R" alt=""><figcaption></figcaption></figure>

1. Button to go to [**evaluator creation**](#creating-a-new-evaluator).

### **Creating a New Evaluator**

<figure><img src="/files/Vu8Sb9rDGtWykDUyazB6" alt=""><figcaption></figcaption></figure>

1. Evaluator name.
2. Evaluator description.
3. Expected values of the evaluator (if the set of expected values is limited).
4. Evaluator code.

## **Editing an Evaluator**

<figure><img src="/files/XkYgAVMqSiY8DRGk8GEL" alt=""><figcaption></figcaption></figure>

1. Switch to editing mode by clicking on the "pencil" icon.

### **Editing an Existing Evaluator**

<figure><img src="/files/mXyveY8Ozl9vahf3P3f5" alt=""><figcaption></figcaption></figure>

1. Evaluator name.
2. Evaluator description.
3. Expected values of the evaluator (if the set of expected values is limited).
4. Evaluator code.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.gravityfield.ai/lang/en/platform-interface/evaluator-creation-flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
