# Campaign evaluation

> Understanding how Talon.One executes one or more campaigns is important to help you build advanced promotion use cases.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

## Evaluate campaigns with promotion rules

:::tip Evaluation summary

The general evaluation order of campaigns with promotion rules is as follows:

1. Information is fetched from [Catalogs][catalogs].
1. [Campaigns](/docs/product/campaigns/overview.md) are evaluated one by one
   according to their [evaluation tree][tree].
   1. Inside each campaign, [cart item filters](/docs/product/rules/cart-item-filters/overview.md)
      are evaluated in their order of appearance in the Campaign Manager.
   1. The rules are evaluated in their order of appearance in the Campaign Manager.
   1. Inside each rule, each condition and [effect](/docs/product/rules/effects/overview.md)
      is also checked and applied in order of appearance.
1. The effects are returned via the [Integration API](/docs/dev/integration-api/overview.md).

:::

## Evaluate campaigns with strikethrough rules

:::tip Evaluation summary

The general evaluation order of campaigns with strikethrough rules is as follows:

1. Talon.One monitors a specific set of [events][stevents] happening in
   [cart item catalogs][catalogs], or in campaigns containing [strikethrough rules][strules].
1. When such an event is triggered, Talon.One evaluates all running campaigns with
   strikethrough rules according to their [evaluation tree][tree].
1. Talon.One sends a request to the URLs set in your [strikethrough pricing notifications][stevents].

:::

