@recapi/client 0.18.0 → 0.33.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,14 +35,12 @@ 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.18.0/index.js';
39
-
40
- const ITEM_ID = ''; // this page's product id
38
+ import { createClient } from 'https://api.example.com/sdk/0.33.0/index.js';
41
39
 
42
40
  const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
43
41
  // From your cookie banner, once the visitor agrees: recapi.setConsent(true).
44
42
  // 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
43
+ recapi.track('view'); // this page's product, and the calls of the quick start below
46
44
  </script>
47
45
  ```
48
46
 
@@ -87,7 +85,9 @@ const recapi = createClient({
87
85
  });
88
86
 
89
87
  // 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.
88
+ // itemId is that page's own id: an empty one sends nothing. On a product
89
+ // page, the first view also sends the product's name (see describePages).
90
+ // No ids of your own? recapi.track('view') takes the page's product.
91
91
  recapi.track(itemId, 'view');
92
92
 
93
93
  // A row of 4 product cards in <div id="recommendations"></div>, drawn from
@@ -130,7 +130,7 @@ nothing to paste again. A file of its own rather than more exports of
130
130
  A theme whose footer takes no sections gets it before `</body>` in
131
131
  `layout/theme.liquid` instead, again after each update. Its Liquid is
132
132
  `product.handle`, `product.title`, `product.type`, `product.tags`,
133
- `customer.id` and `request.page_type`, which a section
133
+ `product.available`, `customer.id` and `request.page_type`, which a section
134
134
  reads as the layout does, and it stays far below the setting's 50 KB. It identifies a
135
135
  logged-in customer, tracks product views, sends each product page's title,
136
136
  type and tags to `POST /v1/shopify/products:seen` (once per product per
@@ -139,12 +139,16 @@ nothing to paste again. A file of its own rather than more exports of
139
139
  a page of 250 per product view while recapi's answer asks for one (once the
140
140
  browser is idle and after the row; recapi keeps the progress, so nothing is
141
141
  stored), and fills the
142
- `<div id="recapi-recommendations" style="min-height: 320px">&nbsp;</div>`
142
+ `<div id="recapi-recommendations"><style>#recapi-recommendations{container-type:inline-size}#recapi-recommendations::before{content:"";display:block;--c:4;--l:2;height:calc(var(--l)*((100cqw + 1rem)/var(--c) + .5rem + 3lh) + 2rem + 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
143
  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
144
+ cards it loads from Shopify's `/products/<handle>.js`. The box's style
145
+ holds a blank card's place in the row's own proportions from the first
146
+ paint and closes it after 4 s, so without the script (recapi down, a
147
+ blocker) it closes by itself; the script holds the place itself from its
148
+ start. The
149
+ `<style>` inside matters: Dawn and the themes built on it hide every empty
150
+ `div`, and a hidden box never comes near the screen; the snippet also puts
151
+ 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
152
  Shopify's own themes, it asks for them only once the div comes within
149
153
  400px of the screen (an `IntersectionObserver`, at once in a browser
150
154
  without one): each list is billed and counted as an impression, and a
@@ -163,12 +167,12 @@ nothing to paste again. A file of its own rather than more exports of
163
167
  a page costs one call (two with a top-up), billed as one recommendation
164
168
  each, a product page's second row included (below). Each row asks for its own placement: `product` on
165
169
  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
170
+ `section` elsewhere, so Home's "By row" and a lift test tell
167
171
  them apart; one not configured in the dashboard serves as `default`, with
168
172
  its settings and its running lift test. A shop that pasted an earlier
169
173
  snippet keeps it, with every row on `default` and 6 products asked for,
170
174
  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.
175
+ a list, and "By row" splits `default` into the rows above.
172
176
 
173
177
  From 0.11.0 a product page has a second row, under the first: what
174
178
  shoppers bought with the product on screen, placement `bought_together`,
@@ -181,6 +185,23 @@ nothing to paste again. A file of its own rather than more exports of
181
185
  any text of the shop's, `''` for no title, `false` for no second row.
182
186
  Pieces pasted before 0.11.0 get the row too, with the default title.
183
187
 
188
+ From 0.27.1 the home page (`pageType` `index`) has a second row too,
189
+ placement `recently_viewed`, in
190
+ the same call, in a `<div id="recapi-recently-viewed">` after the slot under
191
+ "Recently viewed" in the page's language. It shows only when its list holds
192
+ a product the shopper opened (`why: viewed_earlier`), and its cards carry no
193
+ "You looked at this" mark: the title says it.
194
+ From 0.29.4 a home page without the slot gets the row alone, in a
195
+ `<div id="recapi-home">` the snippet adds at the end of `main` (else right
196
+ before the section holding the snippet), hidden while it has no card. The
197
+ theme editor gets none.
198
+
199
+ From 0.19.3, when `product.available` is `false`, there is no second row and
200
+ the first opens with an `<h2 class="recapi-heading">` in the slot, "Other
201
+ products in stock" in the page's language. A heading the shop wrote right
202
+ above the slot stays the row's title instead. Pieces pasted before
203
+ 0.19.3 don't say whether the product is sold out, and change nothing.
204
+
184
205
  Each row shows or hides on its own: an empty first row hides its slot and
