diff --git a/packages/medusa-plugin-segment/src/services/segment.js b/packages/medusa-plugin-segment/src/services/segment.js index eaeddcf5e8..8c1610f493 100644 --- a/packages/medusa-plugin-segment/src/services/segment.js +++ b/packages/medusa-plugin-segment/src/services/segment.js @@ -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, } diff --git a/packages/medusa-plugin-segment/src/subscribers/order.js b/packages/medusa-plugin-segment/src/subscribers/order.js index 3ee9ad40c7..fe422dca4a 100644 --- a/packages/medusa-plugin-segment/src/subscribers/order.js +++ b/packages/medusa-plugin-segment/src/subscribers/order.js @@ -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",