:::tip
To learn which events trigger a pricing update, see [Strikethrough pricing updates](/docs/product/applications/application-notifications/overview.md#strikethrough-pricing-updates).
:::

## Evaluate stores-based campaigns

:::important
Stores-based campaign evaluation is applicable only if your Application has stores.
You can create stores in your Application with the [Create store](/management-api#tag/Stores/operation/createStore)
endpoint.
:::

There are two types of stores-based campaign evaluation:
- **All stores**: Your campaign is evaluated for all the stores that are present in
  the Application.
- **Specific stores**: Your campaign is evaluated only for selected stores. Each store is
  linked to the campaign.

### Evaluate all stores-based campaigns

:::tip Evaluation summary

The general evaluation order of **all stores-based campaigns** is as follows:

1. Talon.One receives a customer session with or without store integration IDs.
1. Talon.One checks whether [stores are linked](/docs/product/campaigns/settings/manage-campaign-stores.md#edit-the-stores-linked-to-a-campaign)
   to the campaigns in the Application.
1. Talon.One evaluates all the stores-based campaigns in the Application along with
   the campaigns linked to the store integration IDs passed in the customer
   session, according to their [evaluation tree][tree].
:::

:::note example

Imagine you want to run a campaign offering a discount to customers
irrespective of their stores.

When Talon.One receives a customer session containing the store integration ID *Store_001*,
it evaluates all the campaigns with all stores-based evaluation.

:::

### Evaluate specific stores-based campaigns

:::tip Evaluation summary

The general evaluation order of **specific stores-based campaigns** is as follows:

1. Talon.One receives a [customer session](/integration-api#tag/Customer-sessions)
   with store integration IDs.
1. Talon.One checks whether [stores are linked](/docs/product/campaigns/settings/manage-campaign-stores.md#edit-the-stores-linked-to-a-campaign)
   to the campaigns in the Application.
1. From all the specific stores-based campaigns, Talon.One only
   evaluates those linked to the store integration IDs passed
   in the customer session, according to their [evaluation tree][tree].
:::

:::note example

Imagine you want to run a campaign to offer a discount to customers of
particular stores. These stores have store integration IDs *Store_001*, *Store_007*,
and *Store_010*.

When Talon.One receives a customer session containing the store integration ID *Store_001*,
it only evaluates the campaigns linked to the particular store integration ID.

:::

## Evaluate reward usage

If a customer session includes the use of a [reward](/docs/product/rewards/overview.md), Talon.One [evaluates the reward](/docs/product/rewards/create-rewards.md#create-rules-and-set-points-required) before evaluating any campaign in the [campaign evaluation tree][tree].

## Evaluate cart item filters

To increase performance, the Rule Engine evaluates cart item filters only in the following
cases:

- A condition referencing a cart item filter is about to be evaluated or a valid effect referencing
  a cart item filter is going to be applied.

  :::note

  Only if the effect type is not [_discount_](/docs/product/rules/effects/available-effects.md#discount-effects)
  or [_update_](/docs/product/rules/effects/available-effects.md#update-effects).

  :::

  In this case, only the cart item filter referenced by the condition or effect is evaluated.

- A [_discount_](/docs/product/rules/effects/available-effects.md#discount-effects) effect
  or an [_update_](/docs/product/rules/effects/available-effects.md#update-effects) effect is
  about to be evaluated.

  In this case, the Rule Engine evaluates from top to bottom all cart item filters that haven't
  yet been evaluated.

## Evaluate rules

The campaign rules are evaluated by the Rule Engine from top to bottom as they appear in
the Rule Builder section.

:::important
Before evaluating the campaign rules, the Rule Engine collects any
[customer profile](/docs/product/applications/display-customer-profiles.md#customer-profile-overview)
data using the profile's integration ID, as that data may be required to evaluate the rules.
:::

All conditions of a rule are evaluated and all its effects are applied before evaluating
the next rule. If a condition is not met, the rule fails, and the next rule is evaluated.

If all the rules of a campaign fail, the next campaign in the
[campaign evaluation tree](/docs/product/applications/manage-campaign-evaluation.md) is evaluated.
[Archived campaigns][archive] are not included in rule evaluation.

### Evaluate conditions

The conditions of each rule are evaluated by the Rule Engine from top to bottom as they
appear in the rule.

All the conditions of the same rule are evaluated before the rule effects are evaluated.

:::note
- If a [failure effect](/docs/product/rules/conditions/use-conditions.md#add-a-failure-effect-to-a-condition)
was added to a condition or to a group of conditions, the effect is applied as soon as the
condition fails.

- A campaign is triggered after its conditions are met, even if it returns no
effects.
:::

### Evaluate effects

The Rule Engine evaluates whether the effects of each rule can be applied. It does it based
on the order in which the effects appear in the rule, from top to bottom.

Each valid effect is added to the [array of effects of the customer session response](/docs/dev/integration-api/api-effects.md#locate-the-returned-effects)
as the Rule Engines evaluates if it can be applied, so the Rule Engine takes the effect into
account when evaluating if the following effects can be applied. If one effect cannot be
applied, all the other effects in the same rule will also not be applied.

:::note
- Any existing [campaign budgets](/docs/product/campaigns/settings/manage-campaign-budgets.md)
are checked when evaluating if the effects that impact them can be applied.

- If a campaign's conditions are met but its
[budget limits](/docs/product/campaigns/settings/manage-campaign-budgets) have been
reached, the campaign does not trigger an effect and evaluation moves to the next
campaign.
:::

## Example

For this example, consider a campaign with three cart item filters and two rules. The first rule
has two conditions and one effect, and the second rule has one condition and two effects.

| Cart item filters                    | Rule  1                                    | Rule 2                                  |
| ------------------------------------ | ------------------------------------------ | --------------------------------------- |
| Filter 1Filter 2Filter 3 | Condition 1Condition 2Effect 1 | Condition 1Effect 1Effect 2 |

Also consider the following:

- Filter 2 is referenced by Condition 2 in Rule 1.
- Filter 3 is referenced by Effect 2 in Rule 2.
- Effect 1 in Rule 2 is a _discount_ effect. The other effects are _coupon_ effects.

The Rule Engine evaluates the cart item filters and conditions, and applies the effects,
in the following order:

- Rule 1
  1. Condition 1
  1. Filter 2
  1. Condition 2
     :::note
     Filter 2 is evaluated when the condition that references it is about to be evaluated.
     :::
  1. Effect 1
- Rule 2
  1. Condition 1
  1. Filter 1
  1. Filter 3
  1. Effect 1
     :::note
     Filter 1 and Filter 3 are evaluated when the Rule Engine is about to evaluate whether the _discount_
     effect can be applied.
     :::
  1. Effect 2

## Related pages

- [Manage campaign evaluation](/docs/product/applications/manage-campaign-evaluation.md)
- [Customer session overview](/docs/product/applications/display-customer-sessions.md#customer-session-overview)
- [Rule overview](/docs/product/rules/overview.md)
- [Manage campaign budgets](/docs/product/campaigns/settings/manage-campaign-budgets.md)

[catalogs]: /docs/product/account/dev-tools/manage-cart-item-catalogs.md
[strules]: /docs/product/rules/overview.md#strikethrough-rules
[tree]: /docs/product/applications/manage-campaign-evaluation.md
[stevents]: /docs/product/applications/application-notifications/overview.md#strikethrough-pricing-updates
[archive]: /docs/product/campaigns/create-and-manage-campaigns.md#archive-a-campaign
