Skip to main content

Start a New Configuration

This is step 1 of the lifecycle: a visitor starts a new configuration from a base product, identified by its productId. Typical places are product detail pages, collection pages and landing pages for a single model.

You load one script and mark up an HTML element with data-diva-* attributes. No JavaScript initialization code is required. The Configurator opens as a fullscreen overlay over your page. When the visitor closes it, your page is shown again.

The widget comes in two variants that differ only in how the Configurator is opened:

  • Button: the Configurator opens when a visitor clicks the element. This is the common case.
  • Direct: the Configurator opens automatically when the page loads. Useful for a dedicated configuration page that visitors reach via a link, e.g. from a campaign.

Step 1 – Add the Widget Element​

Place an element on the page and select the variant with the data-diva-widget-type attribute. The product to open is given in data-diva-param-productid.

Widget typeOpens the Configurator
diva-configurator-buttonwhen the visitor clicks the element
diva-configurator-directautomatically when the page loads
Important

Replace <PRODUCT_ID> with the ID of the product that should be opened in the Configurator.

tip

Products vary from page to page, so as a Best Practice the productId should be managed dynamically. Link the data-diva-param-productid value to a user-accessible field within your CMS (like WordPress), or fill it from the product your shop system is rendering. This allows team members to update products directly through the admin interface without ever touching the integration code.

Button​

Place the element anywhere on the page where you want customers to start configuring.

<div data-diva-widget-type="diva-configurator-button" data-diva-param-productid="<PRODUCT_ID>">
Configure product
</div>

Style the element with your own CSS, e.g. to make it look like a button. You can change the text to "Start Configuration", "Personalize Now", etc.

Direct​

The Configurator opens as soon as the widget script has loaded. The content of the element is visible once the Configurator is closed, so it can hold a short message or a link back to your shop.

<div data-diva-widget-type="diva-configurator-direct" data-diva-param-productid="<PRODUCT_ID>">
The Configurator opens automatically
</div>

Direct, inside your page​

By default the Configurator covers the whole browser window. To show it as part of your page instead, set data-diva-fullscreen="false" on a diva-configurator-direct element. The Configurator is then rendered inside this element and your page stays visible and scrollable around it.

<div
style="height: 700px"
data-diva-widget-type="diva-configurator-direct"
data-diva-param-productid="<PRODUCT_ID>"
data-diva-fullscreen="false"
></div>
Important

Give the element a height with your own CSS. The Configurator fills the element, so an element without a height shows nothing.

  • Leave the element empty, the Configurator is placed inside it.
  • The Configurator has no close button in this mode, so onWebPlanerClose is not triggered.
  • The Button variant always opens in fullscreen; data-diva-fullscreen has no effect there.

Step 2 – Load the Widget Script​

Include the widget script before the closing </body> tag, after the element from Step 1. Include it only once per page, it loads all widgets on the page.

Important

Replace <YOUR_ORGANIZATION_ID> with your organization ID.

<script src="https://<your-diva-api-host>/integration/api/widget/<YOUR_ORGANIZATION_ID>"></script>

That's it. The Configurator now opens in fullscreen mode, on click or on page load depending on the widget type.

Language​

The Configurator is available in German, French, Italian and English. Set the language with the data-lang attribute on the widget element:

<div data-diva-widget-type="diva-configurator-button" data-diva-param-productid="<PRODUCT_ID>" data-lang="fr">Configurer</div>
ValueLanguage
deGerman
frFrench
itItalian
enEnglish

Without data-lang, the widget uses the lang parameter of the widget script URL, then the lang attribute of your page (<html lang="fr">), then the language of the visitor's browser and finally German. See Language for details.

Style the fullscreen overlay​

By default the Configurator fills the whole browser window on a white background. With CSS variables you can leave a margin around it and set the background of that margin, e.g. to let your page shine through:

<div
data-diva-widget-type="diva-configurator-button"
data-diva-param-productid="<PRODUCT_ID>"
style="
--diva-container-background: rgba(15, 15, 15, 0.75);
--diva-container-padding: 48px;
--diva-mobile-container-padding: 16px;
"
>
Configure product
</div>

Set the variables on the widget element or on any parent, e.g. on :root in your stylesheet.

VariableDescriptionDefault
--diva-container-backgroundBackground of the overlay#fff
--diva-container-paddingSpace between the window and the Configurator0
--diva-mobile-container-backgroundBackground on mobile devicesvalue of --diva-container-background
--diva-mobile-container-paddingPadding on mobile devicesvalue of --diva-container-padding

