Script Setup
.hemsy-launcher when multiple elements should open Hemsy. Avoid reusing the same id on multiple elements.
Any element matching data-hemsy-selector becomes a Hemsy launcher. The launch behavior is decided per element from attributes on that exact clicked element.
Required Attributes
data-hemsy-subdomain: Your Hemsy store subdomain. Formystore.hemsy.ai, use"mystore".data-hemsy-selector: CSS selector for elements that should launch Hemsy.
Script Attributes Reference
| Attribute | Required | Example | Description |
|---|---|---|---|
data-hemsy-subdomain | true | "mystore" | Your Hemsy store subdomain. |
data-hemsy-selector | true | ".hemsy-launcher" | CSS selector for elements that launch Hemsy. |
data-hemsy-anonymous-id | false | "visitor-42" | Anonymous visitor ID passed through to Hemsy for analytics and order metadata. |
data-hemsy-mode | false | "instant" | Launch mode. Omit for the default interactive experience; set to "instant" for instant generation with a pre-selected model. |
data-hemsy-action | false | "cart" | Controls the final CTA behavior: "checkout" (default) opens Shopify checkout; "cart" sends variant data back to your site. Applies to all modes. |
onItemAdded, onItemRemoved, onProductVariantData), use window.HemsyEmbedConfig instead of data attributes. See the Event Callbacks section below.
Launcher Attributes
Attach these to any element matchingdata-hemsy-selector.
| Attribute | Example | Description |
|---|---|---|
data-hemsy-share | "<shareId>" | Opens a previously shared look by its short ID. Highest priority. |
data-hemsy-auto-product-context | "true" | Auto-builds a closet payload from the current PDP variant. Falls back to scratch if no variant is detected. |
data-hemsy-closet | "eyJwcm9k..." | Explicit URL-safe base64 closet payload. Use this for bundles or curated looks. |
data-hemsy-flow | "<flowId>" | Adds a guided flow to the launch. Must be on the clicked launcher element. |
data-hemsy-model | "<modelId>" | Model UUID for instant mode. Skips model selection and uses this model for generation. Copy the ID from the dashboard Models page. |
Launch Resolution
Evaluated per clicked element, in this order:- Instant (
data-hemsy-mode="instant"on the script +data-hemsy-modelon the element): instant generation with the specified model and closet payload. data-hemsy-share="<shortId>": share mode with that shared look.data-hemsy-auto-product-context="true": closet mode with a synthesized product payload, or scratch if no product variant is detected.data-hemsy-closet="<base64>": closet mode with that exact payload.- Nothing else: scratch mode (open the full interactive experience).
data-hemsy-flow composes with any of the above. A flow-only launcher opens scratch mode with the flow applied.
data-hemsy-action is orthogonal to launch resolution and controls only what the final CTA does (checkout or cart handoff).
Instant mode and share are not compatible on the same script tag. When
data-hemsy-mode="instant" is set on the script, share launchers do not work
— the share param is not forwarded to the iframe URL. If an element has both
data-hemsy-model and data-hemsy-share, instant wins and share is ignored.
Use default script mode for share buttons, or load separate script tags if you
need both instant and share launchers on the same page.Final Action
data-hemsy-action is set on the script tag and controls what happens when the customer taps the final result CTA. It applies to all modes (default and instant).
checkout(default): the CTA says “Go to Checkout” and Hemsy creates or opens a Shopify checkout/cart URL.cart: the CTA says “Go to Cart”, Hemsy postsPRODUCT_VARIANT_DATAto the parent page, callswindow.HemsyEmbedConfig.onProductVariantData(payload), and closes the modal.
cart when your storefront owns cart state and should add the returned variants itself.
data-hemsy-mode="cart" and data-hemsy-mode="checkout" are deprecated but
still supported for backward compatibility. Prefer data-hemsy-action
instead.Instant Mode
Instant mode bypasses model selection and immediately triggers image generation with a specific model and product closet. The customer sees the generation loading state and then the result.Setup
How It Works
- Set
data-hemsy-mode="instant"on the script tag. - Optionally set
data-hemsy-action="cart"to use cart mode instead of the default checkout. - On each launcher element, set
data-hemsy-modelto the model UUID (copied from the dashboard Models page) anddata-hemsy-closetto the product payload. - When the customer clicks the launcher, Hemsy opens the modal, loads the model image and products, and immediately starts generating the try-on image.
- After generation, the customer sees the result and can proceed to checkout or cart.
Getting Model IDs
Model IDs are UUIDs assigned to each model image in your store’s model library. To find them:- Go to your store’s Models page in the Hemsy dashboard.
- Hover over any model image.
- Click the copy icon in the bottom-left corner to copy the model ID to your clipboard.
Instant Mode with Cart Action
To combine instant mode with cart handoff (where your storefront manages cart state):Launcher Examples
Scratch Launcher
PDP Launcher
Flow Launcher
Closet Launcher
Share Launcher
Open a previously shared look directly:Instant Launcher
Skip model selection and immediately generate with a specific model:URL Parameter Auto-Open
The embed script automatically detects?share= and ?closet= URL parameters and opens the modal on page load:
- Share links: Customers can share their try-on results and recipients see the look immediately when they visit the link.
- Marketing campaigns: Pre-load products via URL parameters in ads or emails.
For SPAs using client-side routing, the embed script also intercepts
history.pushState to detect URL changes after initial page load.Closet Payload
| Field | Required | Type | Notes |
|---|---|---|---|
products | true | Array<object> | Must contain at least 1 product. |
products[].variantId | false | number | string | Preferred identifier and most reliable. |
products[].productId | false | number | string | Fallback identifier when variantId is unavailable. |
products[].attributes | false | Array<{ key: string; value: string }> | Optional line-item attributes passed through to checkout/cart create. |
variantId or productId.
Minimal Closet Payload Example
Resolution Rules
- Best: provide
variantIdfor each line item. - If
variantIdis missing, Hemsy falls back toproductId. attributesare preserved and passed to checkout line items or cart-mode callbacks.
URL-Safe Base64 Encoding
Hemsy expects URL-safe base64:- Replace
+with- - Replace
/with_ - Remove trailing
=
Always wrap
data-hemsy-closet values in quotes. URL-safe base64 strings can
contain = characters that will break unquoted HTML parsing.Programmatic API
If you’d rather open Hemsy from JavaScript, usewindow.HemsyEmbed:
mode on the script tag or window.HemsyEmbedConfig; it applies to every launch from that embed script.
Syncing Cart State
Listen for events from the Hemsy embed to sync with your cart state:Available Event Callbacks
| Callback | Payload | Description |
|---|---|---|
onItemAdded | { variantId: string, quantity: number } | Fired when item added to bag |
onItemRemoved | { variantId: string } | Fired when item removed from bag |
onProductVariantData | { items: Array<{ variantId: string, quantity: number, attributes?: Array<{ key: string, value: string }> }> } | Fired when action: "cart" and final CTA is clicked |
Hydrogen Example
Event callbacks fire immediately when items are added or removed from the bag
inside the Hemsy embed. The
variantId is the numeric Shopify variant ID as a
string, which you’ll need to convert to a GID format for Hydrogen’s cart
operations. With action: "cart", onProductVariantData fires when the final
“Go to Cart” button is clicked.End-to-End Example
End-to-End Example (Instant Mode)
Common Mistake
Do not usedata-hemsy-trigger:
data-hemsy-trigger is not a supported launcher configuration. Specify data-hemsy-selector on the script tag, then make the clickable element match that selector.
Use this instead for a flow: