SoraiDocs
GuidesAPI reference

Reference

Every method and type sorai-js exposes.

The runtime's whole public surface: the window.Sorai object and the types its methods take and return. The custom elements are described in Custom elements.

SoraiApi

window.Sorai: the runtime's whole JavaScript API.

Sorai.init()

Sorai.init(config: SoraiInitConfig): void

Configures the runtime. Call it once, before anything else. It records first-touch attribution, loads the configured pixels and sends a PageView for the page named by window.SORAI_PAGE_ID.

Sorai.checkout()

Sorai.checkout(options: CheckoutOptions): void

Opens checkout for a product: in a modal over the page on a viewport 768px or wider, or by navigating to checkout on a narrower one. Sends InitiateCheckout once per product per tab session.

Sorai.track()

Sorai.track(name: string, props?: Record<string, unknown>): void

Sends an event to Sorai and to every configured pixel. ViewContent and InitiateCheckout with a product_id prop are deduplicated per product; any other name is a custom event.

Sorai.product()

Sorai.product(id: string): Promise<SoraiProduct | null>

Fetches one product with the publishable key. Resolves to null when the store has no active product with that id, and rejects when the request fails.

SoraiInitConfig

What Sorai.init() takes.

PropertyTypeDescription
storeIdstringThe store's id.
storeSlug?stringThe store's slug. When set, checkout links name the store by slug instead of by id.
publicKeystringThe store's publishable key (spk_...). Safe in page source; never put a secret key here.
apiBasestringBase URL of the Sorai API, with no trailing slash.
checkoutBasestringBase URL of the Sorai checkout.
currency?stringThe store's default currency (ISO 4217). <sorai-price> renders the price row matching it unless the element overrides with a currency attribute. Omitted, the element falls back to the product's first price row.
locale?stringThe store's locale, used to format prices. Omitted, the browser's wins.
pixels?PixelsConfigThe ad and analytics tags to load.

PixelsConfig

Ad and analytics tags the runtime loads and forwards every event to.

PropertyTypeDescription
metaPixelId?stringMeta Pixel id.
tiktokPixelId?stringTikTok Pixel id.
ga4Id?stringGoogle Analytics 4 measurement id, such as G-ABC123.
gtmId?stringGoogle Tag Manager container id, such as GTM-XXXX.

CheckoutOptions

What Sorai.checkout() takes.

PropertyTypeDescription
productIdstringThe product to buy.
priceId?stringThe price to charge, which picks the currency. Omitted, the store's default currency is used.
quantity?numberHow many to buy. Default: 1.
fields?Record<string, string>Values for the store's hidden checkout fields, keyed by field key, such as { campaign: "spring" }. They come back in the order's custom_fields; keys the form does not have are dropped. The buyer can change them, so never use them to identify a user: open a checkout session from your server for that.

SoraiProduct

A product as Sorai.product() returns it. The fields below are always there; any other field the API returns comes through as it is.

PropertyTypeDescription
idstringThe product id.
slugstringThe product's slug, the last segment of its page URL.
namestringThe product's name.
descriptionstringThe product's description.
pricesSoraiPrice[]One price per currency the product sells in.

SoraiPrice

One price of a product. A product has one price per currency, and Sorai never converts between them.

PropertyTypeDescription
idstringThe price id, to pass as priceId to Sorai.checkout().
currencystringISO 4217 currency code.
amount_minornumberThe amount in the currency's minor units: 149000 in IDR is Rp 149.000, 1900 in USD is $19.00.
kind?stringone_time or recurring.
pay_what_you_want?booleanTrue when the buyer chooses what to pay.
min_minor?number | nullThe lowest amount a buyer may pay, in minor units, when pay_what_you_want is true.

On this page