@konfiqo/storefront-react 0.5.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 +98 -1
- package/dist/index.cjs +806 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +243 -2
- package/dist/index.d.ts +243 -2
- package/dist/index.js +802 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, HTMLAttributes, ComponentType } from 'react';
|
|
3
|
-
import { Cart, AnyStorefrontError, CheckoutResult, CartIdStorage, StorefrontClientOptions, StorefrontClient, CategoryList, Product, ProductListQuery, ProductPage, Store, AddLineInput, UpdateLineInput, CustomerInput, AddressInput, RequestOptions, ShippingOptionList, Account, Order, PaymentPresentation, ClosedCheckoutPage, ContentNode } from '@konfiqo/storefront-sdk';
|
|
3
|
+
import { Cart, AnyStorefrontError, CheckoutResult, CartIdStorage, StorefrontClientOptions, StorefrontClient, CategoryList, Product, ProductListQuery, ProductPage, Store, AddLineInput, UpdateLineInput, CustomerInput, AddressInput, RequestOptions, ShippingOptionList, Account, Order, PaymentPresentation, ClosedCheckoutPage, ContentNode, CookieCategory, CookieInfo, AdPixels } from '@konfiqo/storefront-sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An error a hook reports: a {@link StorefrontError} (narrow with
|
|
@@ -352,4 +352,245 @@ interface ContentProps {
|
|
|
352
352
|
*/
|
|
353
353
|
declare function Content({ contentKey, components }: ContentProps): ReactNode;
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
/** A category the shopper can grant: every one but `necessary`. */
|
|
356
|
+
type OptionalCookieCategory = Exclude<CookieCategory, 'necessary'>;
|
|
357
|
+
/**
|
|
358
|
+
* A consent decision, as commerce records it (`POST /v1/consents`). The
|
|
359
|
+
* provider hands one to `onDecision` for every decision.
|
|
360
|
+
*/
|
|
361
|
+
interface ConsentRecord {
|
|
362
|
+
consentId: string;
|
|
363
|
+
granted: OptionalCookieCategory[];
|
|
364
|
+
version: string;
|
|
365
|
+
}
|
|
366
|
+
/** A stored consent for the current category version. */
|
|
367
|
+
interface StoredConsent {
|
|
368
|
+
/** Consent id: 32 lowercase hex, kept across later choices. */
|
|
369
|
+
id: string;
|
|
370
|
+
granted: OptionalCookieCategory[];
|
|
371
|
+
}
|
|
372
|
+
/** Every optional category, in display order. */
|
|
373
|
+
declare const OPTIONAL_CATEGORIES: readonly OptionalCookieCategory[];
|
|
374
|
+
|
|
375
|
+
/** The consent state the banner, the panel and the footer button share. */
|
|
376
|
+
interface ConsentState {
|
|
377
|
+
/** Whether the store uses an optional cookie (so consent applies). */
|
|
378
|
+
needed: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* Opens the preferences panel; focus returns to `opener` (default: the
|
|
381
|
+
* focused element) on close. When the opener is gone, focus moves to the
|
|
382
|
+
* element with id `main`.
|
|
383
|
+
*/
|
|
384
|
+
open: (opener?: HTMLElement | null) => void;
|
|
385
|
+
/** The store's cookies (necessary and optional). */
|
|
386
|
+
cookies: CookieInfo[];
|
|
387
|
+
/** The optional categories the store uses, in display order. */
|
|
388
|
+
categories: OptionalCookieCategory[];
|
|
389
|
+
/** The stored choice for the current version; null when none. */
|
|
390
|
+
stored: StoredConsent | null;
|
|
391
|
+
/**
|
|
392
|
+
* Whether the browser's choice has been read (false on the server and
|
|
393
|
+
* during hydration, when `stored` is null without meaning "no choice").
|
|
394
|
+
*/
|
|
395
|
+
known: boolean;
|
|
396
|
+
/** Whether to show the bar: needed and no choice yet (never on the server). */
|
|
397
|
+
showBar: boolean;
|
|
398
|
+
/** Whether the preferences panel is open. */
|
|
399
|
+
panelOpen: boolean;
|
|
400
|
+
/** Closes the panel without a decision. */
|
|
401
|
+
close: () => void;
|
|
402
|
+
/** Stores a decision, passes it to `onDecision`, then closes the panel. */
|
|
403
|
+
decide: (granted: OptionalCookieCategory[]) => void;
|
|
404
|
+
}
|
|
405
|
+
/** Props of {@link ConsentProvider}: the store's public cookie list. */
|
|
406
|
+
interface ConsentProviderProps {
|
|
407
|
+
cookies: CookieInfo[];
|
|
408
|
+
/** The store's category version ('' when no optional cookie). */
|
|
409
|
+
version: string;
|
|
410
|
+
/**
|
|
411
|
+
* Called after every stored decision, for example to record it with
|
|
412
|
+
* commerce (`recordConsent`). An error it throws is ignored.
|
|
413
|
+
*/
|
|
414
|
+
onDecision?: (record: ConsentRecord) => void;
|
|
415
|
+
children?: ReactNode;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Holds the shopper's cookie choice for the banner and the footer button.
|
|
419
|
+
*
|
|
420
|
+
* When the panel closes, focus returns to the element that opened it. When
|
|
421
|
+
* there is none (it was removed, or the decision was made in the bar),
|
|
422
|
+
* focus moves to the element with id `main`: give your main content
|
|
423
|
+
* `id="main"` and `tabIndex={-1}`.
|
|
424
|
+
*/
|
|
425
|
+
declare function ConsentProvider({ cookies, version, onDecision, children, }: ConsentProviderProps): react.JSX.Element;
|
|
426
|
+
/** The shared consent state (inert outside a {@link ConsentProvider}). */
|
|
427
|
+
declare function useConsent(): ConsentState;
|
|
428
|
+
|
|
429
|
+
/** The events the store reports to commerce. */
|
|
430
|
+
type AnalyticsEventType = 'page_view' | 'product_view' | 'add_to_cart' | 'checkout_start';
|
|
431
|
+
/** Optional ids that go with an event. */
|
|
432
|
+
interface AnalyticsExtra {
|
|
433
|
+
productId?: string;
|
|
434
|
+
}
|
|
435
|
+
interface AnalyticsConfig {
|
|
436
|
+
baseUrl: string;
|
|
437
|
+
publishableKey: string;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Sets where events go: the commerce API origin and the store's publishable
|
|
441
|
+
* key. Idempotent; `AnalyticsTracker` calls it on every render.
|
|
442
|
+
*/
|
|
443
|
+
declare function configureAnalytics(next: AnalyticsConfig): void;
|
|
444
|
+
/**
|
|
445
|
+
* For tests only, not for production code: forgets the configuration, the
|
|
446
|
+
* first-event state, the landing check and the queue, so each test starts
|
|
447
|
+
* as a fresh page load. Call it in `beforeEach`.
|
|
448
|
+
*/
|
|
449
|
+
declare function resetAnalytics(): void;
|
|
450
|
+
/**
|
|
451
|
+
* Reports one event. Fire and forget: never awaited, never throws. The
|
|
452
|
+
* first event of a page load carries the full URL (allowlisted query
|
|
453
|
+
* included) and the referrer origin so campaign tags are counted once;
|
|
454
|
+
* later events carry the path only.
|
|
455
|
+
*
|
|
456
|
+
* An identical `page_view` (same path) in the same tick is sent once.
|
|
457
|
+
*
|
|
458
|
+
* Events of one tick are queued and sent together, in call order, by one
|
|
459
|
+
* request (MAX_BATCH events each), so the landing `page_view` and a
|
|
460
|
+
* `product_view` from the same render reach commerce as one batch.
|
|
461
|
+
*/
|
|
462
|
+
declare function track(type: AnalyticsEventType, extra?: AnalyticsExtra): void;
|
|
463
|
+
/**
|
|
464
|
+
* Records a consent decision with commerce. Fire and forget, never throws.
|
|
465
|
+
* Not from the store editor's preview tab (the seller's own choices).
|
|
466
|
+
*/
|
|
467
|
+
declare function recordConsent(record: ConsentRecord): void;
|
|
468
|
+
|
|
469
|
+
/** Props of {@link AnalyticsTracker}. */
|
|
470
|
+
interface AnalyticsTrackerProps {
|
|
471
|
+
/** The commerce API origin (the `baseUrl` the storefront client uses). */
|
|
472
|
+
baseUrl: string;
|
|
473
|
+
/** The store's publishable key. */
|
|
474
|
+
publishableKey: string;
|
|
475
|
+
/**
|
|
476
|
+
* The current route's path, from your router (for example Next.js
|
|
477
|
+
* `usePathname()`). Each new value sends one `page_view`.
|
|
478
|
+
*/
|
|
479
|
+
pathname: string;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Configures analytics and sends a `page_view` on mount and every route change.
|
|
483
|
+
*
|
|
484
|
+
* Pages whose URL carries a buyer secret are protected by path. On an
|
|
485
|
+
* order-status page the URL sent is `/orders/:id`, and on both
|
|
486
|
+
* `/orders/…` and `/cart/recover` the query is left out. A custom storefront must serve its
|
|
487
|
+
* order-status and cart-recovery pages only at those paths, or not render
|
|
488
|
+
* this component there.
|
|
489
|
+
*/
|
|
490
|
+
declare function AnalyticsTracker({ baseUrl, publishableKey, pathname, }: AnalyticsTrackerProps): null;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* What the pixel layer is told about; mapped onto each platform's events.
|
|
494
|
+
*
|
|
495
|
+
* Ids match the rows of the store's product feed, which are variants: a
|
|
496
|
+
* known variant is sent as the item (`product`); a product page before a
|
|
497
|
+
* variant is chosen sends the product id as the group (`product_group`).
|
|
498
|
+
* `purchase` items carry variant ids.
|
|
499
|
+
*/
|
|
500
|
+
type PixelEvent = {
|
|
501
|
+
name: 'page_view';
|
|
502
|
+
} | {
|
|
503
|
+
name: 'view_item';
|
|
504
|
+
productId: string;
|
|
505
|
+
/** The selected variant, when one is chosen. */
|
|
506
|
+
variantId?: string;
|
|
507
|
+
priceMinor: number;
|
|
508
|
+
} | {
|
|
509
|
+
name: 'add_to_cart';
|
|
510
|
+
productId: string;
|
|
511
|
+
variantId: string;
|
|
512
|
+
priceMinor: number;
|
|
513
|
+
quantity: number;
|
|
514
|
+
} | {
|
|
515
|
+
name: 'begin_checkout';
|
|
516
|
+
valueMinor: number;
|
|
517
|
+
} | {
|
|
518
|
+
name: 'purchase';
|
|
519
|
+
orderId: string;
|
|
520
|
+
valueMinor: number;
|
|
521
|
+
/** `id` is the variant id. */
|
|
522
|
+
items: {
|
|
523
|
+
id: string;
|
|
524
|
+
quantity: number;
|
|
525
|
+
priceMinor: number;
|
|
526
|
+
}[];
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* For tests only, not for production code: forgets the configuration, the
|
|
530
|
+
* grant and which scripts were loaded, so each test starts as a fresh page
|
|
531
|
+
* load (storage and cookies are kept). Call it in `beforeEach`.
|
|
532
|
+
*/
|
|
533
|
+
declare function resetPixels(): void;
|
|
534
|
+
/**
|
|
535
|
+
* Whether this page's URL carries a buyer secret: the order page
|
|
536
|
+
* (`/orders/{id}?token=…`) and the cart-recovery link (`/cart/recover?t=…`).
|
|
537
|
+
* Platform scripts read the page URL and send it on, so pixels load nothing
|
|
538
|
+
* and send nothing there; the server's events still report the purchase.
|
|
539
|
+
* Store analytics scrubs the same pages (`/orders/:id`, no query).
|
|
540
|
+
*
|
|
541
|
+
* The paths are fixed: a custom storefront must serve its order-status and
|
|
542
|
+
* cart-recovery pages only at `/orders/…` and `/cart/recover`, or send no
|
|
543
|
+
* analytics or pixel events from them.
|
|
544
|
+
*/
|
|
545
|
+
declare function onSecretPage(path?: string): boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Sets the store's pixels and whether the shopper granted `marketing`.
|
|
548
|
+
* Scripts load once, on the first grant. Platform cookies are deleted only
|
|
549
|
+
* on a withdrawal on this page, or on a denied page when this browser
|
|
550
|
+
* loaded the store's pixels under an earlier grant (the marker), and only
|
|
551
|
+
* those of the platforms configured. `hostOnly` (a default store domain)
|
|
552
|
+
* keeps the deletion to the host. `currency` (ISO 4217, default `'TRY'`)
|
|
553
|
+
* is the currency of every price and value sent to the platforms.
|
|
554
|
+
*/
|
|
555
|
+
declare function configurePixels(next: AdPixels | undefined, isGranted: boolean, opts?: {
|
|
556
|
+
hostOnly?: boolean;
|
|
557
|
+
currency?: string;
|
|
558
|
+
}): void;
|
|
559
|
+
/** Reports `e` to every enabled platform; a no-op without a grant. */
|
|
560
|
+
declare function firePixel(e: PixelEvent): void;
|
|
561
|
+
|
|
562
|
+
/** Props of {@link AdPixelsLoader}. */
|
|
563
|
+
interface AdPixelsLoaderProps {
|
|
564
|
+
/**
|
|
565
|
+
* The store's ad pixels (`Store.adPixels`, filtered by the SDK's
|
|
566
|
+
* `pixelsForHost`).
|
|
567
|
+
*/
|
|
568
|
+
pixels?: AdPixels;
|
|
569
|
+
/** A default store domain: cookies are cleared on the host only. */
|
|
570
|
+
hostOnly?: boolean;
|
|
571
|
+
/**
|
|
572
|
+
* The store's currency (ISO 4217) for every price sent to the platforms.
|
|
573
|
+
* Default `'TRY'`.
|
|
574
|
+
*/
|
|
575
|
+
currency?: string;
|
|
576
|
+
/**
|
|
577
|
+
* The current route's path, from your router (for example Next.js
|
|
578
|
+
* `usePathname()`). Each new value reports one page view.
|
|
579
|
+
*/
|
|
580
|
+
pathname: string;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Loads the store's ad pixels once the shopper granted `marketing` for the
|
|
584
|
+
* current cookie version (no reload needed), stops them on withdrawal, and
|
|
585
|
+
* reports a page view on every route change. Nothing is configured until
|
|
586
|
+
* the browser's choice has been read (hydration), so a stored grant never
|
|
587
|
+
* looks like a refusal. Must be inside a `ConsentProvider`.
|
|
588
|
+
*
|
|
589
|
+
* Pages whose URL carries a buyer secret (`/orders/…` and `/cart/recover`,
|
|
590
|
+
* see `onSecretPage`) load no pixel script and send no pixel event. A
|
|
591
|
+
* custom storefront must serve its order-status and cart-recovery pages
|
|
592
|
+
* only at those paths, or not render this component there.
|
|
593
|
+
*/
|
|
594
|
+
declare function AdPixelsLoader({ pixels, hostOnly, currency, pathname, }: AdPixelsLoaderProps): null;
|
|
595
|
+
|
|
596
|
+
export { AdPixelsLoader, type AdPixelsLoaderProps, type AnalyticsEventType, type AnalyticsExtra, AnalyticsTracker, type AnalyticsTrackerProps, type CartSnapshot, type CheckoutCallOptions, CheckoutChallenge, type CheckoutChallengeHandle, type CheckoutChallengeProps, type CheckoutSnapshot, type ClientConfig, ConsentProvider, type ConsentProviderProps, type ConsentRecord, type ConsentState, Content, type ContentComponents, type ContentProps, OPTIONAL_CATEGORIES, ORDER_POLL_MAX_MS, ORDER_POLL_MIN_MS, type OptionalCookieCategory, PaymentForm, type PaymentFormProps, type PixelEvent, type ResourceResult, type StoredConsent, type StorefrontHookError, StorefrontProvider, type StorefrontProviderProps, type UseAccountResult, type UseCartResult, type UseCheckoutResult, type UseOrderOptions, type UseOrderResult, configureAnalytics, configurePixels, defaultCartStorage, firePixel, isDeadCartError, isOrderSettled, onSecretPage, orderPollDelay, recordConsent, renderContent, resetAnalytics, resetPixels, track, useAccount, useCart, useCartStorage, useCategories, useCheckout, useConsent, useOrder, useProduct, useProducts, useStore, useStorefrontClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, HTMLAttributes, ComponentType } from 'react';
|
|
3
|
-
import { Cart, AnyStorefrontError, CheckoutResult, CartIdStorage, StorefrontClientOptions, StorefrontClient, CategoryList, Product, ProductListQuery, ProductPage, Store, AddLineInput, UpdateLineInput, CustomerInput, AddressInput, RequestOptions, ShippingOptionList, Account, Order, PaymentPresentation, ClosedCheckoutPage, ContentNode } from '@konfiqo/storefront-sdk';
|
|
3
|
+
import { Cart, AnyStorefrontError, CheckoutResult, CartIdStorage, StorefrontClientOptions, StorefrontClient, CategoryList, Product, ProductListQuery, ProductPage, Store, AddLineInput, UpdateLineInput, CustomerInput, AddressInput, RequestOptions, ShippingOptionList, Account, Order, PaymentPresentation, ClosedCheckoutPage, ContentNode, CookieCategory, CookieInfo, AdPixels } from '@konfiqo/storefront-sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An error a hook reports: a {@link StorefrontError} (narrow with
|
|
@@ -352,4 +352,245 @@ interface ContentProps {
|
|
|
352
352
|
*/
|
|
353
353
|
declare function Content({ contentKey, components }: ContentProps): ReactNode;
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
/** A category the shopper can grant: every one but `necessary`. */
|
|
356
|
+
type OptionalCookieCategory = Exclude<CookieCategory, 'necessary'>;
|
|
357
|
+
/**
|
|
358
|
+
* A consent decision, as commerce records it (`POST /v1/consents`). The
|
|
359
|
+
* provider hands one to `onDecision` for every decision.
|
|
360
|
+
*/
|
|
361
|
+
interface ConsentRecord {
|
|
362
|
+
consentId: string;
|
|
363
|
+
granted: OptionalCookieCategory[];
|
|
364
|
+
version: string;
|
|
365
|
+
}
|
|
366
|
+
/** A stored consent for the current category version. */
|
|
367
|
+
interface StoredConsent {
|
|
368
|
+
/** Consent id: 32 lowercase hex, kept across later choices. */
|
|
369
|
+
id: string;
|
|
370
|
+
granted: OptionalCookieCategory[];
|
|
371
|
+
}
|
|
372
|
+
/** Every optional category, in display order. */
|
|
373
|
+
declare const OPTIONAL_CATEGORIES: readonly OptionalCookieCategory[];
|
|
374
|
+
|
|
375
|
+
/** The consent state the banner, the panel and the footer button share. */
|
|
376
|
+
interface ConsentState {
|
|
377
|
+
/** Whether the store uses an optional cookie (so consent applies). */
|
|
378
|
+
needed: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* Opens the preferences panel; focus returns to `opener` (default: the
|
|
381
|
+
* focused element) on close. When the opener is gone, focus moves to the
|
|
382
|
+
* element with id `main`.
|
|
383
|
+
*/
|
|
384
|
+
open: (opener?: HTMLElement | null) => void;
|
|
385
|
+
/** The store's cookies (necessary and optional). */
|
|
386
|
+
cookies: CookieInfo[];
|
|
387
|
+
/** The optional categories the store uses, in display order. */
|
|
388
|
+
categories: OptionalCookieCategory[];
|
|
389
|
+
/** The stored choice for the current version; null when none. */
|
|
390
|
+
stored: StoredConsent | null;
|
|
391
|
+
/**
|
|
392
|
+
* Whether the browser's choice has been read (false on the server and
|
|
393
|
+
* during hydration, when `stored` is null without meaning "no choice").
|
|
394
|
+
*/
|
|
395
|
+
known: boolean;
|
|
396
|
+
/** Whether to show the bar: needed and no choice yet (never on the server). */
|
|
397
|
+
showBar: boolean;
|
|
398
|
+
/** Whether the preferences panel is open. */
|
|
399
|
+
panelOpen: boolean;
|
|
400
|
+
/** Closes the panel without a decision. */
|
|
401
|
+
close: () => void;
|
|
402
|
+
/** Stores a decision, passes it to `onDecision`, then closes the panel. */
|
|
403
|
+
decide: (granted: OptionalCookieCategory[]) => void;
|
|
404
|
+
}
|
|
405
|
+
/** Props of {@link ConsentProvider}: the store's public cookie list. */
|
|
406
|
+
interface ConsentProviderProps {
|
|
407
|
+
cookies: CookieInfo[];
|
|
408
|
+
/** The store's category version ('' when no optional cookie). */
|
|
409
|
+
version: string;
|
|
410
|
+
/**
|
|
411
|
+
* Called after every stored decision, for example to record it with
|
|
412
|
+
* commerce (`recordConsent`). An error it throws is ignored.
|
|
413
|
+
*/
|
|
414
|
+
onDecision?: (record: ConsentRecord) => void;
|
|
415
|
+
children?: ReactNode;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Holds the shopper's cookie choice for the banner and the footer button.
|
|
419
|
+
*
|
|
420
|
+
* When the panel closes, focus returns to the element that opened it. When
|
|
421
|
+
* there is none (it was removed, or the decision was made in the bar),
|
|
422
|
+
* focus moves to the element with id `main`: give your main content
|
|
423
|
+
* `id="main"` and `tabIndex={-1}`.
|
|
424
|
+
*/
|
|
425
|
+
declare function ConsentProvider({ cookies, version, onDecision, children, }: ConsentProviderProps): react.JSX.Element;
|
|
426
|
+
/** The shared consent state (inert outside a {@link ConsentProvider}). */
|
|
427
|
+
declare function useConsent(): ConsentState;
|
|
428
|
+
|
|
429
|
+
/** The events the store reports to commerce. */
|
|
430
|
+
type AnalyticsEventType = 'page_view' | 'product_view' | 'add_to_cart' | 'checkout_start';
|
|
431
|
+
/** Optional ids that go with an event. */
|
|
432
|
+
interface AnalyticsExtra {
|
|
433
|
+
productId?: string;
|
|
434
|
+
}
|
|
435
|
+
interface AnalyticsConfig {
|
|
436
|
+
baseUrl: string;
|
|
437
|
+
publishableKey: string;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Sets where events go: the commerce API origin and the store's publishable
|
|
441
|
+
* key. Idempotent; `AnalyticsTracker` calls it on every render.
|
|
442
|
+
*/
|
|
443
|
+
declare function configureAnalytics(next: AnalyticsConfig): void;
|
|
444
|
+
/**
|
|
445
|
+
* For tests only, not for production code: forgets the configuration, the
|
|
446
|
+
* first-event state, the landing check and the queue, so each test starts
|
|
447
|
+
* as a fresh page load. Call it in `beforeEach`.
|
|
448
|
+
*/
|
|
449
|
+
declare function resetAnalytics(): void;
|
|
450
|
+
/**
|
|
451
|
+
* Reports one event. Fire and forget: never awaited, never throws. The
|
|
452
|
+
* first event of a page load carries the full URL (allowlisted query
|
|
453
|
+
* included) and the referrer origin so campaign tags are counted once;
|
|
454
|
+
* later events carry the path only.
|
|
455
|
+
*
|
|
456
|
+
* An identical `page_view` (same path) in the same tick is sent once.
|
|
457
|
+
*
|
|
458
|
+
* Events of one tick are queued and sent together, in call order, by one
|
|
459
|
+
* request (MAX_BATCH events each), so the landing `page_view` and a
|
|
460
|
+
* `product_view` from the same render reach commerce as one batch.
|
|
461
|
+
*/
|
|
462
|
+
declare function track(type: AnalyticsEventType, extra?: AnalyticsExtra): void;
|
|
463
|
+
/**
|
|
464
|
+
* Records a consent decision with commerce. Fire and forget, never throws.
|
|
465
|
+
* Not from the store editor's preview tab (the seller's own choices).
|
|
466
|
+
*/
|
|
467
|
+
declare function recordConsent(record: ConsentRecord): void;
|
|
468
|
+
|
|
469
|
+
/** Props of {@link AnalyticsTracker}. */
|
|
470
|
+
interface AnalyticsTrackerProps {
|
|
471
|
+
/** The commerce API origin (the `baseUrl` the storefront client uses). */
|
|
472
|
+
baseUrl: string;
|
|
473
|
+
/** The store's publishable key. */
|
|
474
|
+
publishableKey: string;
|
|
475
|
+
/**
|
|
476
|
+
* The current route's path, from your router (for example Next.js
|
|
477
|
+
* `usePathname()`). Each new value sends one `page_view`.
|
|
478
|
+
*/
|
|
479
|
+
pathname: string;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Configures analytics and sends a `page_view` on mount and every route change.
|
|
483
|
+
*
|
|
484
|
+
* Pages whose URL carries a buyer secret are protected by path. On an
|
|
485
|
+
* order-status page the URL sent is `/orders/:id`, and on both
|
|
486
|
+
* `/orders/…` and `/cart/recover` the query is left out. A custom storefront must serve its
|
|
487
|
+
* order-status and cart-recovery pages only at those paths, or not render
|
|
488
|
+
* this component there.
|
|
489
|
+
*/
|
|
490
|
+
declare function AnalyticsTracker({ baseUrl, publishableKey, pathname, }: AnalyticsTrackerProps): null;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* What the pixel layer is told about; mapped onto each platform's events.
|
|
494
|
+
*
|
|
495
|
+
* Ids match the rows of the store's product feed, which are variants: a
|
|
496
|
+
* known variant is sent as the item (`product`); a product page before a
|
|
497
|
+
* variant is chosen sends the product id as the group (`product_group`).
|
|
498
|
+
* `purchase` items carry variant ids.
|
|
499
|
+
*/
|
|
500
|
+
type PixelEvent = {
|
|
501
|
+
name: 'page_view';
|
|
502
|
+
} | {
|
|
503
|
+
name: 'view_item';
|
|
504
|
+
productId: string;
|
|
505
|
+
/** The selected variant, when one is chosen. */
|
|
506
|
+
variantId?: string;
|
|
507
|
+
priceMinor: number;
|
|
508
|
+
} | {
|
|
509
|
+
name: 'add_to_cart';
|
|
510
|
+
productId: string;
|
|
511
|
+
variantId: string;
|
|
512
|
+
priceMinor: number;
|
|
513
|
+
quantity: number;
|
|
514
|
+
} | {
|
|
515
|
+
name: 'begin_checkout';
|
|
516
|
+
valueMinor: number;
|
|
517
|
+
} | {
|
|
518
|
+
name: 'purchase';
|
|
519
|
+
orderId: string;
|
|
520
|
+
valueMinor: number;
|
|
521
|
+
/** `id` is the variant id. */
|
|
522
|
+
items: {
|
|
523
|
+
id: string;
|
|
524
|
+
quantity: number;
|
|
525
|
+
priceMinor: number;
|
|
526
|
+
}[];
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* For tests only, not for production code: forgets the configuration, the
|
|
530
|
+
* grant and which scripts were loaded, so each test starts as a fresh page
|
|
531
|
+
* load (storage and cookies are kept). Call it in `beforeEach`.
|
|
532
|
+
*/
|
|
533
|
+
declare function resetPixels(): void;
|
|
534
|
+
/**
|
|
535
|
+
* Whether this page's URL carries a buyer secret: the order page
|
|
536
|
+
* (`/orders/{id}?token=…`) and the cart-recovery link (`/cart/recover?t=…`).
|
|
537
|
+
* Platform scripts read the page URL and send it on, so pixels load nothing
|
|
538
|
+
* and send nothing there; the server's events still report the purchase.
|
|
539
|
+
* Store analytics scrubs the same pages (`/orders/:id`, no query).
|
|
540
|
+
*
|
|
541
|
+
* The paths are fixed: a custom storefront must serve its order-status and
|
|
542
|
+
* cart-recovery pages only at `/orders/…` and `/cart/recover`, or send no
|
|
543
|
+
* analytics or pixel events from them.
|
|
544
|
+
*/
|
|
545
|
+
declare function onSecretPage(path?: string): boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Sets the store's pixels and whether the shopper granted `marketing`.
|
|
548
|
+
* Scripts load once, on the first grant. Platform cookies are deleted only
|
|
549
|
+
* on a withdrawal on this page, or on a denied page when this browser
|
|
550
|
+
* loaded the store's pixels under an earlier grant (the marker), and only
|
|
551
|
+
* those of the platforms configured. `hostOnly` (a default store domain)
|
|
552
|
+
* keeps the deletion to the host. `currency` (ISO 4217, default `'TRY'`)
|
|
553
|
+
* is the currency of every price and value sent to the platforms.
|
|
554
|
+
*/
|
|
555
|
+
declare function configurePixels(next: AdPixels | undefined, isGranted: boolean, opts?: {
|
|
556
|
+
hostOnly?: boolean;
|
|
557
|
+
currency?: string;
|
|
558
|
+
}): void;
|
|
559
|
+
/** Reports `e` to every enabled platform; a no-op without a grant. */
|
|
560
|
+
declare function firePixel(e: PixelEvent): void;
|
|
561
|
+
|
|
562
|
+
/** Props of {@link AdPixelsLoader}. */
|
|
563
|
+
interface AdPixelsLoaderProps {
|
|
564
|
+
/**
|
|
565
|
+
* The store's ad pixels (`Store.adPixels`, filtered by the SDK's
|
|
566
|
+
* `pixelsForHost`).
|
|
567
|
+
*/
|
|
568
|
+
pixels?: AdPixels;
|
|
569
|
+
/** A default store domain: cookies are cleared on the host only. */
|
|
570
|
+
hostOnly?: boolean;
|
|
571
|
+
/**
|
|
572
|
+
* The store's currency (ISO 4217) for every price sent to the platforms.
|
|
573
|
+
* Default `'TRY'`.
|
|
574
|
+
*/
|
|
575
|
+
currency?: string;
|
|
576
|
+
/**
|
|
577
|
+
* The current route's path, from your router (for example Next.js
|
|
578
|
+
* `usePathname()`). Each new value reports one page view.
|
|
579
|
+
*/
|
|
580
|
+
pathname: string;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Loads the store's ad pixels once the shopper granted `marketing` for the
|
|
584
|
+
* current cookie version (no reload needed), stops them on withdrawal, and
|
|
585
|
+
* reports a page view on every route change. Nothing is configured until
|
|
586
|
+
* the browser's choice has been read (hydration), so a stored grant never
|
|
587
|
+
* looks like a refusal. Must be inside a `ConsentProvider`.
|
|
588
|
+
*
|
|
589
|
+
* Pages whose URL carries a buyer secret (`/orders/…` and `/cart/recover`,
|
|
590
|
+
* see `onSecretPage`) load no pixel script and send no pixel event. A
|
|
591
|
+
* custom storefront must serve its order-status and cart-recovery pages
|
|
592
|
+
* only at those paths, or not render this component there.
|
|
593
|
+
*/
|
|
594
|
+
declare function AdPixelsLoader({ pixels, hostOnly, currency, pathname, }: AdPixelsLoaderProps): null;
|
|
595
|
+
|
|
596
|
+
export { AdPixelsLoader, type AdPixelsLoaderProps, type AnalyticsEventType, type AnalyticsExtra, AnalyticsTracker, type AnalyticsTrackerProps, type CartSnapshot, type CheckoutCallOptions, CheckoutChallenge, type CheckoutChallengeHandle, type CheckoutChallengeProps, type CheckoutSnapshot, type ClientConfig, ConsentProvider, type ConsentProviderProps, type ConsentRecord, type ConsentState, Content, type ContentComponents, type ContentProps, OPTIONAL_CATEGORIES, ORDER_POLL_MAX_MS, ORDER_POLL_MIN_MS, type OptionalCookieCategory, PaymentForm, type PaymentFormProps, type PixelEvent, type ResourceResult, type StoredConsent, type StorefrontHookError, StorefrontProvider, type StorefrontProviderProps, type UseAccountResult, type UseCartResult, type UseCheckoutResult, type UseOrderOptions, type UseOrderResult, configureAnalytics, configurePixels, defaultCartStorage, firePixel, isDeadCartError, isOrderSettled, onSecretPage, orderPollDelay, recordConsent, renderContent, resetAnalytics, resetPixels, track, useAccount, useCart, useCartStorage, useCategories, useCheckout, useConsent, useOrder, useProduct, useProducts, useStore, useStorefrontClient };
|