๐ผ๏ธGallery Integration
It's as easy as walking! The Variant Integration Feature allows you to dynamically switch product variants by sending predefined trigger values to the embedded iFrame using postMessage.
Final Result ๐

Integration Example
Step 1: Add the Mazing Script to the <head> Element
<head> ElementTo enable the Mazing Viewer, include the following script in the <head> element of your HTML. This script initializes the library and prepares your website for the 3D experience.
Note: The defer attribute ensures the script is loaded after the HTML document is parsed, optimizing page performance.
Step 2: Add Your Custom Script at the End of the <body>
<body>Create a new script at the end of the <body> element. This script contains the logic to load and customize your 3D experience.
Step 3: Fill in Your Script Logic
In this step, youโll add the main logic to initialize the Mazing Viewer. Copy and paste the following code into your script file or the <script> element you created earlier (for non-Shopify users).
Whatโs Happening?
The
waitForMazingFunctionensures that themazingProjectAvailablefunction is fully loaded before you execute your custom script.Once everything is ready, the script logs
Mazing configuration is active :)to confirm successful initialization.
Step 4: Get SKU and Create an iFrame
Next, youโll use mazingProjectAvailable() to retrieve the iframeSrc for the Mazing Viewer. This function fetches the SKU (Stock Keeping Unit) of the current product and initializes the viewer.
Whatโs Happening?
Retrieve the SKU: The
getSKUfunction extracts the SKU from the product URL using a regular expression. For example, a URL likehttps://example.com/products/your-productwill returnyour-productas the SKU.Generate the iFrame Source: The
mazingProjectAvailablefunction uses the SKU to create theiframeSrc, which is needed to display the Mazing Viewer.Use the iFrame Source: After generating the
iframeSrc, you can use it to embed the viewer on your website.
Once you have the iframeSrc, customize and append it to your website as needed. See the Script Integration Documentation for more details.
Step 5: Create the iFrame Using the iframeSrc
iframeSrcUse the iframeSrc to dynamically generate the iFrame and embed it into your website. Here's an example script that shows how you can achieve this:
The script dynamically creates an iframe element, assigning it the necessary attributes and styles to embed the Mazing Viewer seamlessly into your website.
The display: none style is applied by default to hide the iFrame, preventing any visual glitches or flickering when no product is available. This behavior ensures a smooth user experience but can be customized to fit your specific requirements.
By default, the example assumes that the iframe will be embedded into a div element with the ID gallery-div1. You can replace this ID with the appropriate container ID for your setup.
Step 6: Use postMessage to Switch Between Variants
Now itโs time to use the ID/Trigger defined for each variant. This will allow you to switch between different product variations using your own custom user interface.

For example, if you have a dropdown menu for selecting variations, you can listen for a userโs selection and send a postMessage to the Mazing Viewer. Letโs assume your dropdown menu has the ID operations-dropdown.
Hereโs how you can implement this logic:
When an option in the dropdown is clicked, the script sends a postMessage to the Mazing Viewer. The trigger value in the message corresponds to the variantโs ID/Trigger, which you defined earlier during variant creation. See -> Variant Operations
For instance:
Clicking the "All-Black" option sends a trigger value of
"all-black".This value activates the variant with the corresponding ID/Trigger.
Step 7 (optional): Model Loaded / Model Visibility
Sometimes you need to delay certain actions until the 3D model is fully loaded. This is because the MODEL_3D_LOADED event ensures that the viewer is ready to receive commands via postMessage. For example, if you have pre-selected variants you want to apply automatically, calling them too early may be overwrittenโright after the model finishes loading, the first variant is always applied as the original state. To avoid this, wait for the MODEL_3D_LOADED event before sending your variant selection, and optionally add a short delay to ensure that the initial state has been set before applying your changes.
Once the 3D model has finished loading, an action is sent to notify you:
window.top.postMessage({
type: 'MODEL_3D_LOADED',
value: {
model: model
},
}, '*');
Here's an example of how you can check for the model loading and set up your environment:
Create and Send Your Variant
Creating the Variant: This step demonstrates how to define a variant, such as "all-black," within your configuration.

Sending the PostMessage:
Send a postMessage with the trigger value 'all-black' from your shop website to switch between product variants.

Congratulations! You've successfully integrated your first configurator into your website! ๐
Last updated