/** * Quomerce browser SDK: types for `window.qm`. * * Copy this file into your project (for example as `types/qm.d.ts`) and make sure your * tsconfig.json includes it. `window.qm` and the global `qm` are then typed, and the shapes * below can be imported: `import type { Product } from "./types/qm"`. * * Generated from packages/client-sdk/src/types.ts. Do not edit by hand. * Docs: https://docs.quomerce.com */ /** The cart as it is now. `value` is its total, in major units. */ export declare interface Cart { value: number; currency: string; items: CartItem[]; } /** One line of a cart or an order. */ export declare interface CartItem { product: Product; quantity: number; } /** * `qm.commerce`: the shop's own commerce events. Sent only when `init` was given * `commerce: "manual"`; in `auto` mode (the default) every call is ignored. */ export declare interface CommerceApi { /** An account was created. `method`: `"email"`, `"google"`… */ signedUp(method?: string): void; /** A buyer logged in. */ loggedIn(method?: string): void; /** A banner or campaign slot was shown. */ promotionViewed(promotion: Promotion): void; /** A banner or campaign slot was clicked. */ promotionSelected(promotion: Promotion): void; /** A search ran. Emails and phone numbers in the term are masked. */ searchPerformed(term: string, results?: number): void; /** A category, search results or another product list was shown. */ itemListViewed(list: ItemList, itemCount?: number): void; /** A product was picked from a list, at `index`. */ itemSelected(product: Product, list?: ItemList, index?: number): void; wishlistAdded(product: Product): void; /** A product page was shown. */ productViewed(product: Product): void; /** `quantity` (default 1) was added to the cart. */ cartAdded(product: Product, quantity?: number): void; /** `quantity` (default 1) was removed from the cart. */ cartRemoved(product: Product, quantity?: number): void; /** The cart page was shown. */ cartViewed(cart: Cart): void; /** The buyer went to checkout. */ checkoutStarted(cart: Cart): void; /** e.g. `"inpost_paczkomat"`, `"dhl"`. */ shippingMethodSelected(method: string): void; /** e.g. `"blik"`, `"card"`, `"transfer"`, `"cod"`. */ paymentMethodSelected(method: string): void; /** The buyer left for the payment gateway, e.g. `("blik", "przelewy24")`. */ paymentRedirected(method: string, provider: string): void; /** The buyer came back from the payment gateway. */ paymentReturned(method: string, provider: string, status: PaymentReturnStatus): void; /** A coupon was tried; `success` says whether the shop accepted it. */ couponApplied(code: string, success: boolean): void; /** The order confirmation was shown. Call it once per order. */ purchase(order: Order): void; } /** * `auto`: commerce events come only from detection, and `qm.commerce` calls are * ignored. `manual`: only from `qm.commerce` calls. Set by `init` alone. */ export declare type CommerceMode = "auto" | "manual"; export declare interface ConsentChoice { analytics: boolean; replay: boolean; } export declare interface InitOptions { /** The site's public key, `pk_live_…`. */ key: string; /** * Where to send. Defaults to the origin the SDK script was loaded from — in * production the ingest host serves both — so only local setups need it. */ endpoint?: string; /** e.g. `.example.com`, to share the session across subdomains. */ cookieDomain?: string; /** Writes what the SDK does (and what it swallowed) to `console.debug`. Off by default. */ debug?: boolean; /** * `auto` (the default): commerce events are detected — from the platform, the * GA4 dataLayer and rules — and `qm.commerce` calls are ignored. `manual`: * only `qm.commerce` calls are sent, and nothing is detected. The shop's code * is the only place this is set. */ commerce?: CommerceMode; } /** A list of products: a category, search results, "related products". Either field identifies it. */ export declare interface ItemList { id?: string | number; name?: string; } /** A placed order. `id` is the shop's order number; `value` its total, in major units. */ export declare interface Order { id: string | number; value: number; currency: string; items?: CartItem[]; } /** Every page type a page can have. */ declare const PAGE_TYPES: readonly ["home", "category", "search", "product", "cart", "checkout", "thank_you", "account", "other"]; /** What kind of page this is: the funnel, replay masking and the Pages report all read it. */ export declare type PageType = (typeof PAGE_TYPES)[number]; /** How the buyer came back from the payment gateway. */ export declare type PaymentReturnStatus = "success" | "failure" | "unknown"; /** * The client commerce API's argument types (client-sdk spec, "Client commerce * API") and their conversion to the wire. A call with arguments that do not * describe a product or a cart is dropped — silently, like everything else * that goes wrong in here: a malformed event is worse than a missing one, and * an exception is worse than both. */ /** A product as the shop shows it. Money is in major units (`2899.99`), currency an ISO 4217 code. */ export declare interface Product { /** The shop's own product id. */ id: string | number; /** The variant's id, when the product has variants (size, colour…). */ variantId?: string | number; sku?: string; name: string; /** The product page's URL. */ url?: string; /** The regular price, in major units. */ price: number; /** The price actually charged, when it is lower than `price`. */ salePrice?: number; /** ISO 4217, e.g. `"PLN"`, `"EUR"`. */ currency: string; category?: string; brand?: string; /** The main image's URL. */ image?: string; /** e.g. `"in_stock"`, `"out_of_stock"`, or a schema.org availability URL. */ availability?: string; } /** A promotion: a banner, a slot, a campaign. `id` or `name` identifies it. */ export declare interface Promotion { id?: string | number; name?: string; creative?: string; slot?: string; } /** * `window.qm`: callable as `qm('command', ...args)` — the form the snippet's * queue records before the SDK has loaded — and as methods once it has. * Before the script has loaded only the call form exists, so shop code should * prefer it: `qm("commerce.cartAdded", product, 1)`. */ export declare interface QmApi { (command: "init", options: InitOptions): void; (command: "page", options: { type: PageType; }): void; (command: "track", name: string, props?: Record): void; (command: "identify", customerId: string | number): void; (command: "consent", choice: Partial): void; (command: `commerce.${K}`, ...args: Parameters): void; /** Starts the SDK. Call it once per page, in the snippet. */ init(options: InitOptions): void; /** Sets this page's type, overriding rules and URL heuristics. */ page(options: { type: PageType; }): void; /** A custom event, sent as `custom:` in both commerce modes. `props` up to 2 KB. */ track(name: string, props?: Record): void; /** Links the session to a customer. Only a hash of the id is sent, never the id. */ identify(customerId: string | number): void; /** Passes on the visitor's consent. Call it on every page load once the choice is known. */ consent(choice: Partial): void; /** The shop's own commerce events (`manual` mode only). */ commerce: CommerceApi; /** The SDK's version, e.g. `"0.1.0"`. */ version: string; } export { } declare global { /** * The Quomerce SDK. Defined by the snippet; `undefined` on the server and before the snippet runs. * Until the script has loaded it is only a queue, so use the call form: `qm?.("page", { type: "cart" })`. */ var qm: QmApi | undefined; }