Block-specific storefront methods exposed by the Measura product block runtime.
These methods are only available when at least one Measura product block has been rendered and initialized on the page.
They are exposed by the Measura product block runtime and are intended for theme code that needs to coordinate mounted Measura blocks.
if (window.Measura?.getRegisteredProductIds) {
const productIds = window.Measura.getRegisteredProductIds();
console.log(productIds);
}| Method | Async | Description |
|---|---|---|
| setVariant(payload) | No | Programmatically switch the selected variant for a mounted Measura product block. |
| getRegisteredProductIds() | No | Return the Measura product IDs currently registered by the block runtime. |
| addEventListener(eventName, callback, options?) | No | Subscribe to block runtime events such as Measura-managed variant changes. |
| removeEventListener(eventName, callback, options?) | No | Unsubscribe a previously registered block runtime event listener. |
window.Measura.setVariant(payload)Programmatically switch the selected variant for a mounted Measura product block.
{ variantId?: string | number; source?: string } | string | number{ handled: boolean; reason?: string; variantId?: string; productId?: string }Usage note
Call this method only after the target Measura product block has mounted and registered itself with the runtime.
window.Measura.getRegisteredProductIds()Returns the set of Measura product IDs currently registered by the block runtime.
voidstring[]const productIds = window.Measura.getRegisteredProductIds();
if (productIds.includes("9904458072362")) {
// Safe point to coordinate with the mounted block.
}window.Measura.addEventListener(eventName, callback, options?)Subscribe to block runtime events such as Measura-managed variant changes.
eventName: string
callback: (detail: unknown) => void
options?: { productId?: string | number }voidListener lifecycle
Keep a stable callback reference if you also plan to remove the listener later with removeEventListener.
window.Measura.removeEventListener(eventName, callback, options?)Unsubscribe a previously registered block runtime event listener.
eventName: string
callback: (detail: unknown) => void
options?: { productId?: string | number }voidfunction handleMeasuraEvent(event) {
console.log(event);
}
window.Measura.addEventListener("your-event-name", handleMeasuraEvent);
// Later:
window.Measura.removeEventListener("your-event-name", handleMeasuraEvent);