Ir al contenido

loadTryYourSize()

Esta página aún no está disponible en tu idioma.

Function@tryyoursize/sdk/loader

Loads TryYourSize.js from our CDN once (the latest compatible v1 build) and creates a client, like loadStripe(). Resolves to null during server-side rendering, so it is safe to call at module level in Next.js, Remix or Astro.

async function loadTryYourSize(
publishableKey: string,
options: TryYourSizeOptions & { scriptUrl?: string } = {},
): Promise<TryYourSizeClient | null>
publishableKeystringObligatorio

Your publishable key (pk_test_… or pk_live_…).

optionsTryYourSizeOptions & { scriptUrl?: string }Opcional= {}

The options of TryYourSize(), plus scriptUrl to load the script from another URL (development only).

Propiedades
embedOriginstringOpcional

Override for development (e.g. http://localhost:5173).

apiOriginstringOpcional

Override of the API origin for development (e.g. http://localhost:8000): the A/B holdout config.

localeLocaleOpcional

Language of our windows; "auto" follows the browser.

Promise<TryYourSizeClient | null>: A promise of the client, or null on the server.

Rejects with TryYourSizeError code script_load_failed when the script cannot load (network, CSP). Call it again to retry.

import { loadTryYourSize } from "@tryyoursize/sdk/loader";
const tys = await loadTryYourSize("pk_test_…");
if (tys) tys.elements().create("sizeGuide", { product: "SKU-123" }).mount("#size-guide");

¿Te ha resultado útil esta página?