Woman standing naturally while reading an open book

Developer docs

Virtual try-on integration documentation

Everything a developer needs to add Makemetryon virtual try-on, 3D viewers and measurement tools to any website.

The integration is one iframe, one public key and one postMessage API. There is no SDK to install, no build step and no backend work.

#Glasses & eyewear

Camera try-on and a 3D viewer for glasses and sunglasses. Pass the frame as sku or model_id. Fit data can follow the shopper between visits.

Before you start

  • A public key: create a project in the dashboard and copy its key.
  • Your domain, added in the dashboard. Its subdomains are included.
  • At least one model linked to your domain, opened by its SKU or model ID.

#API reference

openSendStart try-on or the 3D viewer for a product, or switch product.closeTwo-wayClose the widget, or hear that the shopper closed it.makemetryon_loadingReceiveFollow the busy state to drive your own loader.makemetryon_fitTwo-wayKeep the shopper's PD and face shape between visits.

#Installation

Two commands drive everything: open and close. open: 'vto' starts try-on and open: '3d' starts the 3D viewer. Events from the widget use type: makemetryon_*.

  1. Add the iframe

    Place it where the widget should appear. It stays idle until your page sends an open command.

    index.html
    <iframe
      id="makemetryon-iframe"
      src="https://widgets.makemetryon.com/?key=public_key_********"
      allow="camera; fullscreen"
      sandbox="allow-scripts allow-same-origin">
    </iframe>
    URL parameters
    • keystringRequired

      Your public key from the dashboard.

    • parent_originstringOptional

      Your page origin. Add it only if your site strips the referrer.

    Products and experiences are chosen with postMessage, never in the URL.

  2. Open the widget

    Send open once the iframe has loaded, and hide your own UI when the shopper closes it.

    storefront.js
    const iframe = document.getElementById('makemetryon-iframe')
    
    // The iframe stays idle until your page sends open
    // open: 'vto' = camera try-on, open: '3d' = 3D viewer
    iframe.addEventListener('load', () => {
      iframe.contentWindow.postMessage({ open: 'vto', sku: 'your_sku_code' }, '*')
    })
    
    // The shopper closed the widget: hide your own UI (do not send close back)
    window.addEventListener('message', (event) => {
      if (event.source !== iframe.contentWindow) return
      if (event.data?.close === true) modal.hidden = true
    })

#Commands

Send these from your page with iframe.contentWindow.postMessage().

#openSend

Pass the product as sku or model_id. The same product works in both modes, and shoppers can switch between them inside the widget.

Parameters
  • open'vto' | '3d'Required

    'vto' starts camera try-on. '3d' starts the 3D viewer.

  • skustringOne of

    Your product SKU. Send this or model_id.

  • model_idstringOne of

    The catalog model ID. Send this or sku.

Examples

Try-on (camera)

storefront.js
iframe.contentWindow.postMessage({ open: 'vto', sku: 'your_sku_code' }, '*')

// The same product by catalog model ID
iframe.contentWindow.postMessage({ open: 'vto', model_id: 'your_model_id' }, '*')

3D viewer

storefront.js
iframe.contentWindow.postMessage({ open: '3d', sku: 'your_sku_code' }, '*')

Switch product (widget already open)

Send open again with another sku or model_id. The product changes in place, without a new session.

storefront.js
iframe.contentWindow.postMessage({ open: 'vto', sku: 'another_sku_code' }, '*')

#closeTwo-way

Send close: true to close the widget from your page. The widget sends the same message when the shopper dismisses it. When you receive it, hide your own UI and do not send close back.

Parameters
  • closetrueRequired

    Closes the widget. Also received when the shopper dismisses it.

Example
storefront.js
// Close the widget from your page
iframe.contentWindow.postMessage({ close: true }, '*')

// The shopper closed the widget: hide your UI only
window.addEventListener('message', (event) => {
  if (event.source !== iframe.contentWindow) return
  if (event.data?.close === true) modal.hidden = true
})

#Events

Receive these with a message listener on the window.

Tip

Check event.source before handling a message, so your page only reacts to the widget.

#makemetryon_loadingReceive

Show your own loading animation: turn off Show loading animation in the dashboard settings, then follow this event. loading is true while the widget is busy and false when it is not. It is sent on every change, with the setting on or off.

Event fields
  • type'makemetryon_loading'

    Identifies the event.

  • loadingboolean

    true while the widget is busy, false when it is not.

Examples

Show your loader

storefront.js
window.addEventListener('message', (event) => {
  if (event.source !== iframe.contentWindow) return
  if (event.data?.type !== 'makemetryon_loading') return

  // event.data is { type: 'makemetryon_loading', loading: true | false }
  myLoader.hidden = !event.data.loading
})

Keep it in sync

This is not a one-time ready signal, so keep listening after the first false. loading turns true again whenever the widget opens, your page sends another open, the shopper switches between 3D and try-on, or a measurement starts. It is false while the shopper answers the camera prompt, so your loader never covers it. If the iframe reloads mid-load no final false arrives, so also hide your loader when the iframe loads.

storefront.js
// One product opened, then switched to another
{ type: 'makemetryon_loading', loading: true }   // opening
{ type: 'makemetryon_loading', loading: false }  // ready
{ type: 'makemetryon_loading', loading: true }   // switching product
{ type: 'makemetryon_loading', loading: false }  // ready again

#makemetryon_fitTwo-way

Glasses try-on only. Your page stores the shopper's fit data and the widget asks for it when it starts. The request times out after 3 seconds if your page does not answer.

Messages
  • makemetryon_get_fitReceive

    The widget is starting. Reply with makemetryon_fit.

  • makemetryon_fitSend

    Your reply. payload holds ipd (the PD in millimetres) and face_shape: Oval, Round, Square or Heart, in any case.

  • makemetryon_set_fitReceive

    The measurement changed. Save payload. With replace: true, overwrite the stored data entirely.

  • makemetryon_clear_fitReceive

    The shopper tapped reset. Clear the stored data.

Example
storefront.js
window.addEventListener('message', (event) => {
  if (event.source !== iframe.contentWindow) return

  const { type, payload } = event.data ?? {}

  // The widget is starting: send back what you stored
  if (type === 'makemetryon_get_fit') {
    iframe.contentWindow.postMessage({
      type: 'makemetryon_fit',
      payload: getStoredFit(), // { ipd: 63, face_shape: 'oval' }
    }, '*')
  }

  // The measurement changed: replace: true overwrites the stored data entirely
  if (type === 'makemetryon_set_fit') {
    saveFit(payload, event.data.replace)
  }

  // The shopper tapped reset
  if (type === 'makemetryon_clear_fit') {
    clearFit()
  }
})

#Security & sessions

Before going live

In production, replace "*" with the widget host origin and check event.origin before trusting a message.

Sessions and metering

Auth runs on open, not when the iframe loads. Try-on is metered as a VTO session; the 3D viewer is not. Switching products in an open widget does not start a new session. The first switch from 3D into try-on starts a VTO session for that product; switching back and forth after that does not.