Introduction
To enable secure two-way communication between the Viewer and your website, embedding must be authorized with a session token and initialized using a postMessage handshake.
Setup:
- In the Alter Product app, open the E-commerce Settings Embeding panel.
- Add the domain where the Viewer will be embedded (e.g. https://yourwebsite.com or http://localhost:3000) and save.
Flow:
- Your website loads the Viewer iframe.
- The iframe and your website perform a postMessage handshake (nonce).
- The iframe requests a session token from your website (
ALTER_TOOL_INIT_SESSION). - Your backend requests the token from Alter Product API and your website responds with
ALTER_TOOL_SESSION_READY. - Now you can send Viewer commands (e.g.
ALTER_VIEWER_GET_PRODUCT_DATA) and receive events (e.g.ALTER_VIEWER_DATA_RESPONSE).
You can also add metadata keys to each variant in the design — in the Product Configuration tab. These keys will be included in the Viewer payload.