@recapi/client 0.16.1 → 0.17.1
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 +11 -4
- package/package.json +1 -1
- package/src/shopify.js +9 -1
- package/src/woocommerce.js +4 -2
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.
|
|
38
|
+
import { createClient } from 'https://api.example.com/sdk/0.17.1/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).
|
|
@@ -162,7 +162,7 @@ nothing to paste again. A file of its own rather than more exports of
|
|
|
162
162
|
a page costs one call (two with a top-up), billed as one recommendation
|
|
163
163
|
each, a product page's second row included (below). Each row asks for its own placement: `product` on
|
|
164
164
|
product pages, `cart` on the cart page (Shopify's `request.page_type`),
|
|
165
|
-
`section` elsewhere, so
|
|
165
|
+
`section` elsewhere, so Home's "By placement" and a lift test tell
|
|
166
166
|
them apart; one not configured in the dashboard serves as `default`, with
|
|
167
167
|
its settings and its running lift test. A shop that pasted an earlier
|
|
168
168
|
snippet keeps it, with every row on `default` and 6 products asked for,
|
|
@@ -372,7 +372,7 @@ shortcode shows none unless given one: `[recapi heading="You may also like"]`.
|
|
|
372
372
|
|
|
373
373
|
Each row asks for its own placement: `product` on product pages (the
|
|
374
374
|
Related products spot, or `[recapi]` in a product template), `cart` for
|
|
375
|
-
`[recapi]` on the cart page, `shortcode` elsewhere, so
|
|
375
|
+
`[recapi]` on the cart page, `shortcode` elsewhere, so Home's "By
|
|
376
376
|
placement" and a lift test tell them apart. A placement not configured in
|
|
377
377
|
the dashboard serves as `default`, with its settings and its running lift
|
|
378
378
|
test, so a shop that set `default` up keeps it.
|
|
@@ -466,7 +466,7 @@ library so it stays one file (a snippet holds it) and follows the site's
|
|
|
466
466
|
proxy settings.
|
|
467
467
|
|
|
468
468
|
Have past orders? Download them from WooCommerce → recapi and upload the
|
|
469
|
-
file on
|
|
469
|
+
file on Your data (under Set up). The plugin writes the last 90 days of processing and
|
|
470
470
|
completed orders as the dashboard's `user_id,item_id,level,timestamp` CSV,
|
|
471
471
|
one `purchase` per order line, dated when the order was paid (else
|
|
472
472
|
placed). The buyer is the customer id `identify()` sends, a guest
|
|
@@ -1115,6 +1115,13 @@ minifier, to keep zero dev dependencies.
|
|
|
1115
1115
|
|
|
1116
1116
|
## Changes
|
|
1117
1117
|
|
|
1118
|
+
- 2026-11-24: version 0.17.1. WooCommerce: the settings screen names
|
|
1119
|
+
where the dashboard now keeps the API keys (the Quickstart's last
|
|
1120
|
+
section) and the past-orders upload (Your data, under Set up).
|
|
1121
|
+
- 2026-11-22: version 0.17.0. Shopify's pixel and WooCommerce's
|
|
1122
|
+
order-received page send what each line bought paid, and its currency,
|
|
1123
|
+
with the purchase (`value`, `currency`); a line without a price is sent
|
|
1124
|
+
without them.
|
|
1118
1125
|
- 2026-11-22: version 0.16.1. WooCommerce: the settings screen accepts the
|
|
1119
1126
|
new secret keys, which end in a six-character checksum (38 characters
|
|
1120
1127
|
after `rk_sec_`, 32 before); keys of the old form keep working.
|
package/package.json
CHANGED
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
|
}
|
package/src/woocommerce.js
CHANGED
|
@@ -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[],
|
|
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
|
-
|
|
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
|