feat(medusa-plugin-segment): adds category and type to segment events (#179)
This commit is contained in:
@@ -10,11 +10,12 @@ class SegmentService extends BaseService {
|
|||||||
* write_key: Segment write key given in Segment dashboard
|
* write_key: Segment write key given in Segment dashboard
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
constructor({ totalsService }, options) {
|
constructor({ totalsService, productService }, options) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.totalsService_ = totalsService
|
this.totalsService_ = totalsService
|
||||||
this.options_ = options
|
this.options_ = options
|
||||||
|
this.productService_ = productService
|
||||||
|
|
||||||
this.analytics_ = new Analytics(options.write_key)
|
this.analytics_ = new Analytics(options.write_key)
|
||||||
}
|
}
|
||||||
@@ -129,12 +130,19 @@ class SegmentService extends BaseService {
|
|||||||
variant = item.variant.sku
|
variant = item.variant.sku
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const product = await this.productService_.retrieve(
|
||||||
|
item.variant.product_id,
|
||||||
|
{ relations: ["collection", "type"] }
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
variant,
|
variant,
|
||||||
price: lineTotal / 100 / item.quantity,
|
price: lineTotal / 100 / item.quantity,
|
||||||
reporting_revenue: revenue,
|
reporting_revenue: revenue,
|
||||||
product_id: item.variant.product_id,
|
product_id: item.variant.product_id,
|
||||||
|
category: product.collection?.title,
|
||||||
|
type: product.type?.value,
|
||||||
sku,
|
sku,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class OrderSubscriber {
|
|||||||
"payments",
|
"payments",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
"returns",
|
"returns",
|
||||||
|
"items",
|
||||||
"gift_cards",
|
"gift_cards",
|
||||||
"gift_card_transactions",
|
"gift_card_transactions",
|
||||||
"swaps",
|
"swaps",
|
||||||
@@ -160,6 +161,7 @@ class OrderSubscriber {
|
|||||||
"shipping_methods",
|
"shipping_methods",
|
||||||
"payments",
|
"payments",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
|
"items",
|
||||||
"returns",
|
"returns",
|
||||||
"gift_cards",
|
"gift_cards",
|
||||||
"gift_card_transactions",
|
"gift_card_transactions",
|
||||||
|
|||||||
Reference in New Issue
Block a user