@recapi/client 0.18.1 → 0.33.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 CHANGED
@@ -27,6 +27,25 @@ Playwright's Linux build, not Safari on an iPhone: the engine is the same,
27
27
  but Safari's own storage rules (data deleted after seven days without a
28
28
  visit, private browsing) are not part of it.
29
29
 
30
+ ### A still page in each engine
31
+
32
+ A row's place is held while it loads (WooCommerce and Magento print blank
33
+ cards, Shopify's box and the quick start's element hold it by style). In
34
+ each engine, the most the content under the rows moved from the first paint
35
+ (recapi's page-shift test, before and after 0.33.1, in px):
36
+
37
+ | Page | Chromium 390 / 1440 | Firefox 390 / 1440 | WebKit 390 / 1440 |
38
+ |---|---|---|---|
39
+ | Shopify box | 76 / 186 → 0.2 / 0.2 | 76 / 186 → 0.1 / 0.1 | 76 / 186 → 0.2 / 0.2 |
40
+ | WooCommerce | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 |
41
+ | Magento | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 |
42
+ | Plain row | 26 / 1.2 → 1.2 / 1.2 | 26 / 1.1 → 1.1 / 1.1 | 26 / 1.2 → 1.2 / 1.2 |
43
+
44
+ Without the script, every hold stays put, then closes after 4 s. Safari
45
+ 15.4 to 16.3 lacks the `lh` unit, and 15.4 container queries: there
46
+ Shopify's box and the quick start's element hold nothing until the script
47
+ comes, and blank cards are a line short. Nothing is hidden.
48
+
30
49
  ## Install
31
50
 
32
51
  On a site without a build step (a theme, plain HTML), load the SDK from
@@ -35,14 +54,12 @@ are, gzipped, and browsers cache them:
35
54
 
36
55
  ```html
37
56
  <script type="module">
38
- import { createClient } from 'https://api.example.com/sdk/0.18.1/index.js';
39
-
40
- const ITEM_ID = ''; // this page's product id
57
+ import { createClient } from 'https://api.example.com/sdk/0.33.1/index.js';
41
58
 
42
59
  const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
43
60
  // From your cookie banner, once the visitor agrees: recapi.setConsent(true).
44
61
  // A site that needs no banner passes consent: true instead (see Consent).
45
- recapi.track(ITEM_ID, 'view'); // and the calls of the quick start below
62
+ recapi.track('view'); // this page's product, and the calls of the quick start below
46
63
  </script>
47
64
  ```
48
65
 
@@ -87,7 +104,9 @@ const recapi = createClient({
87
104
  });
88
105
 
89
106
  // The user opened an item: a product, an article, a video… (level 3).
90
- // itemId is that page's own id: an empty one sends nothing.
107
+ // itemId is that page's own id: an empty one sends nothing. On a product
108
+ // page, the first view also sends the product's name (see describePages).
109
+ // No ids of your own? recapi.track('view') takes the page's product.
91
110
  recapi.track(itemId, 'view');
92
111
 
93
112
  // A row of 4 product cards in <div id="recommendations"></div>, drawn from
@@ -130,7 +149,7 @@ nothing to paste again. A file of its own rather than more exports of
130
149
  A theme whose footer takes no sections gets it before `</body>` in
131
150
  `layout/theme.liquid` instead, again after each update. Its Liquid is
132
151
  `product.handle`, `product.title`, `product.type`, `product.tags`,
133
- `customer.id` and `request.page_type`, which a section
152
+ `product.available`, `customer.id` and `request.page_type`, which a section
134
153
  reads as the layout does, and it stays far below the setting's 50 KB. It identifies a
135
154
  logged-in customer, tracks product views, sends each product page's title,
136
155
  type and tags to `POST /v1/shopify/products:seen` (once per product per
@@ -139,12 +158,16 @@ nothing to paste again. A file of its own rather than more exports of
139
158
  a page of 250 per product view while recapi's answer asks for one (once the
140
159
  browser is idle and after the row; recapi keeps the progress, so nothing is
141
160
  stored), and fills the
142
- `<div id="recapi-recommendations" style="min-height: 320px">&nbsp;</div>`
161
+ `<div id="recapi-recommendations"><style>#recapi-recommendations{container-type:inline-size}#recapi-recommendations:not(:is(.page-width,.section--page-width) *){box-sizing:border-box;max-width:var(--page-width,1200px);margin-inline:auto;padding-inline:clamp(1.5rem,(100vw - 749px)*999,5rem)}#recapi-recommendations::before{content:"";display:block;--c:4;--l:2;height:calc(var(--l)*((100cqw + 1rem)/var(--c) + .5rem + 3lh) + .4rem + 2lh);animation:recapi-gone 0s 4s forwards}@container (width<630px){#recapi-recommendations::before{--c:3;--l:4}}@container (width<470px){#recapi-recommendations::before{--c:2}}@keyframes recapi-gone{to{height:0}}</style></div>`
143
162
  the shop pastes where the row goes with 4 product
144
- cards it loads from Shopify's `/products/<handle>.js`. The `&nbsp;` matters:
145
- Dawn and the themes built on it hide every empty `div`, and a hidden box
146
- never comes near the screen; the snippet also puts its style in a box
147
- pasted empty at once, and warns in the console when the page still hides it. Like the row of
163
+ cards it loads from Shopify's `/products/<handle>.js`. The box's style
164
+ holds a blank card's place in the row's own proportions from the first
165
+ paint and closes it after 4 s, so without the script (recapi down, a
166
+ blocker) it closes by itself; the script holds the place itself from its
167
+ start. The
168
+ `<style>` inside matters: Dawn and the themes built on it hide every empty
169
+ `div`, and a hidden box never comes near the screen; the snippet also puts
170
+ its style in a box pasted empty at once, and warns in the console when the page still hides it. Like the row of
148
171
  Shopify's own themes, it asks for them only once the div comes within
149
172
  400px of the screen (an `IntersectionObserver`, at once in a browser
150
173
  without one): each list is billed and counted as an impression, and a
@@ -163,12 +186,12 @@ nothing to paste again. A file of its own rather than more exports of
163
186
  a page costs one call (two with a top-up), billed as one recommendation
164
187
  each, a product page's second row included (below). Each row asks for its own placement: `product` on
165
188
  product pages, `cart` on the cart page (Shopify's `request.page_type`),
166
- `section` elsewhere, so Home's "By placement" and a lift test tell
189
+ `section` elsewhere, so Home's "By row" and a lift test tell
167
190
  them apart; one not configured in the dashboard serves as `default`, with
168
191
  its settings and its running lift test. A shop that pasted an earlier
169
192
  snippet keeps it, with every row on `default` and 6 products asked for,
170
193
  until it pastes this one: its served lists and CTR then read on 4 products
171
- a list, and "By placement" splits `default` into the rows above.
194
+ a list, and "By row" splits `default` into the rows above.
172
195
 
173
196
  From 0.11.0 a product page has a second row, under the first: what
174
197
  shoppers bought with the product on screen, placement `bought_together`,
@@ -181,6 +204,23 @@ nothing to paste again. A file of its own rather than more exports of
181
204
  any text of the shop's, `''` for no title, `false` for no second row.
182
205
  Pieces pasted before 0.11.0 get the row too, with the default title.
183
206
 
207
+ From 0.27.1 the home page (`pageType` `index`) has a second row too,
208
+ placement `recently_viewed`, in
209
+ the same call, in a `<div id="recapi-recently-viewed">` after the slot under
210
+ "Recently viewed" in the page's language. It shows only when its list holds
211
+ a product the shopper opened (`why: viewed_earlier`), and its cards carry no
212
+ "You looked at this" mark: the title says it.
213
+ From 0.29.4 a home page without the slot gets the row alone, in a
214
+ `<div id="recapi-home">` the snippet adds at the end of `main` (else right
215
+ before the section holding the snippet), hidden while it has no card. The
216
+ theme editor gets none.
217
+
218
+ From 0.19.3, when `product.available` is `false`, there is no second row and
219
+ the first opens with an `<h2 class="recapi-heading">` in the slot, "Other
220
+ products in stock" in the page's language. A heading the shop wrote right
221
+ above the slot stays the row's title instead. Pieces pasted before
222
+ 0.19.3 don't say whether the product is sold out, and change nothing.
223
+
184
224
  Each row shows or hides on its own: an empty first row hides its slot and
185
225
  leaves the second; a short row is topped up in the one more call, with
186
226
  only the short rows, without any product either row listed. A refused top-up
@@ -281,7 +321,7 @@ may be added, never renamed or dropped, as shops never paste again.
281
321
 
282
322
  | Call | Options |
283
323
  |---|---|
284
- | `shopifyTheme(options)` (theme) | `apiKey`, `baseUrl`, `project`, `platform`; `product` (`handle`, `title`, `type`, `tags`: Liquid's `product`, all `null` off a product page); `shopCurrency`; `customerId` (`''` for a guest); `pageType` (`request.page_type`); `boughtTogether` (from 0.11.0: the product page's second row's title, `false` for none). Resolves once the page's work is set up. |
324
+ | `shopifyTheme(options)` (theme) | `apiKey`, `baseUrl`, `project`, `platform`; `product` (`handle`, `title`, `type`, `tags`, and from 0.19.3 `available`: Liquid's `product`, all `null` off a product page); `shopCurrency`; `customerId` (`''` for a guest); `pageType` (`request.page_type`); `boughtTogether` (from 0.11.0: the product page's second row's title, `false` for none). Resolves once the page's work is set up. |
285
325
  | `shopifyPixel(options, name, event)` (pixel) | `apiKey`, `baseUrl`, `project`, `platform`, `browser` (the sandbox's); `name` is the subscribed event's, `event` Shopify's. Other names are ignored. |
286
326
 
287
327
  `test/shopify.test.js` runs both pieces with `src/shopify.js` as the quick
@@ -294,12 +334,17 @@ fixture, and a change to the served code must keep every older piece
294
334
  working. The quick start fills in the current version, your address and your
295
335
  project (`jssdk.Shopify`).
296
336
 
297
- `shopify.js` keeps what only Shopify gives: the page's data, the product
298
- lookup for items without metadata, the currency, the consent banner, the
299
- pasted options. The rules every row shares (lazy ask, link with the list's
300
- id, hiding, the bought-together title, card styles) come from `cards.js`,
301
- which [the ready row](#the-ready-row) uses too. Each piece's rows are pinned
302
- to the byte in `test/fixtures/shopify/<version>/rows.txt`.
337
+ #### What the shop modules share
338
+
339
+ `shopify.js`, `woocommerce.js` and `magento.js` keep what only their
340
+ platform gives: the page's data, the store's own cards for items without
341
+ metadata, the currency, the consent, the cart. The rules every row shares
342
+ (lazy ask, the card, the list and its name, the link with the list's id,
343
+ hiding, the title, card styles) come from `cards.js`, which [the ready row](#the-ready-row) uses
344
+ too; what only the shop rows share (the view a card's link brings, both
345
+ rows in one call with their gaps topped up, the order cookie) from
346
+ `shops.js`. Each platform's rows are pinned to the byte, per published piece,
347
+ plugin or module, in `test/fixtures/<platform>/<version>/rows.txt`.
303
348
 
304
349
  Both files name themselves (`platform: 'shopify/<version>'`, sent as
305
350
  `?platform=` on every call), so recapi words its setup hints for Shopify.
@@ -394,12 +439,40 @@ as one, the first row first so no product is on both. The script adds the
394
439
  row as `<div id="recapi-bought-together">` (with its heading) right after
395
440
  the first row's div once it has cards: the printed page doesn't change,
396
441
  and a row with nothing to show leaves nothing. One row empty never hides
397
- the other. *WooCommerce → recapi* turns it off ("Your product pages",
442
+ the other. *WooCommerce → recapi* turns it off ("Your pages",
398
443
  option `recapi_bought_together`); the cart and shortcode rows never have it.
444
+ From 0.27.1 the front page (WordPress's `home` body class) asks for a second
445
+ row instead, `recently_viewed`, drawn as `<div id="recapi-recently-viewed">`
446
+ after the first by the same rule as Shopify's (above). A front page that is a
447
+ product page has all three rows, Recently viewed last (0.28.1).
448
+ From 0.29.0 a front page with no row of the merchant's gets the plugin's own
449
+ slot above the footer (`get_footer` on classic themes, before the footer
450
+ template part on block themes), with placement `recently_viewed`: it holds
451
+ that row alone under its title, or hides while the visitor opened nothing.
452
+ *WooCommerce → recapi* turns it off (option `recapi_home_recently_viewed`).
399
453
  From 0.15.1 the heading is added only when one of the cards drawn has
400
454
  `why: bought_together`; otherwise the cards show without it, a `margin-top`
401
455
  of the grid's gap under the first row.
402
456
 
457
+ On the page of a product WooCommerce calls out of stock (`is_in_stock()`; one
458
+ on back-order isn't), the plugin from 0.19.3 prints no second row and the
459
+ first right under the notice, from `woocommerce_<type>_add_to_cart` at
460
+ priority 31. It is titled "Other products in stock" in the site's language,
461
+ through the `woocommerce_product_related_products_heading` filter. A theme
462
+ that doesn't run that hook keeps the row's usual place. A `[recapi]` in the
463
+ product's descriptions or in a block theme's template keeps its own place and
464
+ title; one a page builder prints after the notice, or a pasted
465
+ `#recapi-recommendations` box there, gives way to the row at the notice.
466
+
467
+ A block theme that dropped the Related Products block still shows the row on
468
+ every product, after Product Details (WooCommerce's compatibility layer runs
469
+ the classic hook there). One without either block shows it on sold-out
470
+ products only. This line takes it off both, from a snippet or a theme:
471
+
472
+ ```php
473
+ add_action('template_redirect', fn () => remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20), 9);
474
+ ```
475
+
403
476
  The widget fills it like the Shopify snippet's, once it nears the screen,
404
477
  asking for the 4 products it shows (recapi counts every product of a list
405
478
  as shown, so a spare would get an impression and could be credited a view it
@@ -465,8 +538,8 @@ ran, how many products it sent and why any were refused. Every item is
465
538
  complete: `active` only while the product is published, not hidden from the
466
539
  catalog, purchasable and in stock (the Store API cards' rule), its category
467
540
  names as `tags` (not "Uncategorized"), its creation date as `published_at`,
468
- and `name`, `url`, `picture` (the `woocommerce_thumbnail` size) and `price`
469
- (as the shop displays it, in its currency) as `metadata`, shrunk below
541
+ and `name`, `url`, `picture` (the `woocommerce_thumbnail` size), `price`
542
+ (as the shop displays it, in its currency) and, on sale, `list_price` as `metadata`, shrunk below
470
543
  2,048 bytes as the Magento module does (picture first, then the name). The
471
544
  row then draws every card from it, with no Store API call. Only items that
472
545
  changed are billed. The plugin uses WordPress's HTTP API rather than the PHP
@@ -496,7 +569,7 @@ calls `User-Agent: recapi-woocommerce/<version>`.
496
569
 
497
570
  `scripts/e2e_woocommerce.sh` (CI job `woocommerce`) runs the plugin on a
498
571
  real, throwaway shop: WordPress and WooCommerce in Docker at pinned
499
- versions, twice: the newest (WordPress 7.1.4, WooCommerce 11.3.0, PHP 8.5)
572
+ versions, twice: the newest (WordPress 7.1.5, WooCommerce 11.3.1, PHP 8.5)
500
573
  and the oldest the plugin's header declares (WordPress 6.3, WooCommerce 8.3,
501
574
  PHP 7.4), the plugin taken from the quick start of a new recapi shop with
502
575
  its public key pasted, then a guest's browser (Playwright) on a product
@@ -561,6 +634,13 @@ together", is printed hidden and empty; from 0.15.1 the script removes that
561
634
  block's `.block-title` when none of the cards drawn has
562
635
  `why: bought_together`, so its cards read as more of the first row.
563
636
 
637
+ From module 0.4.35, a product Magento calls not salable (`isSalable()`; one on
638
+ back-order is) has no second row, and its first moves up: under the price and
639
+ the stock notice on Luma and its children, to the end of the product's box on
640
+ Hyvä, the layout's place on a theme with neither. A row the theme moved out
641
+ of `content.aside` keeps its place. Its title is "Other products
642
+ in stock" in the store view's language, unless the layout's `heading` names it.
643
+
564
644
  #### The served storefront code
565
645
 
566
646
  From module 0.4.25 (library 0.13.0) the module's template holds only what
@@ -582,7 +662,8 @@ never renamed or dropped, as stores keep the module they installed.
582
662
 
583
663
  The storefront code of every module version is kept in
584
664
  `test/fixtures/magento/<version>/` (`Block/Script.php` and the template;
585
- 0.4.24: the last one holding its own page code), and
665
+ 0.4.24: the last one holding its own page code; 0.4.33: also the row's
666
+ template, the last one without the list, for `scripts/e2e/rows.test.js`), and
586
667
  `test/magento_published.test.js` runs every case of `test/magento.test.js`
587
668
  through each against the current `src/`: a change to that code needs a new
588
669
  fixture, and a change to the served code must keep every older module working.
@@ -744,13 +825,14 @@ for (const item of items) {
744
825
  | `timeoutMs` | `5000` | per-request timeout; `recommend()` waits 1.5 s at most |
745
826
  | `historyConfig` | spec defaults | `{ halfLifeSeconds, topK, recentSize }`; must match the server |
746
827
  | `consent` | `false` | storage consent: `false` stores nothing until `setConsent(true)`, see [Consent](#consent-and-eprivacy) |
828
+ | `describePages` | `true` | in a browser, a product's first view also sends its page's name, category and address (no query) to [`POST /v1/products:seen`](https://recapi.io/docs/api#post-v1productsseen--what-any-product-page-says), about 200 bytes, once per product per browser. It never renames a product you sent; never under Do Not Track. `false` turns it off |
747
829
  | `respectDoNotTrack` | `true` | when DNT or Global Privacy Control is on: store nothing, send no events, see [Do Not Track](#do-not-track) |
748
830
  | `onError` | `console.warn` for lost events and lists it answered with a fallback | gets errors from background work (flushes, storage, rejected events) and those `recommend()` and `popular()` fell back from |
749
831
  | `now`, `fetch`, `sleep` | `Date.now`, global `fetch`, `setTimeout` | for tests |
750
832
 
751
833
  ### Client methods
752
834
 
753
- - **`track(itemId, level, { recommendationId?, value?, currency? })`**: `level` is any integer
835
+ - **`track(itemId, level, { recommendationId?, value?, currency?, send? })`**: `level` is any integer
754
836
  0–10 of the [recommended scale](https://recapi.io/docs/api#interaction-levels) (3
755
837
  opened, 5 strong interest, 10 the action that matters most), or one of its
756
838
  shop names `'view'`, `'cart'` and `'purchase'` (3, 5 and 10). `'reject'`
@@ -765,7 +847,10 @@ for (const item of items) {
765
847
  level. A purchase may carry `{ value, currency }` (what the buyer paid for
766
848
  the line, and its ISO 4217 code such as `'EUR'`), kept for the sales figure
767
849
  of a lift test; a negative value, or a currency without a value or not of
768
- three letters, throws the same error. An item id follows the API's rules, 1–256 bytes of UTF-8
850
+ three letters, throws the same error. `send: false` only records the
851
+ event in the visitor's history: use it on the order's page when your server
852
+ sends the purchases, so a list doesn't start with a product just bought.
853
+ An item id follows the API's rules, 1–256 bytes of UTF-8
769
854
  (128 characters of Cyrillic or accented Latin, 85 of CJK) without
770
855
  control characters; any other drops the event and reports it instead of
771
856
  throwing, as a visitor's URL can carry one (see [Fallback](#fallback)). A stored history entry whose id breaks the rule,
@@ -785,6 +870,8 @@ for (const item of items) {
785
870
  one call, see [below](#several-rows-in-one-call).
786
871
  - **`row(slot, { placement, contextItemId, heading })`**: a ready row, see
787
872
  [The ready row](#the-ready-row).
873
+ - **`track(level, options)`** and `row(slot)` with no `contextItemId` key:
874
+ the page's product, see [The page's product](#the-pages-product).
788
875
  - **`popular({ tagsAny, tagsAll, count })`** resolves to `{ items: [{ itemId, score, why, metadata }] }`.
789
876
  A public key goes in `?key=`, so the response can be cached by a CDN.
790
877
  [How the key is sent](#how-the-key-is-sent) gives the reason for the rest.
@@ -820,6 +907,19 @@ const [similar, more] = await recapi.recommendLists({
820
907
  });
821
908
  ```
822
909
 
910
+ The home page's second row, the products the visitor opened and has not
911
+ bought, is the built-in placement `RECENTLY_VIEWED`: ask it after the first
912
+ row, with nothing to set in the dashboard (`BOUGHT_TOGETHER` is the product
913
+ page's second row).
914
+
915
+ ```js
916
+ import { RECENTLY_VIEWED } from 'https://api.example.com/sdk/0.33.1/index.js';
917
+
918
+ const [home, recent] = await recapi.recommendLists({
919
+ lists: [{ placement: 'home', count: 4 }, { placement: RECENTLY_VIEWED, count: 4 }]
920
+ });
921
+ ```
922
+
823
923
  ### The ready row
824
924
 
825
925
  `row(slot, { placement, contextItemId, heading })` fills `slot` (an element
@@ -832,20 +932,84 @@ or a selector) with up to 4 cards, the shop rows' rules in one call:
832
932
  and `price` show when present. A number price takes the item's `currency`,
833
933
  else the page's `<meta property="product:price:currency">`. An item with
834
934
  `available: false` is skipped.
935
+ - A number `list_price` above a number `price` (the price before a sale)
936
+ shows struck through before it, in the same currency, after a hidden "Was"
937
+ for screen readers. It is your figure: recapi computes no reduction.
835
938
  - Each link carries its list's id, which the page it opens reads (see
836
939
  [Consent](#consent-and-eprivacy)).
940
+ - A card for a product the visitor opened earlier (`why: viewed_earlier`)
941
+ says "You looked at this", in the page's `lang` (English, French, German,
942
+ Spanish, Italian, Dutch or Portuguese, else English).
943
+ - A screen reader announces it as a named list of its products: the name is
944
+ `heading`, else a heading right above the slot, else the slot's
945
+ `aria-label`, else "Recommendations" in the page's `lang`. A second row of
946
+ the same name is a list only, not another landmark.
837
947
  - The row hides when no card can be drawn; the console names the missing
838
948
  keys. Under the `bought_together` placement, `heading` shows only over a
839
949
  product bought with this one, and the row stays away when recapi answers
840
950
  with popular items.
841
951
  - Its styles weigh nothing (`:where`), so any rule of yours restyles it
842
952
  (`.recapi-row ul`, `a`, `img`, `.recapi-heading`, `.recapi-name`,
843
- `.recapi-price`), and pass a `style-src 'self'` CSP.
953
+ `.recapi-price`, `.recapi-was`, `.recapi-seen`), and pass a `style-src 'self'` CSP. Your
954
+ rules for every list (`.content ul`) give it no margin, padding or bullets;
955
+ rules that name the row do. It tells them apart as it draws.
956
+ - A `RECENTLY_VIEWED` row is not asked for while the visitor has opened no
957
+ product, or only the one on screen, or bought what they opened: a browser
958
+ key's list reads no stored history, so it could hold no such product. It hides.
959
+ - A `RECENTLY_VIEWED` row with no context (a home page), back on screen by
960
+ Back or Forward, is drawn again, alone and without the other rows'
961
+ products, only if the visitor opened a product since.
844
962
 
845
963
  There are no other options: for another look, draw `recommend()`'s list.
846
964
  The file (`row.js`, and `cards.js` it shares with the shop rows) loads on
847
965
  the first call only.
848
966
 
967
+ ### The page's product
968
+
969
+ A site with no product ids of its own, or no way to print them in a
970
+ template, names none: `track('view')` (a level alone, options second) and
971
+ `row(slot)` without a `contextItemId` key take the page's product.
972
+
973
+ - Its id is its address on your site, path and query, as the markup names
974
+ it (JSON-LD, Open Graph), else as the browser shows it: `/shop/p/blue-mug`.
975
+ A visitor's click and campaign ids, a card's `?rec=` credit, the fragment
976
+ and one trailing slash are left out, and so are the keys shop software
977
+ adds for one visitor: a session (`PHPSESSID`, `XTCsid`…), a currency or
978
+ language switch (`SubmitCurrency`, `currency`, `lang`…). A variant in
979
+ the address goes when the markup names the product without it. The exact rule and its cases are in recapi's shared
980
+ vectors, `spec/page_product_vectors.json`.
981
+ - A page with no product markup sends no view, and its row has no context.
982
+ - A page the browser brings back with Back or Forward (its back/forward
983
+ cache) sends its product's view again, with no list's id; its rows keep
984
+ their cards.
985
+ - A site that moves between pages without reloading gets one view per
986
+ product, and the row drawn again for each, even if it calls them again on
987
+ each page.
988
+ - A site that takes code for all its pages only (Wix, Squarespace) has no
989
+ slot on its product pages: there, `row('#some-id')` adds
990
+ `<div id="some-id">` under the product: at the end of Wix Stores'
991
+ product section, else of `<main>`, else
992
+ before the first `<footer>` or `[role=contentinfo]`, else at the end of
993
+ `<body>`; a spot the footer covers, or above the product's name (the
994
+ page's `<h1>`), is skipped. The row takes the side margins of the
995
+ content around the product's name, where its container has none. A slot already on the page
996
+ wins; a page with no product gets none, and its console no line about
997
+ the slot; a move to another product takes the last one away.
998
+ Where it lands badly, `row(slot, { place: false })` turns it off: place
999
+ the slot.
1000
+ - On Wix the row waits at the page's end, then moves under the product
1001
+ once Wix has drawn it (React's hydration, 2 to 22 seconds): earlier, it
1002
+ made Wix draw the product again. Within a minute, or it stays. Once it
1003
+ has moved, nothing of ours watches the page.
1004
+ - The tag run again on each page (Wix's "load code on each new page") is
1005
+ one tag: one view per product, one row, even when a banner gives each
1006
+ copy its consent after its first calls. Each call goes out with the
1007
+ consent of the copy that made it; one with another `platform` sends its
1008
+ own calls.
1009
+ - An id you pass wins; `''` still sends nothing. Two limits: a renamed
1010
+ address is a new product, and a catalog sent later under your own ids is
1011
+ not matched to these yet.
1012
+
849
1013
  ### Errors and troubleshooting
850
1014
 
851
1015
  Every failure is a `RecapiError` with `code`, `status` and `message`. The
@@ -924,11 +1088,12 @@ latest stored state and writes the result back. If a write fails (quota
924
1088
  exceeded, Safari private mode), the SDK keeps working from memory for the
925
1089
  rest of the page.
926
1090
 
927
- **Server snapshot.** When a request has an empty history and a `user_id`,
928
- the server scores it with its stored history (unless the tenant turned the
929
- server-side history off in the dashboard settings). It returns that history only
930
- to secret-key callers, because the history is personal data. Browsers using
931
- a public key therefore get the snapshot through your backend and
1091
+ **Server snapshot.** When a secret-key request has an empty history and a
1092
+ `user_id`, the server scores it with its stored history (unless the tenant
1093
+ turned the server-side history off in the dashboard settings), and returns
1094
+ it. A public-key request is never scored on it, because the history is
1095
+ personal data ([why](https://recapi.io/docs/api#authentication)). Browsers using a
1096
+ public key therefore get the snapshot through your backend and
932
1097
  `identify(userId, { history })`. When a snapshot does arrive (Node with a
933
1098
  secret key), the SDK stores it only if it sent an empty history, so newer
934
1099
  local data is never overwritten. Events tracked while that request was in
@@ -1020,10 +1185,9 @@ so a batch already in flight when the user navigates away still arrives.
1020
1185
  follows the item id rule (1–256 bytes of UTF-8, no control characters);
1021
1186
  `identify()` throws `RecapiError('invalid_request')` otherwise.
1022
1187
  - `identify(userId)` alone does not bring the user's history to a new
1023
- device. The server scores a request with its stored history only when
1024
- the request has no history at all. That is true on a fresh device until
1025
- the first `track()`. After that, only the local history counts. To carry
1026
- the full history over, pass a server snapshot, as below.
1188
+ device: with a public key, a list comes from the local history only, and
1189
+ a fresh device gets a new visitor's list until the first `track()`. To
1190
+ carry the full history over, pass a server snapshot, as below.
1027
1191
  - `identify(userId, { history: snapshot })` merges a server snapshot into
1028
1192
  the local history. Your backend gets the snapshot with the secret key
1029
1193
  from `GET /v1/users/{id}/history`. Merging adds up the decayed scores
@@ -1082,6 +1246,9 @@ Events are still sent, without `anon_id`. Don't call `track()` if you
1082
1246
  need no network at all. Withdrawing consent deletes the stored data.
1083
1247
  Granting it merges the in-memory history into storage.
1084
1248
 
1249
+ The entry to paste into a cookie banner tool, and how to keep it from
1250
+ blocking the script: [Cookie banners](https://recapi.io/docs/concepts#cookie-banners).
1251
+
1085
1252
  ### Do Not Track
1086
1253
 
1087
1254
  When the browser sends Do Not Track (`navigator.doNotTrack === '1'`) or
@@ -1129,15 +1296,219 @@ key on a format change makes old data invisible.
1129
1296
 
1130
1297
  ## Size budget
1131
1298
 
1132
- Budget: **6 KB gzip** after minification. The sources ship unminified with
1133
- full JSDoc: 66 KB raw in five files, 21 KB as the API serves them (gzip -9),
1134
- and the browser caches them. With comments stripped and no
1135
- minification they are 9 KB gzip. A bundler's minifier should bring
1136
- that under the budget, but this has not been measured: the repo has no
1137
- minifier, to keep zero dev dependencies.
1299
+ What a first visit downloads before the library runs: each entry is one
1300
+ file, joined and gzipped as the API serves it (library 0.33.1). A test fails
1301
+ when an entry passes its budget (`go test ./internal/jssdk -run SizeBudget -v`
1302
+ in `server/` prints these):
1303
+
1304
+ | Entry | Bytes | Gzipped | Budget | Its files as they are |
1305
+ |---|--:|--:|--:|--:|
1306
+ | `index.js` (the pasted tag) | 41,811 | 16,843 | 18,000 | 6 files, 38,228 |
1307
+ | `woocommerce.js` | 51,482 | 20,315 | 20,500 | 9 files, 54,242 |
1308
+ | `shopify.js` | 54,207 | 21,363 | 21,500 | 9 files, 57,147 |
1309
+ | `magento.js` | 50,781 | 20,074 | 20,250 | 9 files, 53,874 |
1310
+
1311
+ `index.js` holds the row too, which it used to fetch at the first `row()`.
1312
+
1313
+ ### Reading what runs
1314
+
1315
+ The API joins each entry with esbuild when it starts: comments go, names
1316
+ shorten. The readable files stay in `src/`, in the npm package and at
1317
+ `/sdk/<version>/<file>` for every module but the four entries. The browser's
1318
+ developer tools read `<entry>.map`, served beside the entry: a console error
1319
+ points at the line of `src/` it came from.
1320
+
1321
+ `RECAPI_SDK_SERVED_DIR=/tmp/served go test ./internal/jssdk -run WriteServedFiles`
1322
+ in `server/` writes the files as served, for `scripts/e2e/chain.mjs /tmp/served`.
1323
+ `scripts/sdk-served.sh` runs this package's tests on them, as `make test` does.
1138
1324
 
1139
1325
  ## Changes
1140
1326
 
1327
+ - 2026-12-02: version 0.33.1. A product name too long for two lines ends
1328
+ with an ellipsis, so a card never grows past its held place. The Shopify
1329
+ box to paste holds the page's width from the first paint: paste it again
1330
+ to get it. On Wix, a product widget not laid out yet no
1331
+ longer lets an off-centre column set the row's margins.
1332
+
1333
+ - 2026-12-02: version 0.33.0. Rows on a product page's first screen
1334
+ hold their place in the printed page, before the script comes: the
1335
+ WooCommerce plugin prints its blank cards and bought together's, the
1336
+ Magento module from 0.4.43 its rows' (the script takes either hold over),
1337
+ and Shopify's box and the plain row's element hold it by style alone. A
1338
+ bought-together title that turns out untitled keeps its line.
1339
+
1340
+ - 2026-12-02: version 0.32.0. Magento: a home page with no recapi block
1341
+ gets Recently viewed at the end of its main content, hidden from a
1342
+ shopper who opened no product. Its cards take the width and gap of the
1343
+ product cards above it.
1344
+
1345
+ - 2026-12-02: version 0.31.0. Every row holds its real place while its
1346
+ list loads: blank cards in its own grid at the page's width, out of reach
1347
+ of screen readers, one block for each row the page will get, instead of a
1348
+ fixed 320 px. A product page no longer jumps when its rows arrive during a
1349
+ scroll. A failed first draw of Recently viewed asks again at the next Back.
1350
+
1351
+ - 2026-12-02: version 0.30.0. WooCommerce: without recapi's script the
1352
+ plugin's row shows the shop's own related products, which the script
1353
+ replaces with recapi's cards, or keeps when recapi has none. Shopify's
1354
+ quick start box, and the plugin's box with no related product to show,
1355
+ hold their place for 4 s only (a CSS animation), so they close by
1356
+ themselves when the script never comes; the script holds them from its
1357
+ start.
1358
+
1359
+ - 2026-12-01: version 0.29.5. WooCommerce: back on the front page with
1360
+ Back, the plugin's own Recently viewed slot shows the product just opened.
1361
+ Every Recently viewed row asks again at the next Back after a failed call.
1362
+
1363
+ - 2026-11-29: version 0.29.4. Shopify: a home page without
1364
+ `#recapi-recommendations` shows Recently viewed in a box of the snippet's
1365
+ own at the end of the main content, as WooCommerce's front page does.
1366
+
1367
+ - 2026-11-29: version 0.29.3. Shopify, WooCommerce, Magento and `row()`: a
1368
+ Recently viewed row is not asked for while the visitor has opened nothing
1369
+ unbought, so a first visit's home page makes no call for it (none at all
1370
+ for WooCommerce's own home slot).
1371
+
1372
+ - 2026-11-29: version 0.29.2. The site tag (`track('view')`, `row()`): a
1373
+ page the browser brings back with Back or Forward counts its product's
1374
+ view again, and a home page's `RECENTLY_VIEWED` row is drawn again if the
1375
+ visitor opened a product since. A row hidden for want of cards shows when
1376
+ drawn again with some.
1377
+
1378
+ - 2026-11-29: version 0.29.1. Shopify, WooCommerce and Magento: a page the
1379
+ browser brings back with Back or Forward (from its back/forward cache)
1380
+ counts its product's view again, and a home page redraws Recently viewed
1381
+ if the shopper opened a product since.
1382
+
1383
+ - 2026-11-29: version 0.29.0. WooCommerce: the front page shows Recently
1384
+ viewed above the footer with no shortcode, on classic and block themes,
1385
+ with a checkbox to turn it off. The plugin's screen follows the quick
1386
+ start's order (key, cookie consent, pages, past orders) in 94 words
1387
+ outside the consent choices, from 209. Other libraries' files are unchanged.
1388
+
1389
+ - 2026-11-29: version 0.28.3. On Wix, a row placed by itself takes the
1390
+ product's side margins on a phone where the product sits off-centre: it
1391
+ touched the screen's edges there. Once the row has moved under the
1392
+ product, the library stops watching the page's changes.
1393
+
1394
+ - 2026-11-28: version 0.28.2. WooCommerce: a refused secret key says where to
1395
+ make one (the Quickstart's step "Paste a secret key"), and the key's
1396
+ paragraph is shorter. The library's files are unchanged.
1397
+
1398
+ - 2026-11-28: version 0.28.1. A WooCommerce front page that is also a
1399
+ product page shows all three rows, each under its own title: before, Bought
1400
+ together's cards showed under "Recently viewed" and its list was dropped.
1401
+ Shopify takes each row by its placement too. WooCommerce's and Shopify's
1402
+ files grow by 0.1 KB as served (gzip -9).
1403
+
1404
+ - 2026-11-28: version 0.28.0. The API serves each entry as one compact file:
1405
+ a first visit fetches the library in one trip, at 37% of the weight
1406
+ (WooCommerce: 49,999 to 18,635 bytes gzipped). Exports and the files a
1407
+ bundler imports are unchanged.
1408
+
1409
+ - 2026-11-28: version 0.27.1. On Shopify, WooCommerce and Magento, the home
1410
+ page asks for `recently_viewed` in the same call as its first row and
1411
+ shows it under "Recently viewed" once the shopper has opened a product. The
1412
+ files a page loads grow by up to 1 KB as served (gzip -9), and the
1413
+ WooCommerce and Magento budgets rise by 1,000 bytes for the new row.
1414
+
1415
+ - 2026-11-28: version 0.27.0. `RECENTLY_VIEWED` and `BOUGHT_TOGETHER`
1416
+ name the built-in placements of a home page's and a product page's second
1417
+ row, for `recommendLists()` and `row()`. The files a page loads grow by
1418
+ 0.1 KB as served (gzip -9).
1419
+
1420
+ - 2026-11-28: version 0.26.1. On WooCommerce and Magento, an add to
1421
+ cart from a shop or category page counts when jQuery loads after the
1422
+ library, as a speed plugin that delays scripts until the visitor's first
1423
+ touch makes it do; before, none of those carts counted. The files a
1424
+ WooCommerce or Magento page loads grow by 0.2 KB as served (gzip -9).
1425
+
1426
+ - 2026-11-28: version 0.26.0. On Wix, a row placed by itself shows under
1427
+ the product, at the end of its product section, not below the footer,
1428
+ once Wix has drawn the product. The files a page loads grow
1429
+ by 1.3 KB as served (gzip -9).
1430
+
1431
+ - 2026-11-28: version 0.25.0. Each entry file (`index.js`,
1432
+ `woocommerce.js`, `shopify.js`, `magento.js`) imports every file it
1433
+ needs, so a first visit fetches them in two trips instead of three or
1434
+ four: about 0.2 s sooner at a phone's 165 ms a request. The files a
1435
+ page loads grow by 0.1 KB as served (gzip -9).
1436
+
1437
+ - 2026-11-28: version 0.24.0. A row placed by itself takes the side
1438
+ margins of the page's content. A product's id leaves out a visitor's
1439
+ session, currency and language keys. A page with no product logs
1440
+ nothing about the row's slot. A call handed between two clients with
1441
+ the same key goes out with the consent of the one that made it, and
1442
+ `destroy()` takes away the row it placed. The files a page loads grow by
1443
+ 2.2 KB as served (gzip -9).
1444
+
1445
+ - 2026-11-28: version 0.23.0. On a product page missing the row's
1446
+ `#id` slot, `row()` with no `contextItemId` adds it under the product
1447
+ ([The page's product](#the-pages-product)); `place: false` turns it
1448
+ off. A tag run again on each page, and a `row(element)` given a new
1449
+ element on each route, follow the page once. The files a page loads
1450
+ grow by 1.1 KB as served (gzip -9).
1451
+
1452
+ - 2026-11-28: version 0.22.0. A product page's words are also read from microdata, a `ProductGroup` and
1453
+ JSON-LD blocks that share the product's `@id`. On a site with no shop platform, a viewed page with no
1454
+ markup the library reads sends its address alone, so recapi's server can draw its card. The files a
1455
+ page loads grow by 0.9 KB as served (gzip -9).
1456
+ - 2026-11-27: version 0.21.0. `track('view')` and `row(slot)` with no
1457
+ product id take the page's product, by its address
1458
+ ([The page's product](#the-pages-product)), and follow a site that moves
1459
+ between pages without reloading. The quick start's tag asks for no id.
1460
+ Calls that pass an id, and the three shop plugins, are unchanged; a
1461
+ `row(slot)` with no `contextItemId` on a product page now has that
1462
+ product as its context, under its address. The
1463
+ files a page loads grow from 28.5 to 32.1 KB as served (gzip -9).
1464
+ - 2026-11-27: version 0.20.0. In a browser, a product's first view also sends the name and category
1465
+ its page prints for search engines, so a site that sent no catalog gets similar products by name
1466
+ (option `describePages`, on by default; the Shopify theme keeps its own). The files a page loads
1467
+ grow from 25.4 to 28.4 KB as served (gzip -9).
1468
+ - 2026-11-27: version 0.19.8. The Magento row draws a card's old price as the ready row does: from
1469
+ a number `list_price` in its metadata, or the one the store's card lookup sends (module 0.4.37),
1470
+ with its stylesheet for modules that print none.
1471
+ - 2026-11-27: version 0.19.7. On Shopify, a product on sale shows its compare-at price struck
1472
+ through before its price, from its metadata or Shopify's lookup, when every variant is reduced.
1473
+ - 2026-11-27: version 0.19.6. A card whose item carries a number `list_price` above its number
1474
+ `price` shows it struck through before the price ([the ready row](#the-ready-row)), on the
1475
+ ready row and the WooCommerce row; the WooCommerce plugin sends a sale's regular price as
1476
+ `list_price`.
1477
+ - 2026-11-26: version 0.19.5. The WooCommerce plugin's script tag, and module 0.4.36's on
1478
+ Magento, carry Cookiebot's `data-cookieconsent="ignore"` whenever recapi reads the shop's
1479
+ consent answer itself ([Cookie banners](https://recapi.io/docs/concepts#cookie-banners)).
1480
+ The library's files are unchanged.
1481
+ - 2026-11-26: version 0.19.4. The WooCommerce plugin shows the row of a `[recapi]` in a
1482
+ product's description: WooCommerce renders the description for its JSON first, which used
1483
+ the page's one row. The library's files are unchanged.
1484
+ - 2026-11-25: version 0.19.3. On a sold-out product's page the row says its
1485
+ products are in stock, and "Often bought together" is not drawn. With the
1486
+ plugin and module of this release (0.19.3, 0.4.35) the row also moves up
1487
+ beside the stock notice. Shopify needs the theme snippet pasted again.
1488
+ `recapi.row()` keeps its place, without bullets, on a site whose style sheet
1489
+ styles every list; rules that name the row still win. A list's margin or
1490
+ padding meant for the row must name its slot (`.recapi-row ul`, or the
1491
+ slot's id or class), not a box around it. A slot drawn again with a heading
1492
+ is named by it, and two rows of the same name are one landmark.
1493
+ - 2026-11-25: version 0.19.2. A screen reader announces every row as a named
1494
+ list of its products: the Shopify, WooCommerce and Magento cards are list
1495
+ items (`ul`, `li`), laid out as before, and each row is a region with its
1496
+ heading's name. No row draws an image for an empty picture. Shops already
1497
+ set up get it with nothing to update.
1498
+ - 2026-11-25: version 0.19.1. Magento: a card for a product without a picture
1499
+ has no image, where it had the open page's address as one (a broken image
1500
+ and a request). Modules already installed get it with nothing to update.
1501
+ - 2026-11-24: version 0.19.0. A row's card for a product the visitor opened
1502
+ earlier (`why: viewed_earlier`) says so, "You looked at this", and is the
1503
+ first card even when it comes with the top-up. `track()` takes
1504
+ `send: false`: the visitor's history learns what your server sends itself
1505
+ (an order). The WooCommerce and Magento order pages use it, with the
1506
+ plugin and module of this release (0.19.0, 0.4.33).
1507
+ - 2026-11-24: version 0.18.2. No visible change: the WooCommerce and Magento
1508
+ rows take the rules every row shares from `cards.js`, and the three shop
1509
+ rows what they share from `shops.js` ([What the shop modules
1510
+ share](#what-the-shop-modules-share)). Plugins and modules already
1511
+ installed get it with nothing to update.
1141
1512
  - 2026-11-24: version 0.18.1. No visible change: Shopify's row takes the
1142
1513
  rules it shares with `recapi.row()` from one file, `cards.js`.
1143
1514
  - 2026-11-24: version 0.18.0. `recapi.row(slot, { placement, contextItemId,
@@ -1307,8 +1678,8 @@ The same steps in real browsers (Chromium, Firefox, WebKit): see
1307
1678
  "Testing" in the repository's development guide.
1308
1679
 
1309
1680
  The API embeds `src/*.js` (module `recapi/sdkjs`, `embed.go`) and serves
1310
- them at `/sdk/<version>/`, where browsers cache every file but `index.js` for
1311
- a year. So a change to `src/` needs a new version: bump `version` in `package.json`,
1681
+ them at `/sdk/<version>/`, the entries joined ([Reading what runs](#reading-what-runs)),
1682
+ where browsers cache every file but the entries for a year. So a change to `src/` needs a new version: bump `version` in `package.json`,
1312
1683
  add the entry the failing Go test `TestSDKChangesNeedANewVersion` prints
1313
1684
  to `published.json` (the digest is `sha256sum src/*.js | sha256sum`, then
1314
1685
  each file's exports), and change the `/sdk/<version>/` paths in this