~15KB gzipped

JavaScript Widget

Add virtual try-on to any website with a single line of code. No coding required.

Overview

The WillItFit Widget is a lightweight, self-contained JavaScript module that automatically detects product images on your website and adds a "Try On" button overlay. When users click the button, a modal opens where they can upload their photo and see the virtual try-on result.

~15KB
Gzipped size
0
Dependencies
<1s
Load time

Installation

Add the following script tag to your website, ideally before the closing </body> tag:

One-line Integrationhtml
<script src="https://cdn.willitfit.ai/widget.js" data-api-key="YOUR_API_KEY"></script>

That's it! The widget will automatically detect product images on your page and add the "Try On" button. Replace YOUR_API_KEY with your actual API key from your dashboard.

Configuration Options

Customize the widget behavior using data attributes on the script tag:

Advanced Configurationhtml
<script 
  src="https://cdn.willitfit.ai/widget.js"
  data-api-key="YOUR_API_KEY"
  data-theme="#6366f1"
  data-button-text="Virtual Try-On"
  data-position="bottom-left"
  data-modal-width="520"
  data-locale="en"
></script>
AttributeTypeRequiredDefaultDescription
data-api-keystringRequired-Your WillItFit API key
data-themestringOptional#10b981Primary theme color (hex)
data-button-textstringOptionalTry OnText displayed on the button
data-positionstringOptionalbottom-rightButton position: top-right, top-left, bottom-right, bottom-left
data-selectorstringOptionalauto-detectCSS selector for product images
data-modal-widthnumberOptional480Modal width in pixels
data-localestringOptionalenLanguage code: en, es, hi

Customization

Match the widget to your brand by setting a custom theme color:

#10b981
#6366f1
#f43f5e
#f59e0b
<!-- Green theme (default) -->
<script src="https://cdn.willitfit.ai/widget.js" data-api-key="KEY" data-theme="#10b981"></script>

<!-- Purple theme -->
<script src="https://cdn.willitfit.ai/widget.js" data-api-key="KEY" data-theme="#6366f1"></script>

<!-- Rose theme -->
<script src="https://cdn.willitfit.ai/widget.js" data-api-key="KEY" data-theme="#f43f5e"></script>

Localization

The widget supports multiple languages. Set the language using the data-locale attribute:

Englishen
Button text: Try On
Spanishes
Button text: Probar
Hindihi
Button text: आज़माएं
<!-- Spanish -->
<script src="https://cdn.willitfit.ai/widget.js" data-api-key="KEY" data-locale="es"></script>

<!-- Hindi -->
<script src="https://cdn.willitfit.ai/widget.js" data-api-key="KEY" data-locale="hi"></script>

JavaScript API

For advanced use cases, you can interact with the widget programmatically:

JavaScript APIjavascript
// The widget exposes a global API after loading
const widget = window.WillItFitWidget;

// Get version
console.log(widget.version); // "1.0.0"

// Create a new widget instance with custom config
const customWidget = widget.create({
  apiKey: 'YOUR_API_KEY',
  theme: '#6366f1',
  selector: '.my-custom-product-images',
  position: 'top-right',
  onTryOnComplete: (result) => {
    console.log('Try-on result:', result);
    // Send to analytics, etc.
  }
});

Platform Integration Guides

Shopify
Add to your Shopify theme with app blocks.
WooCommerce
Add to your WordPress/WooCommerce store.
Magento
Integrate with Adobe Magento stores.
Custom Platform
Use the widget on any custom website.