@konfiqo/storefront-react 0.4.0 → 0.6.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 +101 -4
- package/dist/index.cjs +808 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +246 -5
- package/dist/index.d.ts +246 -5
- package/dist/index.js +804 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ the payment form and the checkout challenge.
|
|
|
11
11
|
"build your own storefront" guide.
|
|
12
12
|
- No styling: components render a plain `<div>` you can give a `className`.
|
|
13
13
|
- No runtime dependencies. Peer dependencies: `@konfiqo/storefront-sdk`
|
|
14
|
-
`^0.
|
|
14
|
+
`^0.6.0` and `react` ≥ 18. Install the SDK yourself, so your code and this
|
|
15
15
|
package share one copy (`isStorefrontError` also recognises errors from a
|
|
16
16
|
second copy, but one copy keeps the bundle small).
|
|
17
17
|
- Server-rendering safe: nothing touches `window`, `document` or storage
|
|
@@ -90,9 +90,9 @@ const {
|
|
|
90
90
|
error, // the last read / write error, or null
|
|
91
91
|
previousCartId, // string | null — an ordered cart a write moved away from (see below)
|
|
92
92
|
itemCount, // total units (for a badge)
|
|
93
|
-
addLine, // ({ variantId, quantity }) => Promise<Cart>
|
|
94
|
-
updateLine, // (
|
|
95
|
-
removeLine, // (
|
|
93
|
+
addLine, // ({ variantId, quantity, personalization? }) => Promise<Cart>
|
|
94
|
+
updateLine, // (lineId, { quantity }) => Promise<Cart>, lineId = cart line `id`
|
|
95
|
+
removeLine, // (lineId) => Promise<Cart>
|
|
96
96
|
setCustomer, // (CustomerInput) => Promise<Cart>
|
|
97
97
|
setAddress, // ({ shipping, billing? }) => Promise<Cart>
|
|
98
98
|
setShippingOption, // (optionId) => Promise<Cart>
|
|
@@ -305,6 +305,103 @@ const { order, error, isLoading, isPolling, refetch } = useOrder(id, token, {
|
|
|
305
305
|
Also exported: `isOrderSettled(order)`, `orderPollDelay(attempt)`,
|
|
306
306
|
`ORDER_POLL_MIN_MS`, `ORDER_POLL_MAX_MS`, `isDeadCartError(e)`.
|
|
307
307
|
|
|
308
|
+
## Consent, analytics and ad pixels
|
|
309
|
+
|
|
310
|
+
Logic only: you build the banner, the preferences panel and the footer
|
|
311
|
+
link yourself.
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
'use client';
|
|
315
|
+
import {
|
|
316
|
+
AdPixelsLoader,
|
|
317
|
+
AnalyticsTracker,
|
|
318
|
+
ConsentProvider,
|
|
319
|
+
recordConsent,
|
|
320
|
+
} from '@konfiqo/storefront-react';
|
|
321
|
+
import { cookiesForHost } from '@konfiqo/storefront-sdk';
|
|
322
|
+
import { usePathname } from 'next/navigation';
|
|
323
|
+
|
|
324
|
+
// `pixels` and `defaultDomain` come from a server component:
|
|
325
|
+
// pixelsForHost(store.adPixels, onDefaultDomain(host, defaultSuffix)).
|
|
326
|
+
export function Tracking({
|
|
327
|
+
store,
|
|
328
|
+
baseUrl,
|
|
329
|
+
publishableKey,
|
|
330
|
+
pixels,
|
|
331
|
+
defaultDomain,
|
|
332
|
+
}) {
|
|
333
|
+
const pathname = usePathname();
|
|
334
|
+
return (
|
|
335
|
+
<ConsentProvider
|
|
336
|
+
cookies={cookiesForHost(store.cookies ?? [], defaultDomain)}
|
|
337
|
+
version={store.consentVersion ?? ''}
|
|
338
|
+
onDecision={recordConsent}
|
|
339
|
+
>
|
|
340
|
+
<AnalyticsTracker
|
|
341
|
+
baseUrl={baseUrl}
|
|
342
|
+
publishableKey={publishableKey}
|
|
343
|
+
pathname={pathname}
|
|
344
|
+
/>
|
|
345
|
+
<AdPixelsLoader
|
|
346
|
+
pixels={pixels}
|
|
347
|
+
hostOnly={defaultDomain}
|
|
348
|
+
currency="EUR"
|
|
349
|
+
pathname={pathname}
|
|
350
|
+
/>
|
|
351
|
+
{/* your banner and panel, built on useConsent() */}
|
|
352
|
+
</ConsentProvider>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
- **Consent.** `ConsentProvider` keeps the shopper's choice in the strictly
|
|
358
|
+
necessary `_consent` cookie, per consent version. `useConsent()` gives
|
|
359
|
+
`needed`, `showBar`, `panelOpen`, `categories`, `cookies`, `stored`,
|
|
360
|
+
`known`, `open()`, `close()` and `decide(granted)`. `onDecision` receives
|
|
361
|
+
a `ConsentRecord` for every decision; an error it throws is ignored.
|
|
362
|
+
When the panel closes, focus returns to the element that opened it, or
|
|
363
|
+
to the element with id `main` when there is none (give your main
|
|
364
|
+
content `id="main"` and `tabIndex={-1}`).
|
|
365
|
+
- **Store analytics.** `AnalyticsTracker` configures `track` and sends a
|
|
366
|
+
`page_view` for each new `pathname`. Call
|
|
367
|
+
`track('product_view', { productId })`,
|
|
368
|
+
`track('add_to_cart', { productId })` or
|
|
369
|
+
`track('checkout_start')` from your pages. Events are batched, never
|
|
370
|
+
throw, and are not sent from the store editor's preview tab. Each batch
|
|
371
|
+
states whether the shopper granted `analytics`.
|
|
372
|
+
- **Ad pixels.** `AdPixelsLoader` loads Meta, TikTok and Google only under
|
|
373
|
+
a `marketing` grant for the current consent version, stops them and
|
|
374
|
+
clears their cookies on withdrawal, and reports a page view per
|
|
375
|
+
`pathname`. Report shop events with `firePixel`:
|
|
376
|
+
`{ name: 'view_item', productId, variantId?, priceMinor }`,
|
|
377
|
+
`{ name: 'add_to_cart', productId, variantId, priceMinor, quantity }`,
|
|
378
|
+
`{ name: 'begin_checkout', valueMinor }` and
|
|
379
|
+
`{ name: 'purchase', orderId, valueMinor, items }` (item `id` is the
|
|
380
|
+
variant id). Ids follow the product feed rows: pass `variantId` as soon
|
|
381
|
+
as a variant is chosen; before that, `view_item` names the product as a
|
|
382
|
+
`product_group`. Prices are in minor units, in the `currency` given to
|
|
383
|
+
`AdPixelsLoader` (ISO 4217, default `'TRY'`).
|
|
384
|
+
- **Which pixels and cookies a host may use.** On a default store domain,
|
|
385
|
+
filter with the SDK's `onDefaultDomain`, `pixelsForHost` and
|
|
386
|
+
`cookiesForHost`. They are server-safe, so call them in server
|
|
387
|
+
components; this package is client-only.
|
|
388
|
+
- **Pages that carry buyer secrets.** The order-status page
|
|
389
|
+
(`/orders/{id}?token=…`) and the cart-recovery link
|
|
390
|
+
(`/cart/recover?t=…`) carry a secret in the URL. Analytics sends
|
|
391
|
+
`/orders/:id` with no query there, and sends no query on
|
|
392
|
+
`/cart/recover`. Pixels load no script and send no event on either path
|
|
393
|
+
(`onSecretPage(path)`). These paths are fixed: serve your order-status
|
|
394
|
+
and cart-recovery pages only at `/orders/…` and `/cart/recover`, or do
|
|
395
|
+
not render `AnalyticsTracker` and `AdPixelsLoader` (and do not call
|
|
396
|
+
`track` or `firePixel`) on them. Open these pages with a full page load
|
|
397
|
+
(`location.assign` or `location.replace`), never a client-side route
|
|
398
|
+
change: pixel scripts already loaded on the previous page read the full
|
|
399
|
+
URL (GA4 history page views, Meta automatic events) and would send the
|
|
400
|
+
secret.
|
|
401
|
+
- **Tests.** `resetAnalytics()` and `resetPixels()` forget the module
|
|
402
|
+
state between tests. They are for tests only; do not call them in
|
|
403
|
+
production code.
|
|
404
|
+
|
|
308
405
|
## Next.js App Router
|
|
309
406
|
|
|
310
407
|
- The package is marked `'use client'`: import the provider, hooks and
|