# Transaction Item Filters

Transaction item filters are a powerful tool in Open Loyalty that allow you to **narrow down the list of products** included in a transaction before applying rules and effects. These filters work on the **line-item level** within a transaction - letting you isolate products based on attributes like category, price, quantity, brand, or custom values.

## How to Add a Transaction Item Filter

{% stepper %}
{% step %}
In the **Rules & Effects** step of campaign creation, click the **Transaction filters** tab.\
![](https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2F2u1LgvJz3d7oDyDKv6pY%2Fimage.png?alt=media\&token=38c91b41-77f0-4bf0-b33a-d28f8c03859a)
{% endstep %}

{% step %}
Select **Add first transaction filter**.\
![](https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FXW2s3OcnDwzIs412ef57%2Fimage.png?alt=media\&token=8b78c9b6-7270-4c7a-9af7-b151e1f650fa)
{% endstep %}

{% step %}
Choose the filter type — for example:

* Item category
* Item SKU
* Item name
* Item price
* Item custom attribute
* Item brand

<div align="left"><figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FdMWj2QbORWX7bUNDfEEV%2Fimage.png?alt=media&#x26;token=bfc1a391-7bf9-4340-bd93-ce335a67913f" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
Define your condition or multiple conditions.
{% endstep %}

{% step %}
Save the filter. It will be saved under a label like `Scenario 1` (you can rename it for clarity).
{% endstep %}
{% endstepper %}

***

## How to Use Transaction Filters in Campaign Rules

Once you have defined a transaction filter, you can reference it in both **Conditions** and **Effects**:

### **In Conditions**

You can use the filter to define conditions such as:

* **Quantity of filtered transaction**
* **Value of filtered transaction**

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FRBPD8es2tl8ejqN23asQ%2Fimage.png?alt=media&#x26;token=362f944b-a58d-4eca-a84e-5d2fa72a0dca" alt=""><figcaption></figcaption></figure>

For example, set a rule to apply only if:

> Quantity of filtered transaction in *Scenario 1* is greater than 3\
> Value of filtered transaction in *Scenario 1* is at least 100 PLN

This allows for precise rule targeting.

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FEU4nyKqsBjzG7kijLsMB%2Fimage.png?alt=media&#x26;token=c30baa93-c5db-4ce1-b86f-01c33c5077cc" alt=""><figcaption></figcaption></figure>

### **In Effects**

You can reference filtered items when defining custom effects using expressions like:

```javascript
agg(filter(transaction.items,'scenario_1')).sumBy('grossValue')
agg(filter(transaction.items,'scenario_1')).sumBy('qty')
```

These expressions:

* **Sum the gross value** or **quantity** of the items in the transaction that match the selected filter (`scenario_1`).
* Allow you to create advanced effects based on only a subset of items.

{% hint style="warning" %}
`scenario_1` is a dynamic identifier generated based on the filter name.&#x20;

Always ensure the name you reference in your expression matches the transaction filter’s label.
{% endhint %}

For example, set a rule to reward based on the following criteria:

> Give 1 point for every currency unit (e.g., for every dollar) spent.

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FPhRO7J50i0KW8Tabxpof%2Fimage.png?alt=media&#x26;token=77407962-2914-4fbb-ba6e-23099461baa1" alt=""><figcaption></figcaption></figure>

You can also limit how much value or quantity is counted from each matching transaction item using a **cap**.

```javascript
(filter(transaction.items,'scenario_1')).sumBy('grossValue', 1)
(filter(transaction.items,'scenario_1')).sumBy('qty', 1)
```

**Examples:**

* `agg(filter(transaction.items,'filter_name')).sumBy('grossValue', 100)`\
  → Sums up `grossValue` per item, but caps each one at 100
* `agg(filter(transaction.items,'filter_name')).sumBy('qty', 2)`\
  → Counts quantity but caps it at 2 units per item

Use this when you want to prevent unusually high item values or quantities from impacting campaign conditions disproportionately.

## Summary

Transaction item filters help you build smarter, more targeted campaigns by focusing only on specific products within a transaction. You can:

* Define them once and reuse them in multiple rule conditions or effects.
* Create precise campaign logic based on filtered item sets.
* Use them to ensure bonuses or effects only apply to relevant items.
