# Because You Purchased

> Source: https://docs.recombee.com/recipes/e-commerce/fully-personalized-homepage/because-you-purchased

> For the complete documentation index, see [llms.txt](/llms.txt).

# Because You Purchased

## Introduction

The **Because You Purchased** scenario ensures your users receive recommendations based on their past purchases. By analyzing their purchasing history, we present a carefully curated list of complementary products to what your users bought before.

With [Composite Recommendations](/scenarios/composite-recommendations), you can return both:

1. The **source item** (the product the user recently purchased), and
2. The **recommended items** (accessories or related items)

— all in a single API response.

## Composite Recommendations Overview

**Composite Recommendations** combine multiple recommendation steps into one response.  
They are requested via the [**Composite Recommendation API endpoint**](/api/recommendations#composite-recommendation).

In this use case:

* **Source:** The product the user purchased (an _Item_)
* **Result:** Products that complement what the user has bought

[![Because You Purchased Composite Recommendation Example](/img/gui/composite_because_you_purchased.png)](/img/gui/composite_because_you_purchased.png)

This setup ensures contextual recommendations that feel natural and personalized — “because you purchased _X_, you might also like _Y_.”

---

## Scenario Setup

In the Recombee Admin UI, navigate to the **[Scenarios](/scenarios)** section and choose **Create Scenario**.

1. Enter a **Scenario ID**. Select a distinctive label for your recommendation scenario, such as `because-you-purchased`.
2. Set the **Recommendation Type** to **Composite** (see [Composite Recommendations](/scenarios/composite-recommendations)).
3. Select the **Template:** [ecommerce:because-you-purchased](/logics/e-commerce#ecommerce-because-you-purchased).

## Logic

Within the [ecommerce:because-you-purchased](/logics/e-commerce#ecommerce-because-you-purchased) Logic, you can customize how the purchased asset is selected in the **Source** section using:

* `maxDaysAgo` – to specify the maximum number of days since the user purchased the item for it to be considered for the "Because" selection.

## Filters

You always want to recommend only the products that are in stock. Therefore you need to apply a [**Filter**](/scenarios/settings-in-admin-ui#filters) rule to allow only such products.

As it would be tedious and prone to error to add this rule to all the Scenarios, this rule shall be added to the [**Global Settings**](/scenarios/settings-in-admin-ui#global-settings), so it is always applied everywhere.

You can select a **predefined rule from the Recombee Library** to allow only the available products.

Depending on how you represent availability in the catalog, it can be **one of the following rules:**

* **Not deleted items** \- when you have a _deleted_ property (true/false)
* **Available items** \- when you have an _available_ property (true/false)
* **Items in stock \[Google Merchant\]** \- when you have a string _available_ property with _"in stock"_ as its value

## Requesting Recommendations

There are two ways to show multiple personalized rows in your application:

1. **Using the API Client**

Using an [API Client of your choice](/api_clients), you can retrieve _Because You Purchased_ recommendations via the **[Composite Recommendation API endpoint](/api/recommendations#composite-recommendation)**.

For more information navigate to the Integration tab of the Scenario in the Admin UI.

In order to request content for multiple rows with a single API request, use the [Batch endpoint](/api/miscellaneous#batch) and put recommendation requests for all rows inside it. Set the parameter `distinctRecomms` in order to [deduplicate the assets among the rows](/api/miscellaneous#batch-example-using-distinctrecomms-parameter-to-deduplicate-results-in-multiple-boxes).

Users without purchases

If a user has not purchased anything in the time range given by the `maxDaysAgo` Logic parameter, the recommendation request returns `null` as the source and an empty list of recommendations.

In this case, the _Because You Purchased_ section should not be displayed.

1. **Using the Widget SDK**

For web applications built with HTML, CSS and JavaScript, the [Widget SDKs](/widget-sdks) support Composite Recommendations out of the box.

Place a widget on your page, with `createRequest` returning a **[Composite Recommendation request](/api/recommendations#composite-recommendation)**. Design the row title with the `SourceItemComponent` parameter and the products inside it with `ItemComponent`.

In order to request content for multiple rows, simply place multiple widgets on the page. These will get deduplicated automatically, for the recommended items as well as for the _source items_ (the purchased products).

For full code examples and in-depth guidance, see the relevant SDK documentation on Composite Recommendations:

* [Carousel Widget (JS)](/widget-sdks/carousel-widget-js#composite-recommendations)
* [Carousel Widget (React)](/widget-sdks/carousel-widget-react#composite-recommendations)
* [Grid Widget (JS)](/widget-sdks/grid-widget-js#composite-recommendations)
* [Grid Widget (React)](/widget-sdks/grid-widget-react#composite-recommendations)
* [Feed Widget (JS)](/widget-sdks/feed-widget-js#composite-recommendations)
* [Feed Widget (React)](/widget-sdks/feed-widget-react#composite-recommendations)