
You can use AI to offer customers a personalized shopping experience by suggesting relevant, complementary products that they might like. You can send those recommendations, based on cross-sell algorithms that select complementary products based on those recently bought, in your email marketing campaigns.

This use case describes how to prepare an automated workflow that sends an email with cross-sell recommendations. This use case uses an aggregate and AI cross-sell recommendations inserts in targeted customer communication. The workflow is triggered with `product.buy` event, and sends an email after a specific time period.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/Usecase-cross-sell.png" alt="Example of communication for recommending complementary products to recently bought"  class="full no-frame">
</figure> 

## Prerequisites 
---
- [Configure AI engine](/docs/settings/configuration/ai-engine-configuration/engine-configuration-for-recommendations).
- Implement transaction events using [SDK](/developers/web/transactions-sdk) or [API](https://developers.synerise.com/DataManagement/DataManagement.html#operation/CreateATransaction).
- [Create an email account](/docs/campaign/e-mail/configuring-email-account).

## Process 
---
In this use case, you will go through the following steps:

1. [Create an aggregate](#create-an-aggreagate).
2. [Prepare AI recommendations](#prepare-ai-recommendations).
3. [Prepare an email template](#prepare-an-email-template). 
4. [Create a workflow](#create-a-workflow).

## Create an aggreagate
---
In this step, create an aggregate that returns the SKU of the product a customer bought in the last 30 days. You will later use it as an insert in an email.

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**.
6. From the **Choose event** dropdown list, select the `product.buy` event.
7. From the **Choose parameter** dropdown list, select `$sku` parameter.
8. In the calendar in the right bottom of the page define the period from which the aggregate will return products from the event.
    1. In this case, in the **Relative date range** section, click **Custom**, type 30 and from the the dropdown list, select **Days**.
    2. Click **Apply**.
9. In the right upper corner, click **Save**.
10. Copy the aggregate ID from its URL to use in [Jinjava later](#prepare-an-email-template).

 <figure>
   <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/reco_comple.png" alt="The view of the configuration of the aggregate with last bought productst" class="full">
   <figcaption> Configuration of the aggregate with last bought products </figcaption>
   </figure>


   <div class="admonition admonition-tip"><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="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   Cross-sell recommendations which you will add to the email template have to have the context of the product based on which the items in the recommendations can be selected. It is provided by the SKU retrieved from the `product.buy` event in the aggregate.

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


## Prepare AI recommendations
---
In this part of the process, you will configure a cross-sell recommendation which will be later used in the email template.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/ai-hub-icon.svg" alt="AI Hub icon" class="icon" > **AI Hub > (AI Recommendations) Models > Add recommendation**.
2. Enter the name of the recommendation (it is only visible on the list of recommendation).
3. In the **Type & Items feed** section, click **Define**.
4. From the **Items feed** dropdown list, select an item feed.
5. In the **Type** section, choose the **Cross-sell** recommendation type.
6. Confirm the settings by clicking **Apply**.
7. In the **Items** section, click **Define**.
    1. Click **Add slot**.
    2. Define the minimum and maximum number of items that will be recommended to the user in each slot.
    3. Optionally, define [Static filters](/docs/ai-hub/recommendations-v2/creating-recommendation-campaign#static-filters) and [Elastic filters](/docs/ai-hub/recommendations-v2/creating-recommendation-campaign#elastic-filters).
    4. Confirm by clicking **Apply**. 
8. Optionally, you can define the **Boosting** factors and settings in the **Additional settings** sections.
9. In the right upper corner, click **Save**.
10. Copy the recommendation ID from its URL to use in [Jinjava later](#prepare-an-email-template).

## Prepare an email template
---
In this part of the process, you will create an email template with a Jinjava code that contains the IDs of the [aggregate](#create-an-aggreagate) and the [recommendation](#prepare-ai-recommendations) you created in the previous steps.  

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/experience-hub-icon.svg" alt="Experience Hub icon" class="icon" > **Experience Hub > Email > Templates**.
    1. To create a new template, click **Create new**.
    2. To create a template out of an existing template, click **From template**.
2. Select the template.
3. Select the wizard:
    1. **Drag&drop** builder - Create email templates with ready-made components.
    2. **Code editor** - Create email templates in CSS and HTML.
4. To add the dynamic part to the email template (last bought product and AI recommendations), you use Jinjava and add your own CSS. Below you can find an example Jijnava code. 


   <details class="accordion"><summary>Check the Jinjava code</summary><div class="accordion-content"><pre><code class="language-jinja">&lt;!-- Opening the tag that retrieves the value from the aggregate prepared in step 1--&gt; {% aggregate 6b009acf-d86a-3ac6-b299-cb3c5d64c04f %} &lt;!-- Assign an aggregate value to skuValue --&gt; {% set skuValue = aggregate_result[0] %} &lt;!-- Referencing with the help of variable to the snrs-product-ogTag directory built by default from OG tags. The variable names depend on the name of the OG tags on your page --&gt; &lt;div class="wrapper-card"&gt; &lt;h2 style="text-align:center"&gt;Product Card&lt;/h2&gt; &lt;div class="card"&gt; &lt;img src="{% catalog.Snrs-produktu-ogTag(skuValue).og:image %}" alt="Product image" style="width:100%"&gt; &lt;h1&gt;{% catalog.Snrs-produktu-ogTag(skuValue).product:brand %}&lt;/h1&gt; &lt;p class="price"&gt;$ {% catalog.Snrs-produktu-ogTag(skuValue).product:price:amount %}&lt;/p&gt; &lt;p&gt;{% catalog.Snrs-produktu-ogTag(skuValue).og:title %}&lt;/p&gt; &lt;p&gt;&lt;button&gt;Add to Cart&lt;/button&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- Adding the skuValue variable to the array for which we will retrieve cross-sell products --&gt; {% set itemContext = [] %} {% do itemContext.append(skuValue) %} &lt;!-- Downloading the cross-sell campaign for the product in the table --&gt; {% recommendations3 campaignId=tFwEUKvZLj4d itemsIds=itemContext %} &lt;!-- Iterating loop through the received products --&gt; {% for item in recommended_products3 %} &lt;!-- Listing the attributes assigned to the product in the feed --&gt; &lt;div class="wrapper-card" style="width:25%;float:left"&gt; &lt;h2 style="text-align:center"&gt;Product Card&lt;/h2&gt; &lt;div class="card"&gt; &lt;img src="{{ item.imageLink }}" alt="Product image" style="width:100%"&gt; &lt;h1&gt;{{ item.brand }}&lt;/h1&gt; &lt;p class="price"&gt;$ {{ item.priceValue }}&lt;/p&gt; &lt;p&gt;{{ item.title }}&lt;/p&gt; &lt;p&gt;&lt;button&gt;Add to Cart&lt;/button&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; {% endfor %} {% endrecommendations3 %} &lt;!-- Closing of the tag that gets the value from the aggregate prepared in point 1 --&gt; {% endaggregate %}</code></pre></div></details>



<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 will find more about email templates in [this article](/docs/campaign/e-mail/creating-email-templates).

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


## Create a workflow
---
To start sending emails with the recommendation to customers prepare a workflow, which in basic configuration may look like the one below.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/automation-hub-icon.svg" alt="Automation Hub icon" class="icon" > **Automation Hub > Workflows > New workflow**.  
2. Enter the name of the workflow.  
3. As the first node, add **Profile Event**. In the configuration of the node, select the event that triggers the workflow. In this use case, it’s a `product.buy` event.
4. As the second node, add **Delay**. In the configuration of the node, set the period according to your business needs.
5. As the next node, add the **Send Email** node.
6. In the **Send Email** node configuration:
    1. In the **Sender details**, define the account from which the email will be sent.
    2. In the **Content** section:
        3. Enter the subject of the email which will be visible in the customer’s inbox.
        4. Select the email template created in [the previous step](#prepare-an-email-template).
    5. Optionally, you can add UTM and URL parameters.
7. Confirm by clicking **Apply**.
8. Add the **End** node to finish the workflow.
9. Optionally, you can set up the capping for this workflow based on your business needs.
10. Click **Save & Run**.

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

## Check the use case set up on the Synerise Demo workspace
---
You can check the configuration of use case in Synerise Demo workspace:
- [Aggregate](https://app.synerise.com/analytics/aggregates/6b009acf-d86a-3ac6-b299-cb3c5d64c04f)
- [Email template](https://app.synerise.com/campaigns/email/content-manager/template/153786)
- [Recommendation](https://app.synerise.com/ai-v2/recommendations/tFwEUKvZLj4d)
- [Workflow](https://app.synerise.com/automations/workflows/automation-diagram/be21803b-2ad4-4c96-b1a2-d5d9cad0e644)

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)
- [Automation Hub](/docs/automation)
- [Jinjava inserts](/developers/inserts)
- [Recommendations](/docs/ai-hub/recommendations-v2)