@recapi/client 0.17.1 → 0.17.2

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,12 +35,14 @@ 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.17.1/index.js';
38
+ import { createClient } from 'https://api.example.com/sdk/0.17.2/index.js';
39
+
40
+ const ITEM_ID = ''; // this page's product id
39
41
 
40
42
  const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
41
43
  // From your cookie banner, once the visitor agrees: recapi.setConsent(true).
42
44
  // A site that needs no banner passes consent: true instead (see Consent).
43
- recapi.track('item-42', 'view'); // and the calls of the quick start below
45
+ recapi.track(ITEM_ID, 'view'); // and the calls of the quick start below
44
46
  </script>
45
47
  ```
46
48
 
@@ -85,7 +87,8 @@ const recapi = createClient({
85
87
  });
86
88
 
87
89
  // The user opened an item: a product, an article, a video… (level 3).
88
- recapi.track('item-42', 'view');
90
+ // itemId is that page's own id: an empty one sends nothing.
91
+ recapi.track(itemId, 'view');
89
92
 
90
93
  // Show recommendations. If recapi is slow, failing or at your plan's limit,
91
94
  // recommend() resolves with popular items instead, and with an empty list if
@@ -591,7 +594,7 @@ const recapi = createClient({
591
594
  });
592
595
 
593
596
  recapi.identify('cust-881');
594
- recapi.track('item-42', 10); // the action that matters most: a purchase, a subscription…
597
+ recapi.track('item_4471', 10); // the action that matters most: a purchase, a subscription…
595
598
  await recapi.destroy(); // flushes queued events before exit
596
599
  ```
597
600
 
@@ -633,7 +636,7 @@ export default {
633
636
  async fetch(request, env, ctx) {
634
637
  const visitor = createClient({ ...options, consent: false });
635
638
  visitor.identify('cust-881');
636
- visitor.track('item-42', 'purchase');
639
+ visitor.track('item_4471', 'purchase');
637
640
  ctx.waitUntil(visitor.flush()); // sends the events after the response
638
641
  const { items } = await shared.popular({ count: 4 });
639
642
  return Response.json(items);
@@ -665,7 +668,7 @@ const recapi = createClient({ apiKey: process.env.RECAPI_KEY, baseUrl: 'https://
665
668
 
666
669
  On Node 18, or 20 before 20.19, `require` throws `ERR_REQUIRE_ESM`. Load
667
670
  the library once with `import()`, which CommonJS has on every Node, then
668
- `await recapi` where you use it: `(await recapi).track('item-42', 'view')`.
671
+ `await recapi` where you use it: `(await recapi).track('item_4471', 'view')`.
669
672
 
670
673
  ```js
671
674
  // CommonJS, Node 18 and later
@@ -806,7 +809,7 @@ parameters and resolves to its own result, in order, with its own
806
809
 
807
810
  ```js
808
811
  const [similar, more] = await recapi.recommendLists({
809
- lists: [{ placement: 'product', count: 4, contextItemId: 'item-42' }, { placement: 'more', count: 8 }]
812
+ lists: [{ placement: 'product', count: 4, contextItemId: 'item_4471' }, { placement: 'more', count: 8 }]
810
813
  });
811
814
  ```
812
815
 
@@ -1115,6 +1118,9 @@ minifier, to keep zero dev dependencies.
1115
1118
 
1116
1119
  ## Changes
1117
1120
 
1121
+ - 2026-11-24: version 0.17.2. `track()` with an empty item id (the
1122
+ quick start's tag before its `ITEM_ID` is set) still sends nothing, and
1123
+ its console line now says to set `ITEM_ID`.
1118
1124
  - 2026-11-24: version 0.17.1. WooCommerce: the settings screen names
1119
1125
  where the dashboard now keeps the API keys (the Quickstart's last
1120
1126
  section) and the past-orders upload (Your data, under Set up).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recapi/client",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
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/client.js CHANGED
@@ -569,7 +569,10 @@ export function createClient(options) {
569
569
  // must not fail it. Nothing is kept: in the history it would make the
570
570
  // API refuse every later list. The line never quotes the visitor's id.
571
571
  if (!isId(itemId)) {
572
- report(new RecapiError('invalid_request', idRule('itemId')), true);
572
+ // An empty id is most often the quick start's tag pasted before its
573
+ // ITEM_ID was set: the line says which constant to fill in.
574
+ const rule = itemId === '' ? "itemId is empty, nothing sent: set ITEM_ID in recapi's tag to this page's product id" : idRule('itemId');
575
+ report(new RecapiError('invalid_request', rule), true);
573
576
  return;
574
577
  }
575
578
  if (quiet) return;