# Build segments by events

**Event-based segmentation** allows you to target users based on their actual behavior and actions within your app or website. This creates highly personalized and effective campaigns by focusing on user engagement patterns.

## Build segments by events

To build a segment by events:

1. Hit **Event** in the **Add filter by** section.

![Interface showing the Add filter by section with Event option highlighted](/segmentation-segments-by-events-1.webp)

2. Select an event from the drop-down list.

![Drop-down list displaying available events for segment filtering](/segmentation-segments-by-events-2.webp)

3. Indicate conditions for the selected event: the number of times it happened and a time frame.

> When specifying a time frame for your segment, you can choose from two categories: **Relative dates** and **Specific dates**.

##### Relative dates

Use these options for dynamically updating time windows based on the current date:

|                     |                                                           |
|-----------------------------|-------------------------------------------------------------------------|
| **during the last N days**  | Includes events that occurred within the past N days                     |
| **exactly N days ago**      | Targets users who triggered the event exactly N days ago                  |
| **N or more days ago**      | Includes users who triggered the event at least N days ago                |
| **between N and M days ago**| Defines a range of days before today                                     |
| **between N and M days ahead**| Defines a range from N to M days from today, where 0 means today. Both N and M are included |


<img src="/segmentation-segments-21.webp" alt="Example of configuring segment filters by event occurrence and relative date criteria"/>

##### Specific dates

Use these options to define fixed calendar-based filters:

|                    |                                                                     |
|-------------------------------|-----------------------------------------------------------------------------------|
| **on a specific date**        | Includes users who triggered the event on a selected calendar date                |
| **on or after a specific date** | Includes users who triggered the event starting from the selected date onward      |
| **on or before a specific date**| Includes users who triggered the event up to and including the selected date       |
| **between dates**             | Includes users who triggered the event between two specific calendar dates        |

<img src="/segmentation-segments-20.webp" alt="Interface for segmenting users by event occurrence and specifying the event time frame criteria"/>

4. (Optional) Click **+ Attribute** to narrow the condition down to a specific event attribute. Select the attribute from the dropdown, choose an operator, and specify a value. Start typing to search suggested values based on previously recorded data.

