Direct Webgj integration for Shopify

This guide outlines the process of integrating Webgj directly into Shopify using Dawn or related themes. Webgj replaces the default Google/Shopify Model Viewer on the product detail page (PDP) and provides high-quality rendering for jewelry and fashion products.
Advanced integration
For most Shopify stores, use the Mini Viewer SDK integration. It is the recommended integration and provides a stable, higher-level API for loading jewelix models, configurators, viewer UI, and Try-On features.
Continue with direct Webgj only when your team needs engine-level control and is prepared to own the viewer implementation and its maintenance.
Why use direct Webgj, and who is it for?
The Mini Viewer SDK is built on Webgj and covers the standard Shopify viewer workflow. It also exposes the underlying Webgj viewer through the jewelix-viewer-ready event, so needing occasional scene or camera customization is not, by itself, a reason to integrate Webgj directly.
Choose Mini Viewer SDK when you want:
- The recommended and supported path for a standard Shopify product page
- Built-in model loading from jewelix Drive or a project configuration
- Ready-made viewer UI, configurators, branding options, and Try-On integration
- A smaller integration surface and easier SDK upgrades
- Access to the underlying Webgj viewer only for selected customizations
Choose direct Webgj only when you have an experienced 3D/WebGL development team and need:
- Full ownership of viewer initialization, plugin setup, loading states, and lifecycle
- A completely custom interface or rendering pipeline that does not fit the Mini Viewer SDK
- Direct access to low-level Webgj APIs throughout the integration
- Support for an existing direct-Webgj implementation that you are maintaining or migrating
| Requirement | Recommended approach |
|---|---|
| Add an jewelix viewer to a Shopify PDP | Mini Viewer SDK |
| Load and configure models from jewelix Drive | Mini Viewer SDK |
| Customize a few camera, scene, or plugin settings | Mini Viewer SDK, then use jewelix-viewer-ready |
| Build and maintain a fully custom rendering architecture | Direct Webgj (this guide) |
| Maintain a legacy direct-Webgj Shopify theme | Direct Webgj (this guide) |
Prerequisites
- Access to your Shopify admin portal
- Basic understanding of Shopify theme structure
- Basic Familiarity with HTML, CSS, and JavaScript
- jewelix3D SDK Website License. Check out the license page for more details.
TIP
If you are looking for a development team for the integration, check our Development Partners
Step 1: Backup Your Theme
- Log in to your Shopify admin portal at https://admin.shopify.com/
- Select your store
- Navigate to
Online Store->Themesin the left menu - Locate your current theme and click on
Actions(three dots) ->Duplicate - This creates a backup of your theme in case you need to revert changes
Step 2: Access Theme Code
- Find your duplicated theme
- Click on
Actions->Edit code. This would open the Code Editor with the theme.
Step 3: Verify Existing Product Model Code
Themes include a file product-model.js that loads the default Google Model Viewer. We need to check that it exists and replace this code with the jewelix 3D Viewer.
- In the
Assetsfolder, locateproduct-model.js - Verify that it contains the following code.
- If you can't find this file, search for similar code in other JavaScript files
product-model.js
if (!customElements.get('product-model')) {
customElements.define(
'product-model',
class ProductModel extends DeferredMedia {
constructor() {
super();
}
loadContent() {
super.loadContent();
Shopify.loadFeatures([
{
name: 'model-viewer-ui',
version: '1.0',
onLoad: this.setupModelViewerUI.bind(this),
},
]);
}
setupModelViewerUI(errors) {
if (errors) return;
this.modelViewerUI = new Shopify.ModelViewerUI(this.querySelector('model-viewer'));
}
}
);
}
window.ProductModel = {
loadShopifyXR() {
Shopify.loadFeatures([
{
name: 'shopify-xr',
version: '1.0',
onLoad: this.setupShopifyXR.bind(this),
},
]);
},
setupShopifyXR(errors) {
if (errors) return;
if (!window.ShopifyXR) {
document.addEventListener('shopify_xr_initialized', () => this.setupShopifyXR());
return;
}
document.querySelectorAll('[id^="ProductJSON-"]').forEach((modelJSON) => {
window.ShopifyXR.addModels(JSON.parse(modelJSON.textContent));
modelJSON.remove();
});
window.ShopifyXR.setupXRElements();
},
};
window.addEventListener('DOMContentLoaded', () => {
if (window.ProductModel) window.ProductModel.loadShopifyXR();
});Step 4: Add jewelix Viewer Code
- Create a new file in the
Assetsfolder namedproduct-model-jewelix.js - Copy the following code into this new file.
- Save the file
product-model-jewelix.js
/**
* This file is an alternative of `product-model.js` on Shopify.
* It overloads the default model-viewer with the `webgj-viewer` from the jewelix3D SDK(https://jewelix3d.com).
* This file must be included in the theme manually, and referenced in the pages where product-model.js was used.
* Check the docs for more information and updates. - https://developer.jewelix3d.com/integrations/shopify
*
* File version - 26-07-2025
*/
// Settings for the jewelix3D SDK, this includes the webgj package version, environment maps etc.
// This can be set externally in the metafields or in the page where the product model is used, if not, the default settings will be used.
window.jewelixSDKSettings = {
webgj_version: "0.15.0",
scene_settings: "",
environment_map: "",
loading: {
loadingTextHeader: "Loading jewelix 3D Experience",
showFileNames: false,
backgroundOpacity: 0.5,
background: "#ffffff",
textColor: "#222222",
logoImage: "https://playground.jewelix3d.com/logo_black.png",
},
...(window.jewelixSDKSettings||{}),
}
// Create a custom model-viewer element that extends the HTMLElement, this will be used to load the jewelix3D SDK viewer.
// Note that it has to be made sure that this should be run before loading the google model viewer, since we cannot redefine an html element.
if(!customElements.get('model-viewer')){
const viewerScript = document.createElement('script');
viewerScript.setAttribute('src',
window.jewelixSDKSettings.webgj_version.includes('/') ? window.jewelixSDKSettings.webgj_version : // assume URL
'https://releases.jewelix3d.com/webgj/runtime/viewer-'+(window.jewelixSDKSettings.webgj_version||'0.9.19')+'.js'
);
document.head.appendChild(viewerScript);
//todo: fix for proper multiple viewer support.
let globalViewer = null; // to make sure we use only 1 viewer and canvas on a page,
customElements.define('model-viewer', class ModelViewerWebgj extends HTMLElement{
constructor() {
super();
const container = document.createElement('div')
this.container = container
this.container.style.width = "100%"
this.container.style.height = "100%"
this.appendChild(container)
this.modelLoaded = false;
this.initialize()
}
doOnLoad(fn){
if(this.modelLoaded) fn()
this.onLoad = fn;
}
async initialize(){
if(globalViewer) {
if(globalViewer === 1) return
this.viewer = globalViewer
this.viewer.scene.removeSceneModels()
}else {
globalViewer = 1;
this.viewer = new CoreViewerApp({container: this.container})
await this.viewer.initialize({caching: true, ground: true, bloom: true, enableDrop: false, importPopup: true, debug: false})
// ENCRYPTED_MODELS
// Uncomment this and set your password to load encrypted models.
// viewer.getManager().importer.registerFile("temp.glb").preparsers[0].key = (encryption, json)=> {
// // console.log(encryption, json);
// return "password";
// };
globalViewer = this.viewer;
this.viewer.canvas.style.width = "100%"
this.viewer.canvas.style.height = "100%"
}
const src = this.getAttribute('src')
let envMapPromise = null
this.refreshLoadingScreen()
if(window.jewelixSDKSettings.environment_map && window.jewelixSDKSettings.environment_map.length){
envMapPromise = this.viewer.getManager().importer.importSinglePath(window.jewelixSDKSettings.environment_map)
}
const modelPromise = this.viewer.load(src)
const [model, envMap] = await Promise.all([modelPromise, envMapPromise])
this.refreshLoadingScreen()
if(window.jewelixSDKSettings.scene_settings && window.jewelixSDKSettings.scene_settings.length){
await this.viewer.load(window.jewelixSDKSettings.scene_settings)
}
this.view = this.viewer.plugins.CameraViews.getCurrentCameraView()
this.refreshLoadingScreen()
if(envMap) this.viewer.scene.setEnvironment(envMap)
this.modelLoaded = true
// await timeout(200)
setTimeout(()=>{
if(this.onLoad) this.onLoad()
window.dispatchEvent(new CustomEvent('jewelix-viewer-loaded', {detail: this}))
}, 200)
}
refreshLoadingScreen(){
const loadingSettings = window.jewelixSDKSettings.loading ?? {}
const loadingPlugin = this.viewer.getPluginByType('LoadingScreenPlugin')
Object.entries(loadingSettings).forEach(([key, value])=>{
loadingPlugin[key] = value
})
}
resetView(){
if(!this.view || !this.viewer) return
this.viewer.plugins.CameraViews.animateToView(this.view, 500)
}
pause(){}
})
}
// Create a custom ProductModel element that extends the DeferredMedia element, this disables loading of google-model-viewer
if (!customElements.get('product-model')) {
customElements.define('product-model', class ProductModel extends DeferredMedia {
constructor() {
super();
const template = this.querySelector('template')
const viewer = template.content.querySelector('model-viewer')
delete viewer.dataset.shopifyFeature // disables loading of google model viewer script by shopify
const closeButton = document.createElement('div')
closeButton.className = 'deferred-media__close-button'
closeButton.innerHTML = '×'
Object.assign(closeButton.style, {
padding: '5px', position: 'absolute',
top: '0', right: '0', margin: '10px', zIndex: 101,
cursor: 'pointer',
borderRadius: '50%', lineHeight: '20px', fontSize: '16px',
display: 'flex', justifyContent: 'center', alignItems: 'center',
backgroundColor: 'rgb(var(--color-background))',
border: '.1rem solid rgba(var(--color-foreground), .1)',
color: 'rgb(var(--color-foreground))',
height: '28px',
width: '28px',
transform: 'scale(1)',
transition: 'transform var(--duration-short) ease, color var(--duration-short) ease',
});
closeButton.addEventListener('click', async () => {
if(this.modelViewer){
await this.modelViewer.resetView()
}
const poster = this.querySelector('.deferred-media__poster')
const posterButton = this.querySelector('.deferred-media__poster-button')
// const poster = document.querySelectorAll('.deferred-media__poster')[0]
// const posterButton = document.querySelectorAll('.deferred-media__poster-button')[0]
posterButton.style.display = 'flex'
poster.style.display = 'flex'
closeButton.style.display = 'none'
})
this.closeButton = closeButton;
}
loadContent() {
super.loadContent();
this.closeButton.style.display = 'flex'
const poster = this.querySelector('.deferred-media__poster')
poster.style.display = 'block'
poster.style.zIndex = 100;
const posterButton = this.querySelector('.deferred-media__poster-button')
posterButton.style.display = 'none'
const modelViewer = this.querySelector('model-viewer')
this.modelViewer = modelViewer; // used by the close button to reset the view
modelViewer.doOnLoad(()=>{
modelViewer.viewer.container.appendChild(this.closeButton)
poster.style.display = 'none'
})
}
setupModelViewerUI(errors) {
if (errors) return;
}
});
}
// Set a dummy ProductModel in the window, just in case
window.ProductModel = {
loadShopifyXR() {
},
setupShopifyXR(errors) {
if (errors) return;
},
};Loading Encrypted Models
Encryption can be used from the jewelix3D Playground to encrypt models, this protects your models from being downloaded and directly viewed in editors/viewers without a password.
To load encrypted models, uncomment the code block ENCRYPTED_MODELS in the initialize function and set the password in the key function. This will be used to decrypt the model before loading. The password can be based on the model/meta-field or a fixed global password.
Note that the password is added to the frontend javascript file. While this prevents non-technical users to easily extract the 3d file, experienced engineers can still extract it by reading the front-end code, and use it to decrypt and view the file. More strategies like obfuscation(and other techniques) can be used to further protect the password. This is very useful when using dynamic passwords for different models, since any bad actors would need to individually extract the password for each model.
Step 5: Update Theme Files
Next, we need to replace the reference of product-model.js with product-model-jewelix.js in the pages where the product model is used.
- Locate the files that reference the file, in the default theme(Dawn) this would be:
sections/main-product.liquidsections/featured-product.liquid- Any other relevant section files
- In each file, find the code block that loads the code. It should look similar to this:
{%- if first_3d_model -%}
<script type="application/json" id="ProductJSON-{{ product.id }}">
{{ product.media | where: 'media_type', 'model' | json }}
</script>
<script src="{{ 'product-model.js' | asset_url }}" defer></script>
{%- endif -%}- Replace the filename in the above code with
product-model-jewelix.jsand optionally get the settings from metafields and set asjewelixSDKSettingsglobal variable:
{%- if first_3d_model -%}
<script type="application/json" id="ProductJSON-{{ product.id }}">
{{ product.media | where: 'media_type', 'model' | json }}
</script>
{%- if shop.metafields.jewelix3d_settings -%}
<script>
var jewelixSDKSettings = {{ shop.metafields.jewelix3d_settings | json }};
</script>
{%- endif -%}
<script src="{{ 'product-model-jewelix.js' | asset_url }}" defer></script>
{%- endif -%}INFO
Note that this is enclosed in if first_3d_model block, this should already be present in the theme, and is done so that the script is only loaded once and when there is a 3d model in the product.
WARNING
There is also a reference to product-modal.js which is different, dont change that.
- Save all modified files
Step 6: Configure jewelix Settings (Optional)
To customize the jewelix viewer, the settings can be changed directly in the code for the file product-model-jewelix.js.
If you would prefer to change them from the admin panel without editing the code, Shopify metafields can be added to store the settings, which are accessed in liquid as in Step 5.3 above.
- Go to
Settings->Metafieldsin your Shopify admin - Create a new metafield for your shop with the namespace
jewelix3d_settings. (or pick your own) - Add your desired settings as a JSON object. (or individual)
- Save the metafield
- Update the code in the theme to read the meta-field and set the
jewelixSDKSettingsglobal variable. (see Step 5.3)
Example settings:
{
"webgj_version": "0.9.19",
"scene_settings": "",
"environment_map": "",
"loading": {
"loadingTextHeader": "Loading jewelix 3D Experience",
"showFileNames": false,
"backgroundOpacity": 0.5,
"background": "#ffffff",
"textColor": "#222222",
"logoImage": "https://playground.jewelix3d.com/logo_black.png"
}
}Step 7: Add 3D Models to Products
- Edit a product in your Shopify admin
- In the Media section, select Upload new
- Upload a GLB file
- Test model: Download Test Model
- Save the changes
Cover Image
Once the model is uploaded, Shopify automatically generates a preview image for it. You can replace the preview by opening the model and editing its cover image. Other model settings in Shopify are not used by this integration.
Note
- Shopify can store multiple 3D models on a product, but this sample integration supports one active 3D model per product.
- If a configurator appears over the model, the GLB probably contains configurator data. To remove it, use the jewelix3D Playground.
License
- An jewelix3D Evaluation Version logo will be shown along with a console warning if the jewelix3D SDK is not licensed.
- To remove this, you need to purchase a license from jewelix3D.
Step 8: Test the Integration
- Preview the product page with the 3D model and the theme.
- Verify that the jewelix viewer loads correctly and functions as expected
- Test on various devices and browsers to ensure compatibility
Troubleshooting
- If the viewer doesn't appear, check the browser console for JavaScript errors
- Ensure all file paths are correct in your theme files
- Verify that the uploaded 3D model is a GLB file
Next Steps
- Explore additional jewelix SDK features and integrate them as needed
- Check out other products at jewelix3D
Remember to thoroughly test your changes before pushing the updated theme live. Regularly check for updates to both the Shopify theme and the jewelix SDK to ensure compatibility and access to new features.
Contact
For any questions or assistance with the integration, or questions about the license, email us at [email protected],