#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
#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_*.
Add the iframe
Place it where the widget should appear. It stays idle until your page sends an open command.
URL parameters
keystringRequiredYour public key from the dashboard.
parent_originstringOptionalYour page origin. Add it only if your site strips the referrer.
Products and experiences are chosen with postMessage, never in the URL.
Open the widget
Send open once the iframe has loaded, and hide your own UI when the shopper closes it.
#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 ofYour product SKU. Send this or
model_id.model_idstringOne ofThe catalog model ID. Send this or
sku.
Examples
Try-on (camera)
3D viewer
Switch product (widget already open)
Send open again with another sku or model_id. The product changes in place, without a new session.
#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
closetrueRequiredCloses the widget. Also received when the shopper dismisses it.
Example
#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.
loadingbooleantrue while the widget is busy, false when it is not.
Examples
Show your loader
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.
#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_fitReceiveThe widget is starting. Reply with
makemetryon_fit.makemetryon_fitSendYour reply.
payloadholds ipd (the PD in millimetres) andface_shape: Oval, Round, Square or Heart, in any case.makemetryon_set_fitReceiveThe measurement changed. Save
payload. Withreplace: true, overwrite the stored data entirely.makemetryon_clear_fitReceiveThe shopper tapped reset. Clear the stored data.
Example
#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.
