# Recommendation Strategies Creation

{% hint style="info" %}
When changing the strategy, the platform suggests an update of the versions of all the experiences where the strategy is used.
{% endhint %}

### **Strategy Creation**

To create a strategy, you need to go to the “Strategies” section → “Create Strategy”.

When you click on the “Create Strategy” button, you will be directed to the following screen:

<figure><img src="/files/8OuztdxPVLBq4MqFgEE6" alt=""><figcaption></figcaption></figure>

**Here you can:**

1. Name your strategy;
2. Include notes about the created strategy to make it easier for your colleagues to understand its purpose;
3. Select the type of page where the strategy will be executed. There are 5 types of pages available (this selection influences the list of accessible algorithms for that specific page type):

<div align="left"><figure><img src="/files/ZtdEzklwyjns31r5Sgj7" alt=""><figcaption></figcaption></figure></div>

4. Choose the strategy algorithm.&#x20;

{% hint style="warning" %}
Some algorithms are accessible for only certain page types. More information about recommendation algorithms: [Recommendation Strategies](/lang/en/platform-interface/recommendation-strategies.md)
{% endhint %}

{% hint style="info" %}
For the Popularity algorithm, you have the option to enable the "shuffle" of displayed products.

<img src="/files/djJaIBK7vS8LCWBmWtCr" alt="" data-size="original">
{% endhint %}

5. If required you can select the algorithm for each slot of the strategy.

![](/files/yrPl44ARvNIXMP7YnI2A)

{% hint style="info" %}
When using different algorithms in different slots of the recommendation strategy, only a pin rule will be available in the Custom Filter Rules for individual slots.
{% endhint %}

6. Activate preset filters. For example, you can exclude products that have already been purchased or viewed by the user or include products from the same category as the currently viewed product.

{% hint style="warning" %}
Different algorithms may have different filters available.
{% endhint %}

<div align="left"><figure><img src="/files/BjBfZ6gGFa5CzzlMuiv6" alt="" width="318"><figcaption></figcaption></figure></div>

7. Custom filter rules. When you click on the "+ New Rule", the following window will open:

<div align="left"><figure><img src="/files/6EFny2c4iKM96f6cY4Sn" alt="" width="359"><figcaption></figcaption></figure></div>

<table data-header-hidden><thead><tr><th width="233"></th><th></th></tr></thead><tbody><tr><td><strong>Item in the screenshot</strong></td><td><strong>Available actions</strong></td></tr><tr><td>1</td><td>Set the name of the rule similar to the name of the strategy;</td></tr><tr><td>2</td><td>Select if the rule applies to all slots or specific slots of the strategy;</td></tr><tr><td>3</td><td><p>Specify the type of rule:</p><p> - include only products with properties A, B, C, </p><p>- exclude products with properties A, B, C, </p><p>- pin specific SKUs to the specified slots.</p></td></tr><tr><td>4</td><td>Specify inclusion conditions based on product properties using "AND", "OR" or "NOT" operators;</td></tr><tr><td>5</td><td>Save or cancel changes.</td></tr></tbody></table>

8. Save and create the strategy or cancel changes.

### **Pin Rule (Locking a Position in a Specific Slot)**

The pin rules allow you to lock specific items in specific strategy slots. Any property could be selected for locking (for example, you can lock a specific SKU). Essentially, pinning is manually placing a product in the slot to promote a selected position. In this case, the recommendation algorithm won’t work in that slot.

<div align="left"><figure><img src="/files/KEeZTH7aLDNVcc2C7DRG" alt="" width="462"><figcaption></figcaption></figure></div>

### **How Conditions Work**

1. <mark style="color:red;">**`Price`**</mark> is the only field recognized by the system as a **number**. This means that when setting a filtering rule for it, you can specify an exact value rather than choosing from a list of options:

<div align="left"><figure><img src="/files/GtRimQhVvsW9nzQG7QbU" alt="" width="468"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
&#x20;If you want to specify a price range, the rule should be constructed as "Price GREATER THAN 'A' AND Price LESS THAN 'B'." The option "Price GREATER THAN 'A' OR Price LESS THAN 'B'" is incorrect.
{% endhint %}

2. For the <mark style="color:red;">**`price`**</mark> field, there is a set of applicable conditions.&#x20;

These include:

* equal;
* more than;
* at least;
* less than;
* at most.

For other fields, the set of conditions includes:

* is;
* is not;
* contains;
* empty;
* is not empty.

{% hint style="info" %}
The "contains" condition only works for matches at the beginning of the string.
{% endhint %}

### **Dynamic Filters**

You also have the option to filter the strategy response using dynamic filters on top of the conditions set when configuring strategies. This type of filtering allows you to make rules dependent on the item the user is currently viewing on their screen.

For example, if you wish to display items that are within a specific price range (+-20%) of the currently viewed item or recommend only "on-sale" items to users who are currently on "on-sale" item pages, you will need to configure a dynamic filter.&#x20;

Unlike the filters described above, dynamic filters for front-end campaigns are set directly in the variation code using JS functions, while for back-end campaigns, they are established through additional parameters in the API calls.

**Example** of a JS function that can exclude products from the final output if their price differs by 50% from the original:

<pre class="language-jsx"><code class="lang-jsx">function <a data-footnote-ref href="#user-content-fn-1">getRules</a>() {
  const rules = [];
  const currentPrice = getCurrentPrice();
  if (!currentPrice) return rules;

  const gte = currentPrice*0.5;
  const lte = currentPrice*1.5;

  rules.push({
    id: 1,
    type: 'include',
    slots: [],
    query: {
      conditions: [
        {
          field: 'price',
          arguments: [
            {
              action: 'less_or_equal',
              value: [lte],
            },
          ],
        },
        {
          field: 'price',
          arguments: [
            {
              action: 'more_or_equal',
              value: [gte],
            },
          ],
        },
      ],
    },
  });
  return rules;
}
</code></pre>

[^1]:


---

# 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/recommendation-strategies-creation.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.
