feat(medusa-plugin-segment): adds category and type to segment events (#179)

This commit is contained in:
Sebastian Rindom
2021-02-22 08:45:01 +01:00
committed by GitHub
parent 99ad43bf47
commit e27cf72a8c
2 changed files with 11 additions and 1 deletions

View File

@@ -10,11 +10,12 @@ class SegmentService extends BaseService {
* write_key: Segment write key given in Segment dashboard
* }
*/
constructor({ totalsService }, options) {
constructor({ totalsService, productService }, options) {
super()
this.totalsService_ = totalsService
this.options_ = options
this.productService_ = productService
this.analytics_ = new Analytics(options.write_key)
}
@@ -129,12 +130,19 @@ class SegmentService extends BaseService {
variant = item.variant.sku
}
const product = await this.productService_.retrieve(
item.variant.product_id,
{ relations: ["collection", "type"] }
)
return {
name,
variant,
price: lineTotal / 100 / item.quantity,
reporting_revenue: revenue,
product_id: item.variant.product_id,
category: product.collection?.title,
type: product.type?.value,
sku,
quantity: item.quantity,
}

View File

@@ -74,6 +74,7 @@ class OrderSubscriber {
"payments",
"fulfillments",
"returns",
"items",
"gift_cards",
"gift_card_transactions",
"swaps",
@@ -160,6 +161,7 @@ class OrderSubscriber {
"shipping_methods",
"payments",
"fulfillments",
"items",
"returns",
"gift_cards",
"gift_card_transactions",