
Thanks to the parameters in the URL, we can track the behavior of customers after interacting with a given campaign. In this use case, we will show an example of analyses related to AI recommendations, but in general, the same principles can be applied to create an analysis for any campaign where these parameters in the URL are placed.

It helps us check the effectiveness of recommendations and monitor the purchases (exact number of products bought after clicking and their total value). This use case describes the process of creating aggregates, metrics and other analyses that count purchases based on the URL parameter with the ID of the AI recommendation.

## Prerequisites 
---
- A [tracking code](/developers/web/installation-and-configuration#creating-a-tracking-code) implemented in the source of your website.
- Send information about transactions through [API](https://developers.synerise.com/DataManagement/DataManagement.html#operation/CreateATransaction) or [SDK](/developers/web/transactions-sdk).
- Implement [OG Tags](/developers/web/og-tags) on your website.
- Implement [AI recommendation](/docs/ai-hub/recommendations-v2) on your website or, in case you want to analyze different type of campaign, add unique parameters to the URL after clicking it, which will allow you to analyze the campaign results.  


## Process
---
This use case contains the following steps which must be performed in the given order:
1. [Getting the list of clicked products](/use-cases/items-bought-after-clicking#getting-the-list-of-clicked-products). 
2. [Getting the timestamp of the first visit to the product page](/use-cases/items-bought-after-clicking#getting-the-timestamp-of-the-first-visit).
3. [Getting the list of the order IDs after clicking the recommendation](/use-cases/items-bought-after-clicking#getting-the-list-of-the-order-ids-after-clicking-the-recommendation).
4. [Multiply the product price by the product quantity](/use-cases/items-bought-after-clicking#multiply-the-product-price-by-the-product-quantity).
5. [Create metrics that calculate](/use-cases/items-bought-after-clicking#create-metrics):
    - The number of products bought after clickng the recommendation
    - The value of products bought after clicking the recommendation
    - The number of transactions with the products bought after clicking the recommendation
    - The value of transactions with the products bought after clicking the recommendation

## Getting the list of clicked products
---
Create an aggregate that returns the SKUs of the clicked items (from a particular recommendation campaign). You will use these SKUs later to check if they occured in the transactions that occurred after clicking at a certain time.

In this use case, we analyze clicking a product from a given AI recommendation based on the `page.visit` event and `uri` parameter (URL of the website). This parameter contains `?snrai_campaign=XXX` part, where `XXX` is the ID of AI recommendation that was clicked. The `?snrai_campaign` parameter it is added to the URL automatically when implementing AI recommendation.  

The analysis is also based on the ID of the clicked product which is stored in the `retailer_part_no` parameter. However, sometimes clicking a product does not transfer directly to the product page, so it is not possible to add parameters to the URL, especially in the case of "Add to cart" buttons placed directly in the product frame.  In such case instead of relying on the `page.visit` event, you should implement a [custom event](/developers/web/event-tracking#declarative-tracking-custom-events). Such an event must contain the AI recommendation ID and the product ID that was clicked in its parameters. Then you will be able to rely your analyses on this custom event. 

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. Click **Analyze profiles by** and select **Last Multi**.  
3. Select **Consider only distinct occurrences of the event parameter**.
3. In the **Size** field, enter the number of returned SKUs.
4. Select the **page.visit** event.
5. Select the **product:retailer_part_no** parameter.
6. Select the **url** parameter.
7. Select the **Contain** logical operator.
8. In the text field, enter the ID of the recommendation campaign.  
    
   <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">

   You can find it in the URL of the product from the recommendation: <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/analytics/_gfx/recommendation-campaign-id.png" alt="Filled settings of the aggregate" class="full" ><figcaption>ID of recommendation campaign in URL</figcaption></figure>

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

9. Save the aggregate.


<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/last-visited-reco.png" alt="Last visited recommendation aggregate"  class="full no-frame">
<figcaption>Last visited recommendation aggregate </figcaption>
</figure>

## Getting the timestamp of the first visit
---
You must get the time of the first click at the product from recommendation campaign. To do so, we use the `TIMESTAMP` parameter and the ID of the recommendation campaign which is visible in the clicked link. Timestamp allows you to define the period from which transactions should be taken into account, and also those transactions which occurred after clicking the campaign.


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. Click **Analyze profiles by** and select **First**.
4. Select the **page.visit** event.
5. Select the **TIMESTAMP** parameter.
6. Select the **url address** parameter.
7. Select the **Contain** logical operator.
8. In the text field, enter the ID of the recommendation campaign.
9. Save the aggregate.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/analytics/_gfx/time-of-reco-visit.png" alt="Configuration of the aggregate" class="full" >
<figcaption>Time of the first visit to the product of the recommendation campaign </figcaption>
</figure>

## Getting the list of the order IDs after clicking the recommendation
---
Create an aggregate that returns the order IDs of the products included in the [first aggregate you prepared](/use-cases/items-bought-after-clicking#getting-the-list-of-clicked-products). It allows you to identify the transactions that included the products clicked from the specific campaign and those transactions which took place just after the click.

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. Click **Analyze profiles by** and select **Last Multi**.
3. Select **Consider only distinct occurrences of the event parameter**.
4. Select the **product.buy** event.
5. Select the **$orderID** parameter.
6. Select the **$sku** parameter.
7. Select the **IN ARRAY** logical operator.
8. Select the aggregate you created in the [Getting the list of visited products](/use-cases/items-bought-after-clicking#getting-the-list-of-clicked-products) step.
9. Save the aggregate.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/aggregate-last-visited-reco.png" alt="Configuration of the aggregate" class="full" >
<figcaption>The list of products clicked in the recommendation </figcaption>
</figure>  

## Multiply the product price by the product quantity
---
Create [an event expression](/docs/analytics/expressions/creating-event-expression) that multiplies the final price of the product and its quantity. At the same time you enrich the parameters of the `product.buy` event.

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 expressions**.
2. From the **Expression for** list, select **Events**.
3. Select the **product.buy** event.
4. On the dashboard, click the **Select** button and select **Event attribute**.
5. On the list, find **$finalUnitprice** or other parameter that signifies the actual transaction value.
6. Click the plus button and select **Event attribute**.
7. On the list, find **$quantity** or other parameter that signifies the quantity of the product. 
8. Change the mathematical sign between the attributes from the plus sign to times sign (`x`).
9. Save the expression.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/expression-price-quantity.png" alt="Configuration of the expression" class="full" >
<figcaption> Configuration of the expression </figcaption>
</figure>

## Create metrics
---
Prepare metrics based on the three aggregates you created in previous steps. Including the aggregates in metrics lets you calculate:
- the number of products purchased after clicking in the campaign,
- the total value of products purchased after clicking in the campaign, 
- the number of transactions that include the products bought after clicking the campaign,
- the total value of transactions that include the products bought after clicking the campaign.


  <details class="accordion"><summary>Click to see the metric for the number of products bought after clicking the campaign</summary><div class="accordion-content"><p>In this metric, you check the number of products by using in the metric formula the aggregate that returns the SKU of the products viewed within a campaign. </p> <p>Additionally, narrow down the results by using the timestamp parameter. Set the time stamp to include the purchases after the first click at the product in the campaign. For that purpose, use the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-timestamp-of-the-first-visit">calculates the timestamp of the first product visit</a>.</p> <ol> <li>Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon"> <strong>Decision Hub &gt; Metrics &gt; New metric</strong>.</li> <li>Enter the name of the metric.</li> <li>Leave the <strong>Aggregator</strong> at default (<strong>Count</strong>).</li> <li>Select the <strong>product.buy</strong> event.</li> <li>Add the following parameters:<ol> <li>Add the <strong>$sku</strong> parameter.<ol> <li>Select the <strong>In</strong> operator.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon">.</li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-list-of-clicked-products">returns the list of visited products</a>.</li> </ol> </li> <li>Add the <strong>TIMESTAMP</strong> parameter (available in the <strong>Specials</strong> tab).<ol> <li>Select the <strong>Date</strong> operator.</li> <li>Select the <strong>More than</strong> option.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon"></li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-timestamp-of-the-first-visit">returns the timestamp of the first product visit</a>.</li> </ol> </li> </ol> </li> <li>Select the date range of the metric (for example, last 30 days).</li> <li>Save the metric by clicking <strong>Save</strong>.</li> </ol> <figure> <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/metric-nr-one-use-case.png" alt="Configuration of the metric" class="full" > <figcaption> Configuration of the metric </figcaption> </figure></div></details>



<details class="accordion"><summary>Click to see the metric for the sum of products bought after clicking a campaign</summary><div class="accordion-content"><p>This metric returns the total sum of products bought after clicking a campaign. The metric uses the expression that multiplies the product price by the product quantity.</p> <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"> <p>You can duplicate the metric that calculates the number of products bought after clicking a product, change the aggregator from <strong>Count</strong> to <strong>Sum</strong> and use the expression that multiplies the price by the quantity.</p> </div></div></div> <ol> <li>Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon"> <strong>Decision Hub &gt; Metrics &gt; New metric</strong>.</li> <li>Enter the name of the metric.</li> <li>As the aggregator type, select <strong>Sum</strong>.</li> <li>Select the <strong>product.buy</strong> event.</li> <li>Add the following parameters:<ol> <li>The expression that multiplies the product price by product quantity.<ol> <li>Select the <strong>$sku</strong> parameter.</li> <li>Select the <strong>In</strong> operator.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon">.</li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-list-of-clicked-products">returns the list of visited products</a>.</li> </ol> </li> <li>Add the <strong>TIMESTAMP</strong> parameter (available in the <strong>Specials</strong> tab).<ol> <li>Select the <strong>Date</strong> operator.</li> <li>Select the <strong>More than</strong> option.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon"></li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-timestamp-of-the-first-visit">returns the timestamp of the first product visit</a>.</li> </ol> </li> </ol> </li> <li>Select the date range of the metric (for example, last 30 days).</li> <li>Save the metric by clicking <strong>Save</strong>.</li> </ol> <figure> <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/metric-nr-two-use-case.png" alt="Configuration of the metric" class="full" > <figcaption> Configuration of the metric </figcaption> </figure></div></details>



<details class="accordion"><summary>Click to see the metric for the number of transactions with the products bought after clicking a campaign</summary><div class="accordion-content"><p>This metric is based on the <code>transaction.charge</code> event (this event collects an array of products included in the transaction). The metric reuses the aggregate that returns the list of products bought after clicking the campaign to check if the order ID of the product is included in the transaction. The scope of the metric is narrowed down by the aggregate that returns the timestamp of the first visit at the product page. </p> <ol> <li>Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon"> <strong>Decision Hub &gt; Metrics &gt; New metric</strong>.</li> <li>Enter the name of the metric.</li> <li>Leave the <strong>Aggregator</strong> to default (<strong>Count</strong>).</li> <li>Select the <strong>transaction.charge</strong> event.</li> <li>Add the following parameters:<ol> <li>Add the <strong>$orderID</strong> parameter.<ol> <li>Select the <strong>In</strong> operator.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon"></li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-list-of-the-order-ids-after-clicking-the-recommendation">returns the list of the order IDs after clicking the recommendation</a>.</li> </ol> </li> <li>Add the <strong>TIMESTAMP</strong> parameter (available in the <strong>Specials</strong> tab).<ol> <li>Select the <strong>Date</strong> operator.</li> <li>Select the <strong>More than</strong> option.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon"></li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-timestamp-of-the-first-visit">returns the timestamp of the first product visit</a>.</li> </ol> </li> </ol> </li> <li>Select the date range of the metric (for example, last 30 days).</li> <li>Save the metric by clicking <strong>Save</strong>.</li> </ol> <figure> <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/metric-nr-three-use-case.png" alt="Configuration of the metric" class="full" > <figcaption> Configuration of the metric </figcaption> </figure></div></details>



<details class="accordion"><summary>Click to see the metric for the sum of transactions with the products bought after clicking a campaign</summary><div class="accordion-content"><p>This metric is based on the <code>transaction.charge</code> event (this event collects an array of products included in the transaction). The metric reuses the aggregate that returns the list of products bought after clicking the campaign to check if the order ID of the product is included in the transaction. The scope of the metric is narrowed down by the aggregate that returns the timestamp of the first visit at the product page. </p> <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"> <p>If you have already created a metric for the number of transactions with the products bought after clicking a campaign, you can duplicate it and change the aggregator type and use the <code>totalAmount</code> parameter.</p> </div></div></div> <ol> <li>Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/decision-hub-icon.svg" alt="Decision Hub icon" class="icon"> <strong>Decision Hub &gt; Metrics &gt; New metric</strong>.</li> <li>Enter the name of the metric.</li> <li>As the <strong>Aggregator</strong> type, select <strong>Sum</strong>.</li> <li>Select the <strong>transaction.charge</strong> event.</li> <li>Add the following parameters:<ol> <li>Add the <strong>$totalAmount</strong> parameter.<ol> <li>Select the <strong>In</strong> operator.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon"></li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-list-of-the-order-ids-after-clicking-the-recommendation">returns the list of the order IDs after clicking the recommendation</a>.</li> </ol> </li> <li>Add the <strong>TIMESTAMP</strong> parameter (available in the <strong>Specials</strong> tab).<ol> <li>Select the <strong>Date</strong> operator.</li> <li>Select the <strong>More than</strong> option.</li> <li>Keep clicking the icon next to the logical operator until you get <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/choose-value.png" alt="Choose value icon" class="icon"></li> <li>Select the aggregate that <a href="/use-cases/items-bought-after-clicking/#getting-the-timestamp-of-the-first-visit">returns the timestamp of the first product visit</a>.</li> </ol> </li> </ol> </li> <li>Select the date range of the metric (for example, last 30 days).</li> <li>Save the metric by clicking <strong>Save</strong>.</li> </ol> <figure> <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/metric-nr-four-use-case.png" alt="Configuration of the metric" class="full" > <figcaption> Configuration of the metric </figcaption> </figure></div></details>


## What's next
---

You can display created metrics on the [dashboard](/docs/analytics/analytics-dashboard), which help you present them in useful and readable form.

## Check the use case set up on the Synerise Demo workspace
---
You can check the created metrics directly in Synerise Demo workspace:
- [Number of products bought after clicking the campaign](https://app.synerise.com/analytics/metrics/2603b814-57e6-4bfd-ad4f-f73677003117)
- [The sum of products bought after clicking a campaign](https://app.synerise.com/analytics/metrics/cada2f5c-5295-4b88-9a29-be74f0cf2044)
- [The number of transactions with the products bought after clicking a campaign](https://app.synerise.com/analytics/metrics/7c105ed8-1c55-438c-bebb-40cdaf06d792)
- [The sum of transactions with the products bought after clicking a campaign](https://app.synerise.com/analytics/metrics/e0058e97-b130-4632-b4aa-5500c369cda9)

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) 
- [Recommendations](/docs/ai-hub/recommendations-v2/creating-recommendation-campaign)