185
206
  leaves the second; a short row is topped up in the one more call, with
186
207
  only the short rows, without any product either row listed. A refused top-up
@@ -281,7 +302,7 @@ may be added, never renamed or dropped, as shops never paste again.
281
302
 
282
303
  | Call | Options |
283
304
  |---|---|
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. |
305
+ | `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
306
  | `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
307
 
287
308
  `test/shopify.test.js` runs both pieces with `src/shopify.js` as the quick
@@ -294,6 +315,18 @@ fixture, and a change to the served code must keep every older piece
294
315
  working. The quick start fills in the current version, your address and your
295
316
  project (`jssdk.Shopify`).
296
317
 
318
+ #### What the shop modules share
319
+
320
+ `shopify.js`, `woocommerce.js` and `magento.js` keep what only their
321
+ platform gives: the page's data, the store's own cards for items without
322
+ metadata, the currency, the consent, the cart. The rules every row shares
323
+ (lazy ask, the card, the list and its name, the link with the list's id,
324
+ hiding, the title, card styles) come from `cards.js`, which [the ready row](#the-ready-row) uses
325
+ too; what only the shop rows share (the view a card's link brings, both
326
+ rows in one call with their gaps topped up, the order cookie) from
327
+ `shops.js`. Each platform's rows are pinned to the byte, per published piece,
328
+ plugin or module, in `test/fixtures/<platform>/<version>/rows.txt`.
329
+
297
330
  Both files name themselves (`platform: 'shopify/<version>'`, sent as
298
331
  `?platform=` on every call), so recapi words its setup hints for Shopify.
299
332
 
@@ -387,12 +420,40 @@ as one, the first row first so no product is on both. The script adds the
387
420
  row as `<div id="recapi-bought-together">` (with its heading) right after
388
421
  the first row's div once it has cards: the printed page doesn't change,
389
422
  and a row with nothing to show leaves nothing. One row empty never hides
390
- the other. *WooCommerce → recapi* turns it off ("Your product pages",
423
+ the other. *WooCommerce → recapi* turns it off ("Your pages",
391
424
  option `recapi_bought_together`); the cart and shortcode rows never have it.
425
+ From 0.27.1 the front page (WordPress's `home` body class) asks for a second
426
+ row instead, `recently_viewed`, drawn as `<div id="recapi-recently-viewed">`
427
+ after the first by the same rule as Shopify's (above). A front page that is a
428
+ product page has all three rows, Recently viewed last (0.28.1).
429
+ From 0.29.0 a front page with no row of the merchant's gets the plugin's own
430
+ slot above the footer (`get_footer` on classic themes, before the footer
431
+ template part on block themes), with placement `recently_viewed`: it holds
432
+ that row alone under its title, or hides while the visitor opened nothing.
433
+ *WooCommerce → recapi* turns it off (option `recapi_home_recently_viewed`).
392
434
  From 0.15.1 the heading is added only when one of the cards drawn has
393
435
  `why: bought_together`; otherwise the cards show without it, a `margin-top`
394
436
  of the grid's gap under the first row.
395
437
 
438
+ On the page of a product WooCommerce calls out of stock (`is_in_stock()`; one
439
+ on back-order isn't), the plugin from 0.19.3 prints no second row and the
440
+ first right under the notice, from `woocommerce_<type>_add_to_cart` at
441
+ priority 31. It is titled "Other products in stock" in the site's language,
442
+ through the `woocommerce_product_related_products_heading` filter. A theme
443
+ that doesn't run that hook keeps the row's usual place. A `[recapi]` in the
444
+ product's descriptions or in a block theme's template keeps its own place and
445
+ title; one a page builder prints after the notice, or a pasted
446
+ `#recapi-recommendations` box there, gives way to the row at the notice.
447
+
448
+ A block theme that dropped the Related Products block still shows the row on
449
+ every product, after Product Details (WooCommerce's compatibility layer runs
450
+ the classic hook there). One without either block shows it on sold-out
451
+ products only. This line takes it off both, from a snippet or a theme:
452
+
453
+ ```php
454
+ add_action('template_redirect', fn () => remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20), 9);
455
+ ```
456
+
396
457
  The widget fills it like the Shopify snippet's, once it nears the screen,
397
458
  asking for the 4 products it shows (recapi counts every product of a list
398
459
  as shown, so a spare would get an impression and could be credited a view it
@@ -458,8 +519,8 @@ ran, how many products it sent and why any were refused. Every item is
458
519
  complete: `active` only while the product is published, not hidden from the
459
520
  catalog, purchasable and in stock (the Store API cards' rule), its category
460
521
  names as `tags` (not "Uncategorized"), its creation date as `published_at`,
461
- and `name`, `url`, `picture` (the `woocommerce_thumbnail` size) and `price`
462
- (as the shop displays it, in its currency) as `metadata`, shrunk below
522
+ and `name`, `url`, `picture` (the `woocommerce_thumbnail` size), `price`
523
+ (as the shop displays it, in its currency) and, on sale, `list_price` as `metadata`, shrunk below
463
524
  2,048 bytes as the Magento module does (picture first, then the name). The
464
525
  row then draws every card from it, with no Store API call. Only items that
465
526
  changed are billed. The plugin uses WordPress's HTTP API rather than the PHP
@@ -489,7 +550,7 @@ calls `User-Agent: recapi-woocommerce/<version>`.
489
550
 
490
551
  `scripts/e2e_woocommerce.sh` (CI job `woocommerce`) runs the plugin on a
491
552
  real, throwaway shop: WordPress and WooCommerce in Docker at pinned
492
- versions, twice: the newest (WordPress 7.1.4, WooCommerce 11.3.0, PHP 8.5)
553
+ versions, twice: the newest (WordPress 7.1.5, WooCommerce 11.3.1, PHP 8.5)
493
554
  and the oldest the plugin's header declares (WordPress 6.3, WooCommerce 8.3,
494
555
  PHP 7.4), the plugin taken from the quick start of a new recapi shop with
495
556
  its public key pasted, then a guest's browser (Playwright) on a product
@@ -554,6 +615,13 @@ together", is printed hidden and empty; from 0.15.1 the script removes that
554
615
  block's `.block-title` when none of the cards drawn has
555
616
  `why: bought_together`, so its cards read as more of the first row.
556
617
 
618
+ From module 0.4.35, a product Magento calls not salable (`isSalable()`; one on
619
+ back-order is) has no second row, and its first moves up: under the price and
620
+ the stock notice on Luma and its children, to the end of the product's box on
621
+ Hyvä, the layout's place on a theme with neither. A row the theme moved out
622
+ of `content.aside` keeps its place. Its title is "Other products
623
+ in stock" in the store view's language, unless the layout's `heading` names it.
624
+
557
625
  #### The served storefront code
558
626
 
559
627
  From module 0.4.25 (library 0.13.0) the module's template holds only what
@@ -575,7 +643,8 @@ never renamed or dropped, as stores keep the module they installed.
575
643
 
576
644
  The storefront code of every module version is kept in
577
645
  `test/fixtures/magento/<version>/` (`Block/Script.php` and the template;
578
- 0.4.24: the last one holding its own page code), and
646
+ 0.4.24: the last one holding its own page code; 0.4.33: also the row's
647
+ template, the last one without the list, for `scripts/e2e/rows.test.js`), and
579
648
  `test/magento_published.test.js` runs every case of `test/magento.test.js`
580
649
  through each against the current `src/`: a change to that code needs a new
581
650
  fixture, and a change to the served code must keep every older module working.
@@ -737,13 +806,14 @@ for (const item of items) {
737
806
  | `timeoutMs` | `5000` | per-request timeout; `recommend()` waits 1.5 s at most |
738
807
  | `historyConfig` | spec defaults | `{ halfLifeSeconds, topK, recentSize }`; must match the server |
739
808
  | `consent` | `false` | storage consent: `false` stores nothing until `setConsent(true)`, see [Consent](#consent-and-eprivacy) |
809
+ | `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 |
740
810
  | `respectDoNotTrack` | `true` | when DNT or Global Privacy Control is on: store nothing, send no events, see [Do Not Track](#do-not-track) |
741
811
  | `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 |
742
812
  | `now`, `fetch`, `sleep` | `Date.now`, global `fetch`, `setTimeout` | for tests |
743
813
 
744
814
  ### Client methods
745
815
 
746
- - **`track(itemId, level, { recommendationId?, value?, currency? })`**: `level` is any integer
816
+ - **`track(itemId, level, { recommendationId?, value?, currency?, send? })`**: `level` is any integer
747
817
  0–10 of the [recommended scale](https://recapi.io/docs/api#interaction-levels) (3
748
818
  opened, 5 strong interest, 10 the action that matters most), or one of its
749
819
  shop names `'view'`, `'cart'` and `'purchase'` (3, 5 and 10). `'reject'`
@@ -758,7 +828,10 @@ for (const item of items) {
758
828
  level. A purchase may carry `{ value, currency }` (what the buyer paid for
759
829
  the line, and its ISO 4217 code such as `'EUR'`), kept for the sales figure
760
830
  of a lift test; a negative value, or a currency without a value or not of
761
- three letters, throws the same error. An item id follows the API's rules, 1–256 bytes of UTF-8
831
+ three letters, throws the same error. `send: false` only records the
832
+ event in the visitor's history: use it on the order's page when your server
833
+ sends the purchases, so a list doesn't start with a product just bought.
834
+ An item id follows the API's rules, 1–256 bytes of UTF-8
762
835
  (128 characters of Cyrillic or accented Latin, 85 of CJK) without
763
836
  control characters; any other drops the event and reports it instead of
764
837
  throwing, as a visitor's URL can carry one (see [Fallback](#fallback)). A stored history entry whose id breaks the rule,
@@ -778,6 +851,8 @@ for (const item of items) {
778
851
  one call, see [below](#several-rows-in-one-call).
779
852
  - **`row(slot, { placement, contextItemId, heading })`**: a ready row, see
780
853
  [The ready row](#the-ready-row).
854
+ - **`track(level, options)`** and `row(slot)` with no `contextItemId` key:
855
+ the page's product, see [The page's product](#the-pages-product).
781
856
  - **`popular({ tagsAny, tagsAll, count })`** resolves to `{ items: [{ itemId, score, why, metadata }] }`.
782
857
  A public key goes in `?key=`, so the response can be cached by a CDN.
783
858
  [How the key is sent](#how-the-key-is-sent) gives the reason for the rest.
@@ -813,6 +888,19 @@ const [similar, more] = await recapi.recommendLists({
813
888
  });
814
889
  ```
815
890
 
891
+ The home page's second row, the products the visitor opened and has not
892
+ bought, is the built-in placement `RECENTLY_VIEWED`: ask it after the first
893
+ row, with nothing to set in the dashboard (`BOUGHT_TOGETHER` is the product
894
+ page's second row).
895
+
896
+ ```js
897
+ import { RECENTLY_VIEWED } from 'https://api.example.com/sdk/0.33.0/index.js';
898
+
899
+ const [home, recent] = await recapi.recommendLists({
900
+ lists: [{ placement: 'home', count: 4 }, { placement: RECENTLY_VIEWED, count: 4 }]
901
+ });
902
+ ```
903
+
816
904
  ### The ready row
817
905
 
818
906
  `row(slot, { placement, contextItemId, heading })` fills `slot` (an element
@@ -825,18 +913,83 @@ or a selector) with up to 4 cards, the shop rows' rules in one call:
825
913
  and `price` show when present. A number price takes the item's `currency`,
826
914
  else the page's `<meta property="product:price:currency">`. An item with
827
915
  `available: false` is skipped.
916
+ - A number `list_price` above a number `price` (the price before a sale)
917
+ shows struck through before it, in the same currency, after a hidden "Was"
918
+ for screen readers. It is your figure: recapi computes no reduction.
828
919
  - Each link carries its list's id, which the page it opens reads (see
829
920
  [Consent](#consent-and-eprivacy)).
921
+ - A card for a product the visitor opened earlier (`why: viewed_earlier`)
922
+ says "You looked at this", in the page's `lang` (English, French, German,
923
+ Spanish, Italian, Dutch or Portuguese, else English).
924
+ - A screen reader announces it as a named list of its products: the name is
925
+ `heading`, else a heading right above the slot, else the slot's
926
+ `aria-label`, else "Recommendations" in the page's `lang`. A second row of
927
+ the same name is a list only, not another landmark.
830
928
  - The row hides when no card can be drawn; the console names the missing
831
929
  keys. Under the `bought_together` placement, `heading` shows only over a
832
930
  product bought with this one, and the row stays away when recapi answers
833
931
  with popular items.
834
932
  - Its styles weigh nothing (`:where`), so any rule of yours restyles it
835
933
  (`.recapi-row ul`, `a`, `img`, `.recapi-heading`, `.recapi-name`,
836
- `.recapi-price`), and pass a `style-src 'self'` CSP.
934
+ `.recapi-price`, `.recapi-was`, `.recapi-seen`), and pass a `style-src 'self'` CSP. Your
935
+ rules for every list (`.content ul`) give it no margin, padding or bullets;
936
+ rules that name the row do. It tells them apart as it draws.
937
+ - A `RECENTLY_VIEWED` row is not asked for while the visitor has opened no
938
+ product, or only the one on screen, or bought what they opened: a browser
939
+ key's list reads no stored history, so it could hold no such product. It hides.
940
+ - A `RECENTLY_VIEWED` row with no context (a home page), back on screen by
941
+ Back or Forward, is drawn again, alone and without the other rows'
942
+ products, only if the visitor opened a product since.
837
943
 
838
944
  There are no other options: for another look, draw `recommend()`'s list.
839
- The file (`row.js`) loads on the first call only.
945
+ The file (`row.js`, and `cards.js` it shares with the shop rows) loads on
946
+ the first call only.
947
+
948
+ ### The page's product
949
+
950
+ A site with no product ids of its own, or no way to print them in a
951
+ template, names none: `track('view')` (a level alone, options second) and
952
+ `row(slot)` without a `contextItemId` key take the page's product.
953
+
954
+ - Its id is its address on your site, path and query, as the markup names
955
+ it (JSON-LD, Open Graph), else as the browser shows it: `/shop/p/blue-mug`.
956
+ A visitor's click and campaign ids, a card's `?rec=` credit, the fragment
957
+ and one trailing slash are left out, and so are the keys shop software
958
+ adds for one visitor: a session (`PHPSESSID`, `XTCsid`…), a currency or
959
+ language switch (`SubmitCurrency`, `currency`, `lang`…). A variant in
960
+ the address goes when the markup names the product without it. The exact rule and its cases are in recapi's shared
961
+ vectors, `spec/page_product_vectors.json`.
962
+ - A page with no product markup sends no view, and its row has no context.
963
+ - A page the browser brings back with Back or Forward (its back/forward
964
+ cache) sends its product's view again, with no list's id; its rows keep
965
+ their cards.
966
+ - A site that moves between pages without reloading gets one view per
967
+ product, and the row drawn again for each, even if it calls them again on
968
+ each page.
969
+ - A site that takes code for all its pages only (Wix, Squarespace) has no
970
+ slot on its product pages: there, `row('#some-id')` adds
971
+ `<div id="some-id">` under the product: at the end of Wix Stores'
972
+ product section, else of `<main>`, else
973
+ before the first `<footer>` or `[role=contentinfo]`, else at the end of
974
+ `<body>`; a spot the footer covers, or above the product's name (the
975
+ page's `<h1>`), is skipped. The row takes the side margins of the
976
+ content around the product's name, where its container has none. A slot already on the page
977
+ wins; a page with no product gets none, and its console no line about
978
+ the slot; a move to another product takes the last one away.
979
+ Where it lands badly, `row(slot, { place: false })` turns it off: place
980
+ the slot.
981
+ - On Wix the row waits at the page's end, then moves under the product
982
+ once Wix has drawn it (React's hydration, 2 to 22 seconds): earlier, it
983
+ made Wix draw the product again. Within a minute, or it stays. Once it
984
+ has moved, nothing of ours watches the page.
985
+ - The tag run again on each page (Wix's "load code on each new page") is
986
+ one tag: one view per product, one row, even when a banner gives each
987
+ copy its consent after its first calls. Each call goes out with the
988
+ consent of the copy that made it; one with another `platform` sends its
989
+ own calls.
990
+ - An id you pass wins; `''` still sends nothing. Two limits: a renamed
991
+ address is a new product, and a catalog sent later under your own ids is
992
+ not matched to these yet.
840
993
 
841
994
  ### Errors and troubleshooting
842
995
 
@@ -916,11 +1069,12 @@ latest stored state and writes the result back. If a write fails (quota
916
1069
  exceeded, Safari private mode), the SDK keeps working from memory for the
917
1070
  rest of the page.
918
1071
 
919
- **Server snapshot.** When a request has an empty history and a `user_id`,
920
- the server scores it with its stored history (unless the tenant turned the
921
- server-side history off in the dashboard settings). It returns that history only
922
- to secret-key callers, because the history is personal data. Browsers using
923
- a public key therefore get the snapshot through your backend and
1072
+ **Server snapshot.** When a secret-key request has an empty history and a
1073
+ `user_id`, the server scores it with its stored history (unless the tenant
1074
+ turned the server-side history off in the dashboard settings), and returns
1075
+ it. A public-key request is never scored on it, because the history is
1076
+ personal data ([why](https://recapi.io/docs/api#authentication)). Browsers using a
1077
+ public key therefore get the snapshot through your backend and
924
1078
  `identify(userId, { history })`. When a snapshot does arrive (Node with a
925
1079
  secret key), the SDK stores it only if it sent an empty history, so newer
926
1080
  local data is never overwritten. Events tracked while that request was in
@@ -1012,10 +1166,9 @@ so a batch already in flight when the user navigates away still arrives.
1012
1166
  follows the item id rule (1–256 bytes of UTF-8, no control characters);
1013
1167
  `identify()` throws `RecapiError('invalid_request')` otherwise.
1014
1168
  - `identify(userId)` alone does not bring the user's history to a new
1015
- device. The server scores a request with its stored history only when
1016
- the request has no history at all. That is true on a fresh device until
1017
- the first `track()`. After that, only the local history counts. To carry
1018
- the full history over, pass a server snapshot, as below.
1169
+ device: with a public key, a list comes from the local history only, and
1170
+ a fresh device gets a new visitor's list until the first `track()`. To
1171
+ carry the full history over, pass a server snapshot, as below.
1019
1172
  - `identify(userId, { history: snapshot })` merges a server snapshot into
1020
1173
  the local history. Your backend gets the snapshot with the secret key
1021
1174
  from `GET /v1/users/{id}/history`. Merging adds up the decayed scores
@@ -1074,6 +1227,9 @@ Events are still sent, without `anon_id`. Don't call `track()` if you
1074
1227
  need no network at all. Withdrawing consent deletes the stored data.
1075
1228
  Granting it merges the in-memory history into storage.
1076
1229
 
1230
+ The entry to paste into a cookie banner tool, and how to keep it from
1231
+ blocking the script: [Cookie banners](https://recapi.io/docs/concepts#cookie-banners).
1232
+
1077
1233
  ### Do Not Track
1078
1234
 
1079
1235
  When the browser sends Do Not Track (`navigator.doNotTrack === '1'`) or
@@ -1121,15 +1277,215 @@ key on a format change makes old data invisible.
1121
1277
 
1122
1278
  ## Size budget
1123
1279
 
1124
- Budget: **6 KB gzip** after minification. The sources ship unminified with
1125
- full JSDoc: 66 KB raw in five files, 21 KB as the API serves them (gzip -9),
1126
- and the browser caches them. With comments stripped and no
1127
- minification they are 9 KB gzip. A bundler's minifier should bring
1128
- that under the budget, but this has not been measured: the repo has no
1129
- minifier, to keep zero dev dependencies.
1280
+ What a first visit downloads before the library runs: each entry is one
1281
+ file, joined and gzipped as the API serves it (library 0.33.0). A test fails
1282
+ when an entry passes its budget (`go test ./internal/jssdk -run SizeBudget -v`
1283
+ in `server/` prints these):
1284
+
1285
+ | Entry | Bytes | Gzipped | Budget | Its files as they are |
1286
+ |---|--:|--:|--:|--:|
1287
+ | `index.js` (the pasted tag) | 41,723 | 16,802 | 18,000 | 6 files, 38,197 |
1288
+ | `woocommerce.js` | 51,394 | 20,274 | 20,500 | 9 files, 54,138 |
1289
+ | `shopify.js` | 54,119 | 21,323 | 21,500 | 9 files, 57,043 |
1290
+ | `magento.js` | 50,693 | 20,033 | 20,250 | 9 files, 53,770 |
1291
+
1292
+ `index.js` holds the row too, which it used to fetch at the first `row()`.
1293
+
1294
+ ### Reading what runs
1295
+
1296
+ The API joins each entry with esbuild when it starts: comments go, names
1297
+ shorten. The readable files stay in `src/`, in the npm package and at
1298
+ `/sdk/<version>/<file>` for every module but the four entries. The browser's
1299
+ developer tools read `<entry>.map`, served beside the entry: a console error
1300
+ points at the line of `src/` it came from.
1301
+
1302
+ `RECAPI_SDK_SERVED_DIR=/tmp/served go test ./internal/jssdk -run WriteServedFiles`
1303
+ in `server/` writes the files as served, for `scripts/e2e/chain.mjs /tmp/served`.
1304
+ `scripts/sdk-served.sh` runs this package's tests on them, as `make test` does.
1130
1305
 
1131
1306
  ## Changes
1132
1307
 
1308
+ - 2026-12-02: version 0.33.0. Rows on a product page's first screen
1309
+ hold their place in the printed page, before the script comes: the
1310
+ WooCommerce plugin prints its blank cards and bought together's, the
1311
+ Magento module from 0.4.43 its rows' (the script takes either hold over),
1312
+ and Shopify's box and the plain row's element hold it by style alone. A
1313
+ bought-together title that turns out untitled keeps its line.
1314
+
1315
+ - 2026-12-02: version 0.32.0. Magento: a home page with no recapi block
1316
+ gets Recently viewed at the end of its main content, hidden from a
1317
+ shopper who opened no product. Its cards take the width and gap of the
1318
+ product cards above it.
1319
+
1320
+ - 2026-12-02: version 0.31.0. Every row holds its real place while its
1321
+ list loads: blank cards in its own grid at the page's width, out of reach
1322
+ of screen readers, one block for each row the page will get, instead of a
1323
+ fixed 320 px. A product page no longer jumps when its rows arrive during a
1324
+ scroll. A failed first draw of Recently viewed asks again at the next Back.
1325
+
1326
+ - 2026-12-02: version 0.30.0. WooCommerce: without recapi's script the
1327
+ plugin's row shows the shop's own related products, which the script
1328
+ replaces with recapi's cards, or keeps when recapi has none. Shopify's
1329
+ quick start box, and the plugin's box with no related product to show,
1330
+ hold their place for 4 s only (a CSS animation), so they close by
1331
+ themselves when the script never comes; the script holds them from its
1332
+ start.
1333
+
1334
+ - 2026-12-01: version 0.29.5. WooCommerce: back on the front page with
1335
+ Back, the plugin's own Recently viewed slot shows the product just opened.
1336
+ Every Recently viewed row asks again at the next Back after a failed call.
1337
+
1338
+ - 2026-11-29: version 0.29.4. Shopify: a home page without
1339
+ `#recapi-recommendations` shows Recently viewed in a box of the snippet's
1340
+ own at the end of the main content, as WooCommerce's front page does.
1341
+
1342
+ - 2026-11-29: version 0.29.3. Shopify, WooCommerce, Magento and `row()`: a
1343
+ Recently viewed row is not asked for while the visitor has opened nothing
1344
+ unbought, so a first visit's home page makes no call for it (none at all
1345
+ for WooCommerce's own home slot).
1346
+
1347
+ - 2026-11-29: version 0.29.2. The site tag (`track('view')`, `row()`): a
1348
+ page the browser brings back with Back or Forward counts its product's
1349
+ view again, and a home page's `RECENTLY_VIEWED` row is drawn again if the
1350
+ visitor opened a product since. A row hidden for want of cards shows when
1351
+ drawn again with some.
1352
+
1353
+ - 2026-11-29: version 0.29.1. Shopify, WooCommerce and Magento: a page the
1354
+ browser brings back with Back or Forward (from its back/forward cache)
1355
+ counts its product's view again, and a home page redraws Recently viewed
1356
+ if the shopper opened a product since.
1357
+
1358
+ - 2026-11-29: version 0.29.0. WooCommerce: the front page shows Recently
1359
+ viewed above the footer with no shortcode, on classic and block themes,
1360
+ with a checkbox to turn it off. The plugin's screen follows the quick
1361
+ start's order (key, cookie consent, pages, past orders) in 94 words
1362
+ outside the consent choices, from 209. Other libraries' files are unchanged.
1363
+
1364
+ - 2026-11-29: version 0.28.3. On Wix, a row placed by itself takes the
1365
+ product's side margins on a phone where the product sits off-centre: it
1366
+ touched the screen's edges there. Once the row has moved under the
1367
+ product, the library stops watching the page's changes.
1368
+
1369
+ - 2026-11-28: version 0.28.2. WooCommerce: a refused secret key says where to
1370
+ make one (the Quickstart's step "Paste a secret key"), and the key's
1371
+ paragraph is shorter. The library's files are unchanged.
1372
+
1373
+ - 2026-11-28: version 0.28.1. A WooCommerce front page that is also a
1374
+ product page shows all three rows, each under its own title: before, Bought
1375
+ together's cards showed under "Recently viewed" and its list was dropped.
1376
+ Shopify takes each row by its placement too. WooCommerce's and Shopify's
1377
+ files grow by 0.1 KB as served (gzip -9).
1378
+
1379
+ - 2026-11-28: version 0.28.0. The API serves each entry as one compact file:
1380
+ a first visit fetches the library in one trip, at 37% of the weight
1381
+ (WooCommerce: 49,999 to 18,635 bytes gzipped). Exports and the files a
1382
+ bundler imports are unchanged.
1383
+
1384
+ - 2026-11-28: version 0.27.1. On Shopify, WooCommerce and Magento, the home
1385
+ page asks for `recently_viewed` in the same call as its first row and
1386
+ shows it under "Recently viewed" once the shopper has opened a product. The
1387
+ files a page loads grow by up to 1 KB as served (gzip -9), and the
1388
+ WooCommerce and Magento budgets rise by 1,000 bytes for the new row.
1389
+
1390
+ - 2026-11-28: version 0.27.0. `RECENTLY_VIEWED` and `BOUGHT_TOGETHER`
1391
+ name the built-in placements of a home page's and a product page's second
1392
+ row, for `recommendLists()` and `row()`. The files a page loads grow by
1393
+ 0.1 KB as served (gzip -9).
1394
+
1395
+ - 2026-11-28: version 0.26.1. On WooCommerce and Magento, an add to
1396
+ cart from a shop or category page counts when jQuery loads after the
1397
+ library, as a speed plugin that delays scripts until the visitor's first
1398
+ touch makes it do; before, none of those carts counted. The files a
1399
+ WooCommerce or Magento page loads grow by 0.2 KB as served (gzip -9).
1400
+
1401
+ - 2026-11-28: version 0.26.0. On Wix, a row placed by itself shows under
1402
+ the product, at the end of its product section, not below the footer,
1403
+ once Wix has drawn the product. The files a page loads grow
1404
+ by 1.3 KB as served (gzip -9).
1405
+
1406
+ - 2026-11-28: version 0.25.0. Each entry file (`index.js`,
1407
+ `woocommerce.js`, `shopify.js`, `magento.js`) imports every file it
1408
+ needs, so a first visit fetches them in two trips instead of three or
1409
+ four: about 0.2 s sooner at a phone's 165 ms a request. The files a
1410
+ page loads grow by 0.1 KB as served (gzip -9).
1411
+
1412
+ - 2026-11-28: version 0.24.0. A row placed by itself takes the side
1413
+ margins of the page's content. A product's id leaves out a visitor's
1414
+ session, currency and language keys. A page with no product logs
1415
+ nothing about the row's slot. A call handed between two clients with
1416
+ the same key goes out with the consent of the one that made it, and
1417
+ `destroy()` takes away the row it placed. The files a page loads grow by
1418
+ 2.2 KB as served (gzip -9).
1419
+
1420
+ - 2026-11-28: version 0.23.0. On a product page missing the row's
1421
+ `#id` slot, `row()` with no `contextItemId` adds it under the product
1422
+ ([The page's product](#the-pages-product)); `place: false` turns it
1423
+ off. A tag run again on each page, and a `row(element)` given a new
1424
+ element on each route, follow the page once. The files a page loads
1425
+ grow by 1.1 KB as served (gzip -9).
1426
+
1427
+ - 2026-11-28: version 0.22.0. A product page's words are also read from microdata, a `ProductGroup` and
1428
+ JSON-LD blocks that share the product's `@id`. On a site with no shop platform, a viewed page with no
1429
+ markup the library reads sends its address alone, so recapi's server can draw its card. The files a
1430
+ page loads grow by 0.9 KB as served (gzip -9).
1431
+ - 2026-11-27: version 0.21.0. `track('view')` and `row(slot)` with no
1432
+ product id take the page's product, by its address
1433
+ ([The page's product](#the-pages-product)), and follow a site that moves
1434
+ between pages without reloading. The quick start's tag asks for no id.
1435
+ Calls that pass an id, and the three shop plugins, are unchanged; a
1436
+ `row(slot)` with no `contextItemId` on a product page now has that
1437
+ product as its context, under its address. The
1438
+ files a page loads grow from 28.5 to 32.1 KB as served (gzip -9).
1439
+ - 2026-11-27: version 0.20.0. In a browser, a product's first view also sends the name and category
1440
+ its page prints for search engines, so a site that sent no catalog gets similar products by name
1441
+ (option `describePages`, on by default; the Shopify theme keeps its own). The files a page loads
1442
+ grow from 25.4 to 28.4 KB as served (gzip -9).
1443
+ - 2026-11-27: version 0.19.8. The Magento row draws a card's old price as the ready row does: from
1444
+ a number `list_price` in its metadata, or the one the store's card lookup sends (module 0.4.37),
1445
+ with its stylesheet for modules that print none.
1446
+ - 2026-11-27: version 0.19.7. On Shopify, a product on sale shows its compare-at price struck
1447
+ through before its price, from its metadata or Shopify's lookup, when every variant is reduced.
1448
+ - 2026-11-27: version 0.19.6. A card whose item carries a number `list_price` above its number
1449
+ `price` shows it struck through before the price ([the ready row](#the-ready-row)), on the
1450
+ ready row and the WooCommerce row; the WooCommerce plugin sends a sale's regular price as
1451
+ `list_price`.
1452
+ - 2026-11-26: version 0.19.5. The WooCommerce plugin's script tag, and module 0.4.36's on
1453
+ Magento, carry Cookiebot's `data-cookieconsent="ignore"` whenever recapi reads the shop's
1454
+ consent answer itself ([Cookie banners](https://recapi.io/docs/concepts#cookie-banners)).
1455
+ The library's files are unchanged.
1456
+ - 2026-11-26: version 0.19.4. The WooCommerce plugin shows the row of a `[recapi]` in a
1457
+ product's description: WooCommerce renders the description for its JSON first, which used
1458
+ the page's one row. The library's files are unchanged.
1459
+ - 2026-11-25: version 0.19.3. On a sold-out product's page the row says its
1460
+ products are in stock, and "Often bought together" is not drawn. With the
1461
+ plugin and module of this release (0.19.3, 0.4.35) the row also moves up
1462
+ beside the stock notice. Shopify needs the theme snippet pasted again.
1463
+ `recapi.row()` keeps its place, without bullets, on a site whose style sheet
1464
+ styles every list; rules that name the row still win. A list's margin or
1465
+ padding meant for the row must name its slot (`.recapi-row ul`, or the
1466
+ slot's id or class), not a box around it. A slot drawn again with a heading
1467
+ is named by it, and two rows of the same name are one landmark.
1468
+ - 2026-11-25: version 0.19.2. A screen reader announces every row as a named
1469
+ list of its products: the Shopify, WooCommerce and Magento cards are list
1470
+ items (`ul`, `li`), laid out as before, and each row is a region with its
1471
+ heading's name. No row draws an image for an empty picture. Shops already
1472
+ set up get it with nothing to update.
1473
+ - 2026-11-25: version 0.19.1. Magento: a card for a product without a picture
1474
+ has no image, where it had the open page's address as one (a broken image
1475
+ and a request). Modules already installed get it with nothing to update.
1476
+ - 2026-11-24: version 0.19.0. A row's card for a product the visitor opened
1477
+ earlier (`why: viewed_earlier`) says so, "You looked at this", and is the
1478
+ first card even when it comes with the top-up. `track()` takes
1479
+ `send: false`: the visitor's history learns what your server sends itself
1480
+ (an order). The WooCommerce and Magento order pages use it, with the
1481
+ plugin and module of this release (0.19.0, 0.4.33).
1482
+ - 2026-11-24: version 0.18.2. No visible change: the WooCommerce and Magento
1483
+ rows take the rules every row shares from `cards.js`, and the three shop
1484
+ rows what they share from `shops.js` ([What the shop modules
1485
+ share](#what-the-shop-modules-share)). Plugins and modules already
1486
+ installed get it with nothing to update.
1487
+ - 2026-11-24: version 0.18.1. No visible change: Shopify's row takes the
1488
+ rules it shares with `recapi.row()` from one file, `cards.js`.
1133
1489
  - 2026-11-24: version 0.18.0. `recapi.row(slot, { placement, contextItemId,
1134
1490
  heading })` draws a ready row of product cards from the items' metadata
1135
1491
  ([The ready row](#the-ready-row)). `track()` above level 0 without a
@@ -1297,8 +1653,8 @@ The same steps in real browsers (Chromium, Firefox, WebKit): see
1297
1653
  "Testing" in the repository's development guide.
1298
1654
 
1299
1655
  The API embeds `src/*.js` (module `recapi/sdkjs`, `embed.go`) and serves
1300
- them at `/sdk/<version>/`, where browsers cache every file but `index.js` for
1301
- a year. So a change to `src/` needs a new version: bump `version` in `package.json`,
1656
+ them at `/sdk/<version>/`, the entries joined ([Reading what runs](#reading-what-runs)),
1657
+ 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`,
1302
1658
  add the entry the failing Go test `TestSDKChangesNeedANewVersion` prints
1303
1659
  to `published.json` (the digest is `sha256sum src/*.js | sha256sum`, then
1304
1660
  each file's exports), and change the `/sdk/<version>/` paths in this