@recapi/client 0.17.0 → 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 +19 -10
- package/package.json +1 -1
- package/src/client.js +4 -1
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.
|
|
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(
|
|
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
|
-
|
|
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
|
|
@@ -162,7 +165,7 @@ nothing to paste again. A file of its own rather than more exports of
|
|
|
162
165
|
a page costs one call (two with a top-up), billed as one recommendation
|
|
163
166
|
each, a product page's second row included (below). Each row asks for its own placement: `product` on
|
|
164
167
|
product pages, `cart` on the cart page (Shopify's `request.page_type`),
|
|
165
|
-
`section` elsewhere, so
|
|
168
|
+
`section` elsewhere, so Home's "By placement" and a lift test tell
|
|
166
169
|
them apart; one not configured in the dashboard serves as `default`, with
|
|
167
170
|
its settings and its running lift test. A shop that pasted an earlier
|
|
168
171
|
snippet keeps it, with every row on `default` and 6 products asked for,
|
|
@@ -372,7 +375,7 @@ shortcode shows none unless given one: `[recapi heading="You may also like"]`.
|
|
|
372
375
|
|
|
373
376
|
Each row asks for its own placement: `product` on product pages (the
|
|
374
377
|
Related products spot, or `[recapi]` in a product template), `cart` for
|
|
375
|
-
`[recapi]` on the cart page, `shortcode` elsewhere, so
|
|
378
|
+
`[recapi]` on the cart page, `shortcode` elsewhere, so Home's "By
|
|
376
379
|
placement" and a lift test tell them apart. A placement not configured in
|
|
377
380
|
the dashboard serves as `default`, with its settings and its running lift
|
|
378
381
|
test, so a shop that set `default` up keeps it.
|
|
@@ -466,7 +469,7 @@ library so it stays one file (a snippet holds it) and follows the site's
|
|
|
466
469
|
proxy settings.
|
|
467
470
|
|
|
468
471
|
Have past orders? Download them from WooCommerce → recapi and upload the
|
|
469
|
-
file on
|
|
472
|
+
file on Your data (under Set up). The plugin writes the last 90 days of processing and
|
|
470
473
|
completed orders as the dashboard's `user_id,item_id,level,timestamp` CSV,
|
|
471
474
|
one `purchase` per order line, dated when the order was paid (else
|
|
472
475
|
placed). The buyer is the customer id `identify()` sends, a guest
|
|
@@ -591,7 +594,7 @@ const recapi = createClient({
|
|
|
591
594
|
});
|
|
592
595
|
|
|
593
596
|
recapi.identify('cust-881');
|
|
594
|
-
recapi.track('
|
|
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('
|
|
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('
|
|
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: '
|
|
812
|
+
lists: [{ placement: 'product', count: 4, contextItemId: 'item_4471' }, { placement: 'more', count: 8 }]
|
|
810
813
|
});
|
|
811
814
|
```
|
|
812
815
|
|
|
@@ -1115,6 +1118,12 @@ 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`.
|
|
1124
|
+
- 2026-11-24: version 0.17.1. WooCommerce: the settings screen names
|
|
1125
|
+
where the dashboard now keeps the API keys (the Quickstart's last
|
|
1126
|
+
section) and the past-orders upload (Your data, under Set up).
|
|
1118
1127
|
- 2026-11-22: version 0.17.0. Shopify's pixel and WooCommerce's
|
|
1119
1128
|
order-received page send what each line bought paid, and its currency,
|
|
1120
1129
|
with the purchase (`value`, `currency`); a line without a price is sent
|
package/package.json
CHANGED
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
|
-
|
|
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;
|