The variables apply to the fullscreen overlay only. A Configurator rendered inside your page is styled through its own element.

Step 3 – React to Configurator Events (optional)​

The Configurator reports what the visitor does as events, e.g. closing the Configurator or adding the configured product to the cart. Depending on the event, it comes with data.

EventTriggered whenData
onWebPlanerClosethe visitor closes the Configuratornone
onAddToBasketthe visitor adds the configured product to the cartthe Configuration Object, see Add to Cart
onErroran error occurs in DIVA{ message, errorCode }
custom eventsthe visitor clicks a custom call-to-action button (see below)depends on the call to action

Closing is handled by the widget itself, so you only need onWebPlanerClose if you want to run your own code at that moment.

Call a function per event​

Name a global function in a data-diva-event-<event> attribute on the widget element. Write the event name in lowercase, e.g. data-diva-event-onaddtobasket for onAddToBasket. The widget calls the function with the data of the event.

<div
data-diva-widget-type="diva-configurator-button"
data-diva-param-productid="<PRODUCT_ID>"
data-diva-event-onaddtobasket="addToCart"
data-diva-event-onwebplanerclose="plannerClosed"
>
Configure product
</div>

<script>
function addToCart(detail) {
// The visitor added the configured product to the cart, see Add to Cart
}
function plannerClosed(detail) {
// The visitor closed the Configurator
}
</script>

The functions must be reachable on window, e.g. as window.addToCart. Declare them with function in a regular <script> or assign them to window (window.addToCart = …). Top-level const or let and functions in a module script (<script type="module">) are not on window.

Custom call-to-action buttons​

Besides the standard buttons, such as "Add to cart", Crystal Design can add custom call-to-action buttons to the Configurator for your project, e.g. "Request a quote" or "Book an appointment". Each custom button dispatches its own event. Crystal Design provides the event names, and you react to them like to any other event:

<div
data-diva-widget-type="diva-configurator-button"
data-diva-param-productid="<PRODUCT_ID>"
data-diva-event-<custom_event_name>="requestQuote"
>
Configure product
</div>

<script>
function requestQuote(detail) {
// e.g. open your own quote request form with the configuration
}
</script>

Complete Examples​

Button – full HTML page
<!doctype html>
<html>
<head>
<title>Configurator Button Widget</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
#configure-btn {
display: inline-block;
padding: 0.75rem 1.5rem;
background-color: #713434;
color: #fff;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div
id="configure-btn"
data-diva-widget-type="diva-configurator-button"
data-diva-param-productid="<PRODUCT_ID>"
data-diva-event-onwebplanerclose="plannerClosed"
data-diva-event-onaddtobasket="addToCart"
>
Configure product
</div>

<script>
function plannerClosed() {
alert('Configurator closed');
}
function addToCart() {
alert('Product added to cart');
}
</script>

<script src="https://<your-diva-api-host>/integration/api/widget/<YOUR_ORGANIZATION_ID>"></script>
</body>
</html>
Direct – full HTML page
<!doctype html>
<html>
<head>
<title>Configurator Direct Widget</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div
data-diva-widget-type="diva-configurator-direct"
data-diva-param-productid="<PRODUCT_ID>"
data-diva-event-onwebplanerclose="plannerClosed"
data-diva-event-onaddtobasket="addToCart"
>
The Configurator opens automatically
</div>

<script>
function plannerClosed() {
alert('Configurator closed');
}
function addToCart() {
alert('Product added to cart');
}
</script>

<script src="https://<your-diva-api-host>/integration/api/widget/<YOUR_ORGANIZATION_ID>"></script>
</body>
</html>

Attributes​

AttributeExampleDescriptionRequired
data-diva-widget-typediva-configurator-buttondiva-configurator-button (open on click) or diva-configurator-direct (open on page load)yes
data-diva-param-productidQ7vdOYy4g7y5cL4TVWaItThe product that is opened in the Configurator. The product must be stored in DIVA and be available in your organizationyes
data-diva-fullscreenfalseOnly for diva-configurator-direct: false renders the Configurator inside the element instead of fullscreen. Default true. See Direct, inside your pageno
data-langfrLanguage of the Configurator: de, fr, it or en. See Language for the fallback orderno
data-diva-event-<event>addToCartName of a global function that is called for this event, event name in lowercase. See Step 3no

Next step​

Visitors can save their configuration and receive a PDF with a link back to your website. Set up the page behind this link in Reopen a Saved Configuration.