@recapi/client 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,7 +35,7 @@ are, gzipped, and browsers cache them:
35
35
 
36
36
  ```html
37
37
  <script type="module">
38
- import { createClient } from 'https://api.example.com/sdk/0.16.1/index.js';
38
+ import { createClient } from 'https://api.example.com/sdk/0.17.0/index.js';
39
39
 
40
40
  const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
41
41
  // From your cookie banner, once the visitor agrees: recapi.setConsent(true).
@@ -1115,6 +1115,10 @@ minifier, to keep zero dev dependencies.
1115
1115
 
1116
1116
  ## Changes
1117
1117
 
1118
+ - 2026-11-22: version 0.17.0. Shopify's pixel and WooCommerce's
1119
+ order-received page send what each line bought paid, and its currency,
1120
+ with the purchase (`value`, `currency`); a line without a price is sent
1121
+ without them.
1118
1122
  - 2026-11-22: version 0.16.1. WooCommerce: the settings screen accepts the
1119
1123
  new secret keys, which end in a six-character checksum (38 characters
1120
1124
  after `rk_sec_`, 32 before); keys of the old form keep working.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recapi/client",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "description": "Browser and Node client for the recapi recommendation API: local decayed history, event batching, attribution.",
5
5
  "homepage": "https://recapi.io/docs",
6
6
  "bugs": {
package/src/shopify.js CHANGED
@@ -403,6 +403,14 @@ const fromCart = (attributes) => {
403
403
  }
404
404
  };
405
405
 
406
+ // What the line cost the buyer after its discounts, as Shopify reports it
407
+ // (with tax where the shop's prices include it). A price the API would
408
+ // refuse is left out, never the purchase: track() throws on a bad amount.
409
+ const paid = (price) => (typeof price?.amount === 'number' && price.amount >= 0 && price.amount !== Infinity
410
+ && typeof price.currencyCode === 'string' && /^[A-Za-z]{3}$/.test(price.currencyCode)
411
+ ? { value: price.amount, currency: price.currencyCode }
412
+ : {});
413
+
406
414
  async function withRecapi({ apiKey, baseUrl, project, platform, browser }, track, attributes) {
407
415
  // The pixel's own storage is not the shop's: read the snippet's state from
408
416
  // the page (browser.localStorage is asynchronous, the SDK's storage
@@ -443,7 +451,7 @@ export function shopifyPixel(options, name, event) {
443
451
  return withRecapi(options, (recapi) => {
444
452
  for (const line of event.data.checkout.lineItems) {
445
453
  const item = handleOf(line.variant?.product?.url);
446
- if (item) recapi.track(item, 'purchase');
454
+ if (item) recapi.track(item, 'purchase', paid(line.finalLinePrice));
447
455
  }
448
456
  }, event.data.checkout.attributes);
449
457
  }
@@ -25,7 +25,8 @@ import { createClient } from './index.js';
25
25
  * heading?: string|null, together?: string|null, orders?: boolean,
26
26
  * consent: 'wp-consent-api'|'banner'|'no-banner'|string,
27
27
  * currency?: string|null,
28
- * order?: { items: string[], customer: string|null }|null } }} options
28
+ * order?: { items: string[], amounts?: ({ value: number, currency: string }|null)[],
29
+ * customer: string|null }|null } }} options
29
30
  */
30
31
  export async function woocommercePage({ apiKey, baseUrl, platform, page }) {
31
32
  // recapi keeps a history on the visitor's device only with their consent,
@@ -145,7 +146,8 @@ export async function woocommercePage({ apiKey, baseUrl, platform, page }) {
145
146
  // and the recommendations they clicked where the product pages left them.
146
147
  if (page.order) {
147
148
  if (page.order.customer) recapi.identify(page.order.customer);
148
- for (const item of page.order.items) recapi.track(item, 'purchase');
149
+ // An older plugin prints no amounts: its purchases go without one.
150
+ page.order.items.forEach((item, i) => recapi.track(item, 'purchase', page.order.amounts?.[i] ?? {}));
149
151
  }
150
152
 
151
153
  // Fills <div id="recapi-recommendations"></div>. A merchant who pasted one