From a58cd4e33c19a115d55cad4093b1457cd3f7c9ec Mon Sep 17 00:00:00 2001 From: rrader2890 Date: Wed, 15 Jul 2026 11:01:00 -0400 Subject: [PATCH] fix(examples): put order amount in metadata.amount so RFM monetary works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The next-best-offer demo wrote each order's price only into the memory `content` string ("Order — $42 pizza"). The RFM miner sums a structured numeric field (metadata.value/total/amount, or a lineItems array) for the Monetary score and does not parse prices out of free text, so every contact in the demo scored M=0 — the monetary axis of RFM was dead in our own flagship example, and customers copying it hit the same wall. Move the dollar amount into `metadata.amount` (a JSON number) on each order_placed event and drop it from the display text. Non-order events (site_visit, email_open) carry no amount, as before. Co-Authored-By: Claude Opus 4.8 (1M context) --- examples/next-best-offer.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/next-best-offer.ts b/examples/next-best-offer.ts index dfb5a0d..bfbba28 100644 --- a/examples/next-best-offer.ts +++ b/examples/next-best-offer.ts @@ -338,10 +338,13 @@ const CONTACTS: Contact[] = [ // Regular-then-quiet → a win-back candidate. externalId: 'sarah-lapsing', activity: [ - { activityType: 'order_placed', content: 'Order #1 — $42 pizza', occurredAt: daysAgo(90) }, - { activityType: 'order_placed', content: 'Order #2 — $38 pizza', occurredAt: daysAgo(76) }, - { activityType: 'order_placed', content: 'Order #3 — $45 pizza', occurredAt: daysAgo(62) }, - { activityType: 'order_placed', content: 'Order #4 — $40 pizza', occurredAt: daysAgo(48) }, + // The dollar amount goes in `metadata.amount` (a JSON number) — that is + // the field the RFM miner sums for the Monetary score. A price written + // only into `content` is not parsed, so it would leave M=0. + { activityType: 'order_placed', content: 'Order #1 — pizza', occurredAt: daysAgo(90), metadata: { amount: 42 } }, + { activityType: 'order_placed', content: 'Order #2 — pizza', occurredAt: daysAgo(76), metadata: { amount: 38 } }, + { activityType: 'order_placed', content: 'Order #3 — pizza', occurredAt: daysAgo(62), metadata: { amount: 45 } }, + { activityType: 'order_placed', content: 'Order #4 — pizza', occurredAt: daysAgo(48), metadata: { amount: 40 } }, { activityType: 'site_visit', content: 'Browsed menu, did not order', occurredAt: daysAgo(20) }, ], }, @@ -349,9 +352,9 @@ const CONTACTS: Contact[] = [ // Frequent + steady → reward, don't discount. externalId: 'mike-loyal', activity: [ - { activityType: 'order_placed', content: 'Order — $30', occurredAt: daysAgo(21) }, - { activityType: 'order_placed', content: 'Order — $34', occurredAt: daysAgo(14) }, - { activityType: 'order_placed', content: 'Order — $28', occurredAt: daysAgo(7) }, + { activityType: 'order_placed', content: 'Order', occurredAt: daysAgo(21), metadata: { amount: 30 } }, + { activityType: 'order_placed', content: 'Order', occurredAt: daysAgo(14), metadata: { amount: 34 } }, + { activityType: 'order_placed', content: 'Order', occurredAt: daysAgo(7), metadata: { amount: 28 } }, { activityType: 'email_open', content: 'Opened weekly newsletter', occurredAt: daysAgo(2) }, ], }, @@ -359,9 +362,9 @@ const CONTACTS: Contact[] = [ // Predictable monthly cadence → replenishment timing play. externalId: 'ana-replenish', activity: [ - { activityType: 'order_placed', content: 'Coffee beans 1kg — $24', occurredAt: daysAgo(88) }, - { activityType: 'order_placed', content: 'Coffee beans 1kg — $24', occurredAt: daysAgo(58) }, - { activityType: 'order_placed', content: 'Coffee beans 1kg — $24', occurredAt: daysAgo(29) }, + { activityType: 'order_placed', content: 'Coffee beans 1kg', occurredAt: daysAgo(88), metadata: { amount: 24 } }, + { activityType: 'order_placed', content: 'Coffee beans 1kg', occurredAt: daysAgo(58), metadata: { amount: 24 } }, + { activityType: 'order_placed', content: 'Coffee beans 1kg', occurredAt: daysAgo(29), metadata: { amount: 24 } }, ], }, ]