
Delivering personalized and context-aware communication often requires combining behavioral insights with dynamically evaluated logic. 

[Brickworks](/docs/assets/brickworks) allows you to define a communication template that can dynamically assign the most relevant loyalty offer for each customer based on their browsing behavior.

In this use case, you will create a schema that enables an email template to return a specific loyalty offer based on an evaluated expression. This supports a next best offer (NBO) approach, where each customer receives the most relevant promotion determined by their behavior. The expression analyzes the price range of the products they viewed and assigns them to one of three predefined tiers. Based on the tier result, customers can automatically receive an email containing the loyalty offer that best matches their browsing behavior.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/template_email_telco.png" alt="Email message example"  class="full no-frame">
</figure> 

## Prerequisites 
---
- Implement a [tracking code](/developers/web/installation-and-configuration) into your website.
- Implement the [transaction events](/developers/web/transactions-sdk) using [SDK](/developers/web/transactions-sdk) or [API](https://developers.synerise.com/DataManagement/DataManagement.html#operation/CreateATransaction).
- Prepare a tier-based loyalty offer.

## Process
---

In this use case, you will go through the following steps:
1. [Create an aggregate](#create-an-aggregate) that will return last visited product price.
2. [Create segmentations](#create-segmentations) of customers qualifying for one of the three offer tiers.
3. [Create an expression](#create-an-expression) that returns information on tier which the customer qualifies for.
4. [Create a schema](#create-a-schema) with offer based on the expression result.
5. [Create records](#create-records).
6. [Create an email campaign](#create-an-email-campaign) based on the brickworks schema, using our predefined email template.

## Create an aggregate
---
In this step, create an aggregate that returns the price of the last visited product. The result of the aggregate will be used in segmentations determining tiers in the offer.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/behavioral-data-hub-icon.svg" alt="Behavioral Data Hub icon" class="icon"> **Behavioral Data Hub > Live Aggregates > Create aggregate**.
2. As the aggregate type, select **Profile**.  
2. Enter the name of the aggregate.
3. Click **Analyze profiles by** and select **Last**.
5. From the **Choose event** dropdown list, select the `page.visit` event.
6. As the event parameter, select **price**.
7. Click the **+ where** button. 
8. From the **Choose parameter** dropdown list, select **price** once again.
9. From the **Choose** dropdown list, select **String** and the **Is not empty** operator.
7. Set the period from which the aggregate will analyze the results, in our case **Last 30 days**. 
12. Save the aggregate.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/agg_telco_brcwrks.png" alt="The view of the aggregate configuration"  class="full">
<figcaption>Aggregate that returns the price of the last visited product configuration</figcaption>
</figure> 

## Create segmentations
---
Based on the [aggregate created in the previous step](#create-an-aggregate), create three segmentations of customers qualifying for one of the three next best offer tiers - Low Cost, Advantage, or All Inclusive.

### Low cost tier segmentation

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon" > **Decision Hub > Segmentations > New segmentation**. 
2. Enter the name of the segmentation.
1. Click **Add condition**.
2. Select the [aggregate created in the previous step](#create-an-aggregate).
3. From the **Choose** dropdown list, select **Number** and the **Less or equal to** operator.
4. In the text field, enter `300` as the upper limit of this tier.
5. Click **Save**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/lowcost_seg.png" alt="The view of the segmentation configuration"  class="full">
<figcaption>Segmentation that returns customers meeting the conditions of the low cost tier</figcaption>
</figure> 

### Advantage tier segmentation

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon" > **Decision Hub > Segmentations > New segmentation**. 
2. Enter the name of the segmentation.
1. Click **Add condition**.
2. Select the [aggregate created in the previous step](#create-an-aggregate).
3. From the **Choose** dropdown list, select **Number** and the **Less than** operator.
4. In the text field, enter `700` as the upper limit of this tier.
5. Click **Add condition**.
2. Select the [aggregate created in the previous step](#create-an-aggregate).
3. From the **Choose** dropdown list, select **Number** and the **More than** operator.
4. In the text field, enter `300` as the lower limit of this tier.
5. Click **Save**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/advantage_seg.png" alt="The view of the segmentation configuration"  class="full">
<figcaption>Segmentation that returns customers meeting the conditions of the advantage tier</figcaption>
</figure> 

### All inclusive tier segmentation

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon" > **Decision Hub > Segmentations > New segmentation**. 
2. Enter the name of the segmentation.
1. Click **Add condition**.
2. Select the [aggregate created in the previous step](#create-an-aggregate).
3. From the **Choose** dropdown list, select **Number** and the **More or equal to** operator.
4. In the text field, enter `700` as the upper limit of this tier.
5. Click **Save**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/allinclusive_seg.png" alt="The view of the segmentation configuration"  class="full">
<figcaption>Segmentation that returns customers meeting the conditions of the all inclusive tier</figcaption>
</figure> 

## Create an expression
---
In this step, create an attribute expression that evaluates the customer's last visited product price and assigns it to the appropriate offer segment. The expression checks whether the profile meets the criteria for the Low Cost, Advantage, or All Inclusive NBO segmentation categories and returns the corresponding offer label. This expression will be later used in the schema.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/behavioral-data-hub-icon.svg" alt="Behavioral Data Hub icon" class="icon"> **Behavioral Data Hub > Expressions > New expression**.  
2. Enter the name of the expression.  
3. Set the **Expression for** option to **Atribute**. 
4. Click **Select** and from the **Function** dropdown list, choose **To string**.
5. Click **Select** in the brackets, and from the **Function** dropdown list, choose **If**.
6. Click the first **Select** in the brackets, and pick **Profile**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and click **Choose attribute**.
    4. From the dropdown list, select the [low cost tier segmentation you created earlier](#low-cost-tier-segmentation).
7. Click the second **Select** in the brackets, and pick **Constant**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and type `Low Cost Offer` in the field.
8. Click the third **Select** in the brackets, and from the **Function** dropdown list, choose **If**.
9. Click the first **Select** in the brackets, and pick **Profile**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and click **Choose attribute**.
    4. From the dropdown list, select the [advantage tier segmentation you created earlier](#advantage-tier-segmentation).
10. Click the second **Select** in the brackets, and pick **Constant**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and type `Advantage` in the field.
11. Click the third **Select** in the brackets, and from the **Function** dropdown list, choose **If**.
12. Click the first **Select** in the brackets, and pick **Profile**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and click **Choose attribute**.
    4. From the dropdown list, select the [all inclusive tier segmentation you created earlier](#all-inclusive-tier-segmentation).
13. Click the second **Select** in the brackets, and pick **Constant**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and type `All inclusive` in the field.
14. Click the thirds **Select** in the brackets, and pick **Constant**.
    1. Click the **0** node that appeared on the canvas.
    3. Scroll down the page and type `null` in the field.
15. Click **Save**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/exp_telco_brcwrks.png" alt="The view of the expression configuration"  class="full">
<figcaption> Expression that returns information on tier which the customer qualifies for.</figcaption>
</figure> 

## Create a schema
---
In this section, you will configure a [Brickworks schema](/docs/assets/brickworks/quick-start/creating-a-schema) with fields for offer information.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/data-modeling-hub-icon.svg" alt="Data Modeling Hub icon" class="icon"> **Data Modeling Hub > Schemas > New schema**.  
2. Choose **Simple Schema**.
3. In **Display name**, enter a name for the schema, for example **Telco offers**. **API names** value is pre-filled with the value from **Display name**. The value in this field is the unique identifier used to reference this schema in API requests.
4. Optionally, add the **Description**.

### Add the Offer title

1. Click **Add new field** and choose **String**.
3. Complete the fileds:
    - Add the **Display name** for the field in our case `Offer title`. 
    - The **API name** will be pre-filled automatically. 
    - **Description** is optional, in our case `Presents offer title to be displayed for customer`.
4. In **Settings**, select **Use as record title**.
5. Click **Apply** to save your changes.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/offer_brcwrks.png" alt="The view of the brickworks configuration"  class="full">
<figcaption>Schema configuration</figcaption>
</figure> 

### Add the Offer image

1. Click **Add new field** and choose **Image**.
3. Complete the fileds:
    - Add the **Display name** for the field in our case `Offer image`. 
    - The **API name** will be pre-filled automatically. 
    - **Description** is optional, in our case `image of the offer`.
5. To save your changes, Click **Apply**.

### Add other descriptive fields

1. Click **Add new field** and choose **String**.
3. Complete the fileds:
    - Add the **Display name** for the field. 
    - The **API name** will be pre-filled automatically. 
    - **Description** is optional.
5. To save your changes, click **Apply**.

In this use case, we add the following **String** fields:
- `Offer short description` - describes the purpose of the offer,
- `Package conditions` - minutes, internet packages description,
- `Promotion for new subscribers` - new subscribers only - promotion information.

### Add the Price

1. Click **Add new field** and choose **Number**.
2. Choose **Float** to let users type real numbers, also numbers which contain fractional or decimal parts.
3. Complete the fileds:
    - Add the **Display name** for the field in our case `Price`. 
    - The **API name** will be pre-filled automatically.
    - **Description** is optional, in our case `monthly price for offer in Euro`.
5. To save your changes, click **Apply**.

### Add the Number of months

1. Click **Add new field** and choose **Number**
2. Choose **Integer** to let users type in a whole number that can be positive, negative, or zero, but does not include any fractional or decimal part.
3. Complete the fileds:
    - Add the **Display name** for the field in our case `number of months`. the **API name** will be pre-filled automatically. **Description** is optional, in our case `Number of contracted months. -1 equals that the offer has no contract engagement`.
4. In **Settings**, check **Dafault value** and type `-1`
5. To save your changes, click **Apply**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/months_brcwrks.png" alt="The view of the brickworks configuration"  class="full">
<figcaption>Brickworks configuration</figcaption>
</figure> 

### Add the Expression

5. Click **Add new field** and choose **Expression**.
3. Complete the fileds:
    - Add the **Display name** for the field in our case `qualified offer`. 
    - The **API name** will be pre-filled automatically. 
    - **Description** is optional, in our case `informs about offer which qualifies for client`.
4. Choose the [expression created in the previous part of the process](#create-an-expression) from the list.
5. To save your changes, click **Apply**.

### Add the Jinjava code

5. Click **Add new field** and choose **Jinjava code**
3. Complete the fileds:
    - Add the **Display name** for the field in our case `display offer`. 
    - The **API name** will be pre-filled automatically. 
    - **Description** is optional, in our case `informs if offer should be displayed`.
4. Use jinjava code:

   <pre><code class="language-jinjava">{% if record.offerTitle == record.qualifiedOffer %}true{% else %}false{% endif %}</code></pre>
  
5. To save your changes, click **Apply**.

### Set up the Audience & Settings

1. Click the **Audience & Settings** tab.
2. In the **Audience** section, click **Define**.
3. Choose the schema recipients according to your needs, in our case choose **Everyone**.
4. Click **Apply**.
5. In the upper-right corner, click **Save**

## Create records
---
[Creating a record](/docs/assets/brickworks/quick-start/creating-a-record) means adding the data to the schema. It means that you fill out schema fields. In this case, these are examples of telecommunications offers - one of the three next best offer tiers - Low Cost, Advantage, or All Inclusive.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/data-modeling-hub-icon.svg" alt="Data Modeling Hub icon" class="icon"> **Data Modeling Hub > Data collections > Select schema**.  
2. Choose [schema created in the previous step](#create-a-schema).
3. In the upper-right corner, click **New record**. We will create three records in total, for each of the tiers.
4. Add a name for the record.
5. Add a slug for the record. Slug is a unique, URL-friendly version of the name. It usually contains only lowercase letters, numbers, and hyphens.
6. Add **Offer title**.
7. Add coresponding **Offer image**, **Offer short description**, **Package conditions**, **Price**, **Number of months**, **Promotion for new subscribers**.
8. Everything in **Qualified offer** section shouold be pre-filled with data provided in the schema.
9. In the upper-right corner, click **Publish** to publish your record.
10. Repeat steps **3-9** for two remaining tiers.

### Previewing records

After saving the record either as a draft (in case of records created based on versioned schemas) or publishing it (in case of both schema types), you can [preview the record for the context of a selected user](/docs/assets/brickworks/quick-start/creating-a-record#previewing-records). This context-driven approach enables your records to adapt dynamically based on the requesting application, user session, or any external factors you define.

1. In <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/data-modeling-hub-icon.svg" alt="Data Modeling Hub icon" class="icon"> **Data Modeling Hub > Data collections**.
2. In the header, from **Select schema** dropdown list, select the [schema created in the previous step](#create-a-schema).
3. Find the record which you want to preview.
4. Enter the record configuration.
5. Click **Preview**.
6. Click **Preview contexts**.
7. From the dropdown list, find a profile for which you want to generate record preview. This means the same record can render completely differently depending on the context you provide.

    <figure>
    <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/record_brcwrks.png" alt="The view of the record results for an example profile"  class="full">
    <figcaption>Record results for an example profile</figcaption>
    </figure> 

8. You can also see the preview as JSON.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/record_json_brcwrks.png" alt="The view of the JSON record results for an example profile"  class="full">
<figcaption>JSON record results for an example profile</figcaption>
</figure> 

## Create an email campaign
---
In this part of the process, you [create an email campaign](/docs/campaign/e-mail/creating-email-campaigns). We will use a predefined template, so there is no need to create a template from scratch.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/experience-hub-icon.svg" alt="Image presents the Experience Hub icon" class="icon">  **Experience Hub > Email campaign > Create new**.
2. Enter the name of the email campaign.
3. In the **Audience** section, define the recipents of your campaign according to your business needs.

### Define content
---
In this part of the process, you will create the content of the email message that returns information on tier which the customer qualifies for, with the help of ready-made template.

1. Click **Define** in the **Content** section.
2. From the dropdown in the **From email address** section, select the email account from which the email will be sent.  
2. In **Subject**, provide the subject of the email.
3. Click **Create message** and from the list of template folders, select **Predefined templates**.
3. Select the **Brickworks: Telco offer** template.

**Result:** You are redirected to the code editor.

<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

You can edit the template in two ways, by editing the code of the template [add snippets](/docs/campaign/e-mail/creating-email-templates/email-code-editor#adding-a-snippet-to-the-template-code), [add variables](/docs/campaign/e-mail/creating-email-templates/email-code-editor#adding-a-variable) and/or by filling out the form in the Config tab. In this use case, we will use the capabilities of the predefined Config tab.

</div></div></div>


#### Edit form in the Config tab 
---
The form in the **Config** tab is already filled in with default values. You can keep them or change them to fit your business needs.

<figure>
    <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/telco_config_brcwrks.png" alt="The view of the email template configuration"  class="full">
    <figcaption>Email template  configuration</figcaption>
    </figure> 


1. To the **Schema ID** field, add the ID of the [schema created in the previous part of the process](#create-a-schema). 
2. To the following fields, add the ID of the [records created in the previous part of the process](#create-records). You can find the ID of the record in the record URL:
    - **Record ID - Low cost offer**, 
    - **Record ID - All inclusive**, 
    - **Record ID - Advantage** fields**, 
3. Optionally, you can edit the copy and design of the template.
10. After you make changes to the template, you can check the preview.
    1. Click the **Preview** button on the upper left side.
    2. Enter the ID of a customer.
    3. Click **Apply**.
11. If the template is ready, in the upper right corner click **Save as...**.
12. On the pop-up:
    1. In the **Template name** field, enter the name of the template.
    2. From the **Template directory** dropdown list, select the folder where the template will be saved.
    3. Confirm by clicking **Save**.
13. To continue the process of configuring the email campaign, click **Next**.
14. To save your content changes, click **Apply**.

### Prepare the final settings  
 
1. In the **Schedule tab**, decide when your email is sent.
3. Optionally:
    1. In the **UTM & URL parameters** section, add the parameters to track the email performance.
    2. In the **Additional parameters** section, add the custom event parameters with constant values to the automatically generated events in the email channel.
    3. In the **Test** section, you can send a test email of your message to verify if the content of the email is displayed correctly.
3. If everything is ready, click **Send**.

## What's next
---

After defining this schema, you can reuse the template across other placements as needed. It can be applied  in emails, in-apps, or any additional surfaces supported by your setup.

## Check the use case set up on the Synerise Demo workspace
---
In Synerise Demo workspace, you can check the configuration of:  
- [Aggregate](https://app.synerise.com/analytics-v2/aggregates/861fd984-a278-3ff9-aefa-58db40fc21c2)
- [Low cost tier segment](https://app.synerise.com/analytics-v2/segmentations/f71be786-8147-4dd3-8099-76434865e284)
- [Advantage tier segment](https://app.synerise.com/analytics-v2/segmentations/680bb059-2ce0-4990-b380-39b1bdc932e6)
- [All inclusive tier segment](https://app.synerise.com/analytics-v2/segmentations/e377294f-8e6a-42c7-9851-f0eff8a794d8)
- [Expression](https://app.synerise.com/analytics/expressions/f7afae27-ad5a-4faf-afe0-ec32f7a89dcd)
- [Brickwork schema](https://app.synerise.com/assets/brickworks/schemas/37ef59a6-710d-494f-b8c6-f67fd873a77d)
- [Email campaign](https://app.synerise.com/campaigns/email/create/de4862a7-5e5b-4398-acbe-d907bf5ae477)

If you’re our partner or client, you already have automatic access to the **Synerise Demo workspace (1590)**, where you can explore all the configured elements of this use case and copy them to your workspace.  

If you’re not a partner or client yet, we encourage you to fill out the contact [form](https://demo.synerise.com/request) to schedule a meeting with our representatives. They’ll be happy to show you how our demo works and discuss how you can apply this use case in your business. 

## Read more
---
- [Aggregates](/docs/analytics/aggregates)
- [Brickworks](/docs/assets/brickworks)
- [Email campaigns](/docs/campaign/e-mail)
- [Expressions](/docs/analytics/expressions)
- [Segmentation](/docs/analytics/segmentations)


