# Calculating e-commerce conversion rate

**URL:** <https://discuss.elastic.co/t/calculating-e-commerce-conversion-rate/88676>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 7:47am UTC](https://discuss.elastic.co/t/calculating-e-commerce-conversion-rate/88676 "2017-06-08T07:47:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ygokirmak](https://avatars.discourse-cdn.com/v4/letter/y/d07c76/32.png) [@ygokirmak](https://discuss.elastic.co/u/ygokirmak)\
**Post date:** [June 8, 2017, 7:47am UTC](https://discuss.elastic.co/t/calculating-e-commerce-conversion-rate/88676/1 "2017-06-08T07:47:35Z")

</div>

Hi all,

I need to calculate conversion rates (view/purchase) for each banner in my e-commerce site. I have 3 documents, assume you are surfing on an ecommerce site there are lots of products and banners. When u see a banner, banner\_view event is saved to elasticsearch. On banner\_view event we have user\_id ( who saw the banner ) and banner\_id

```
---------------------------
banner_view
---------------------------
{
	"user-id": "id-1234",
	"banner-id": "banner_x",
}

```

Actually from the system point of view I know which banner is related to which products. Say I have a set of documents showing this relation;  
---------------------------  
banner-product-relation  
---------------------------  
{  
"banner-id": "banner\_x",  
"product\_ids": [  
"product\_1",   
"product\_8"  
]  
}  
{  
"banner-id": "banner\_y",  
"product\_ids": [  
"product\_10",   
"product\_11",   
"product\_12"  
]  
}

Assume during your session, you decided to buy some products. When u buy products checkout\_completed event is triggered ans saved in elasticsearch.

```
---------------------------
checkout_completed
---------------------------
{
	"user-id": "id-1234",
	"products" : [
		{
			product_id: "product_1",
			price: "123"
		},
		{
			product_id: "product_2",
			price: "253"
		},
		{
			product_id: "product_3",
			price: "62"
		}

	]	

}

```

As u see in samples user (id\_1234) first saw a banner (banner\_x) then bought a product (product\_1) which is related to banner. In order to calculate conversion for each banner I need something like that;

```
user-id | banner_id | impression_count | purchase_count 
id-1234 | banner_x | 1 | 1

```

How can I calculate such an aggregation with elasticsearch,  
please feel free to advice model changes also, I can change model of documents or create new documents.

regards.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 7:47am UTC](https://discuss.elastic.co/t/calculating-e-commerce-conversion-rate/88676/2 "2017-07-06T07:47:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