<Aside type="tip">
For custom events, add attributes when you [create the event](/product/audience-data-and-segmentation/events/custom-events/#creating-custom-events). Attribute types are listed in [Understanding events](/product/audience-data-and-segmentation/events/#2-set-attributes). Default events already include their attributes. See [Default events](/product/audience-data-and-segmentation/events/default-events/).
</Aside>


<img src="/segmentation-segments-by-events-4.webp" alt="Event attribute condition showing attribute name, operator, and value with autocomplete suggestions"/>

See [event attribute operators by type](#event-attribute-operators-by-type) for the full list of available operators.

5. If you set several events as a segment condition, select an operator you'd like to use (AND/OR).

<video src="/segmentation-segments-5.webm" title="Setting segment filter by Events showing event selection and time frame conditions" autoplay loop muted playsinline />

6. Include all user devices

Enable this option to target a user across all their devices, not just the one that matched the segment condition. This ensures they receive your messages on every platform they use.

* **Enabled**: If any of the user's devices meet the condition (for example, purchase event, tag, behavior), all their devices across platforms are included in the segment.

* **Disabled**: Only the devices that meet the condition are included in the segment.

<img src="/segmentation-segments-16.webp" alt="Include all user devices option toggle for cross-platform targeting"/> 

## Event attribute operators by type

The available operators depend on the type of the event attribute you're filtering by. Select a type below to see its operators.

<Tabs>
<TabItem label="String">

| Operator    <div style="width:180px"></div> | Description    <div style="width:250px"></div> | Example |
| --- | --- | --- |
| **is** | Attribute value equals the specified value | `button_name is "checkout"` |
| **is not** | Attribute value does not equal the specified value | `url is not "/cart"` |
| **starts with** | Attribute value begins with the specified string | `url starts with "https://example.com"` |
| **ends with** | Attribute value ends with the specified string | `url ends with ".html"` |
| **contains** | Attribute value contains the specified string | `url contains "/products/"` |
| **in** | Attribute value matches any value in a provided list | `button_name in ["submit", "cancel"]` |
| **not in** | Attribute value does not match any value in a provided list | `category not in ["spam", "test"]` |
| **not set** | No value was recorded for the attribute | `coupon_code not set` |
| **any** | Attribute has any recorded value | `referrer any` |

</TabItem>
<TabItem label="Integer">

| Operator    <div style="width:180px"></div> | Description    <div style="width:250px"></div> | Example |
| --- | --- | --- |
| **is** | Attribute value equals the specified number | `level_number is 5` |
| **is not** | Attribute value does not equal the specified number | `score is not 0` |
| **greater or equals** | Attribute value is greater than or equal to the specified number | `points_earned greater or equals 100` |
| **less or equals** | Attribute value is less than or equal to the specified number | `attempts less or equals 3` |
| **between** | Attribute value is within the specified range (inclusive) | `level_number between 10 and 20` |
| **in** | Attribute value matches any value in the list | `level_number in [5, 10, 15]` |
| **not in** | Attribute value does not match any value in the list | `attempts not in [0, 1]` |
| **not set** | No value was recorded for the attribute | `score not set` |
| **any** | Attribute has any recorded value | `level_number any` |

</TabItem>
<TabItem label="Boolean">

| Operator    <div style="width:180px"></div> | Description    <div style="width:250px"></div> | Example |
| --- | --- | --- |
| **is true** | Attribute value is true | `enabled is true` |
| **is false** | Attribute value is false | `is_trial is false` |
| **not set** | No value was recorded for the attribute | `enabled not set` |
| **any** | Attribute has any recorded value (true or false) | `is_trial any` |

</TabItem>
<TabItem label="Decimal (price)">

Use this type for monetary values with decimals. In the Control Panel it appears as **decimal (price)** when you create or edit an event attribute.

| Operator    <div style="width:180px"></div> | Description    <div style="width:250px"></div> | Example |
| --- | --- | --- |
| **is** | Attribute value equals the specified price | `total_price is 9.99` |
| **is not** | Attribute value does not equal the specified price | `total_price is not 0` |
| **greater or equals** | Attribute value is greater than or equal to a price | `total_price greater or equals 50.00` |
| **less or equals** | Attribute value is less than or equal to a price | `total_price less or equals 100.00` |
| **between** | Attribute value falls within the specified price range (inclusive) | `total_price between 10.00 and 50.00` |
| **in** | Attribute value matches any value in a list | `total_price in [9.99, 14.99, 19.99]` |
| **not in** | Attribute value does not match any value in a list | `total_price not in [0, 5]` |
| **not set** | No value was recorded for the attribute | `total_price not set` |
| **any** | Attribute has any recorded value | `total_price any` |

</TabItem>
<TabItem label="List">

List-type attributes can hold multiple values at once, such as product IDs added to a cart.

| Operator    <div style="width:180px"></div> | Description    <div style="width:250px"></div> | Example |
| --- | --- | --- |
| **in** | Attribute contains at least one of the specified values | `product_ids in ["prod-123", "prod-456"]` |
| **not in** | Attribute does not contain any of the specified values | `product_ids not in ["prod-789"]` |
| **not set** | No value was recorded for the attribute | `product_ids not set` |
| **any** | Attribute has any recorded value | `product_ids any` |

</TabItem>
<TabItem label="Date">

Date-type attributes support the same [relative](#relative-dates) and [specific date](#specific-dates) comparisons used for the event's own time frame. 

</TabItem>
</Tabs>

## Event-based segmentation examples

Below are several practical scenarios illustrating how you can use event filters to create meaningful audience segments. 

##### Frequent purchasers

**Goal:** Target highly engaged users who have made multiple purchases recently.

**How to set up:**
- **Event:** `Purchase_made`
- **Condition:** exactly or more
- **Times:** `3`
- **Time frame:** during the last N days
- **Value:** `30`

**Use case:** Send special offers or loyalty rewards to users who demonstrate frequent buying activity.


##### High-value single purchase

**Goal:** Target users who made a large purchase, regardless of how often they buy.

**How to set up:**
- **Event:** `Purchase_made`
- **Condition:** exactly or more
- **Times:** `1`
- **Time frame:** during the last N days
- **Time frame value:** `30`
- **Attribute:** `total_price`
- **Operator:** greater or equals
- **Attribute value:** `50`

**Use case:** Invite big spenders to a loyalty or VIP program right after a qualifying purchase.

##### Viewed products but no purchase

**Goal:** Identify users who have shown interest but have not converted.

**How to set up:**
- **Event 1:** `Product_Viewed`
   - **Condition:** exactly or more
   - **Times:** `1`
   - **Time frame:** during the last N days
   - **Value:** `7`
- **Event 2:** `Purchase_made`
   - **Condition:** never
   - **Time frame:** during the last N days
   - **Value:** `7`
- **Operator:** AND

**Use case:** Send reminders, special offers, or personalized messages to users who browsed products but haven't made a purchase yet.

##### Users engaged during a campaign

**Goal:** Target users who participated during a specific promotional period.

**How to set up:**
- **Event:** `Promotion_Click`
- **Condition:** exactly or more
- **Times:** `1`
- **Time frame:** between dates
- **Value:** `"2024-01-01"` and `"2024-01-31"`

**Use case:** Follow up with users who interacted with a past campaign to promote a related offer or gather feedback.

##### High-value actions over time

**Goal:** Identify users who performed a valuable event a certain number of times within a custom date range.

**How to set up:**
- **Event:** `Subscription_Renewal`
- **Condition:** exactly or more
- **Times:** `2`
- **Time frame:** between dates
- **Value:** `"2024-01-01"` and `"2024-12-31"`

**Use case:** Offer special recognition or advanced features to loyal subscribers who regularly renew their subscriptions.

## Tips for event-based segmentation

- Use [relative dates](#relative-dates) for ongoing campaigns that should stay updated with current user activity.
- Narrow an event condition down with an [event attribute filter](#event-attribute-operators-by-type) (e.g., purchase amount, product category) instead of relying on event occurrence alone.
- Combine event filters with other criteria such as [tags](/product/audience-data-and-segmentation/segmentation/create-segments/by-tags/) (e.g., user demographics, subscription status) or [existing segments](/product/audience-data-and-segmentation/segmentation/create-segments/by-existing-segments/) for more precise targeting. For example, you can filter users based on both event occurrence and user properties stored in tags to tailor your messaging even further.
- Periodically review and update your segment filters to adapt to changing user behaviors or business goals.