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
|
||||
* }
|
||||
*/
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user