Class: StyliticsClassicWidget

StyliticsClassicWidget(client, target, params)

new StyliticsClassicWidget(client, target, params)

Initialize a Classic widget object attached to a DOM element on your page. Afterward, when you are ready, call .start() on the object.
Parameters:
Name Type Description
client string The username given to you by Stylitics
target HTMLElement | string The HTML element within which you would like to render the Stylitics Widget. You can pass either the HTMLElement directly or a string that matches the id attribute of the element on your page.
params Object
Properties
Name Type Attributes Default Description
api Object
Properties
Name Type Attributes Default Description
item_number string <optional>
Identifier of the item corresponding to the current PDP page, typically a colorway-level ID. This item_number should be dynamically referenced in your code to reflect the item_number of the PDP/swatch the user has selected. If you do not supply a value for this field you must provide api.tags.
tags string <optional>
A comma separated tag string. Bundles will be returned that have been given those tags. If you do not supply a value for this field you must provide api.item_number.
max number <optional>
10 Maximum number of bundles to include in the widget
min number <optional>
1 Use this to change the bundle count threshold under which the widget is hidden completely. For instance, pass 3 if you never want to display the widget with bundle counts of two or one at any screen size.
from_accounts string <optional>
Filter bundle results to only return results from a specified list of Stylitics accounts. If you would like to supply multiple accounts please separate the account names with commas like: "some-account-women,some-account-children".
responsive Array.<Array> <optional>
See example
customer Object <optional>
Properties
Name Type Attributes Default Description
locale string <optional>
"en-US" If en-US is not correct, pass a different Unicode BCP 47 locale identifier string.
text Object <optional>
Properties
Name Type Attributes Description
viewDetailsCTA string <optional>
Override the default text "View details"
backToLookCTA string <optional>
Override the default "Back to Look"
itemLinkCTA string <optional>
Override the default text "SHOP"
seeMoreOptionsCTA string <optional>
Override the default Mix and Match text "See more options"
itemDetailsModalHeader string <optional>
Override the default text for the mobile item details modal
mnmClose string <optional>
Override the default text for the Mix & Match Expandable Shelf Close button
price Object <optional>
Properties
Name Type Attributes Default Description
roundingStyle "floor" | "ceiling" | "round" | "none" <optional>
"none" Default style is "none". "floor" would round down in every case no matter the decimal count. "ceiling" would round up in every case no matter the decimal count. "round" will round up when equal or greater than .50, and round down when equal or lesser than .49
hideDoubleZeroCents boolean <optional>
false Hide decimals that are .00
salesPriceStyle "strikethrough" | "sales-price-only" <optional>
"strikethrough"
navigation Object <optional>
Properties
Name Type Attributes Default Description
clickItemLinkDesktop "new-tab" | "same-tab" <optional>
"new-tab" Click on the shop button opens PDP in a new tab or same tab
clickItemLinkMobile "new-tab" | "same-tab" <optional>
"same-tab" Tap on the shop button opens PDP in a new tab or same tab
display Object <optional>
Properties
Name Type Attributes Default Description
clickableCarouselDots boolean <optional>
false Display carousel-advancement progress indicators (dots) on desktop
clickableCarouselAdvancementRate number <optional>
1 Set the amount of cards to scroll by: min = 1, max = columnCount
clickableCarouselNextItemPeek number <optional>
0 Set "peeking" visibility amount of the next (offscreen) carousel-item in pixels
clickableCarouselPreviousItemPeek number <optional>
0 Set "peeking" visibility amount of the previous (offscreen) carousel-item in pixels
swipeableCarouselNextItemPeek number <optional>
0.275 Set "peeking" visibility factor of the next (offscreen) mobile swipe gallery item from 0 to 1
clickableCarouselGutterWidth number <optional>
16 Set gutterWidth for the desktop.
swipeableCarouselGutterWidth number <optional>
16 Set gutterWidth for the mobile carousel.
swipeableCarouselLeftPadding number <optional>
0 Set the left-most item margin on mobile swipe gallery
bundleBackgroundColor string <optional>
"#fff" Set the bundle background color.
bundleProductList "slideout-on-click" | "product-list-on-click" | "product-list-on-hover" <optional>
"slideout-on-click" Set the product list appearance. Default - slideout-on-click
disableMnM boolean <optional>
Turns off Mix & Match functionality
trackingEnv string <optional>
Send tracking events to "production" or "staging." Defaults to "production" for backwards compatibility
display.swipeableCarouselDots boolean <optional>
false Allows for swipeable carousel dots on mobile
display.swipeableCarouselArrows boolean <optional>
false Allows for swipeable carousel arrows on mobile
display.clickableImageMnM boolean <optional>
false When MnM is enabled allows for bundle item images to click through replacements
display.productListMnM boolean <optional>
false When MnM is enabled allows displaying MnM as a product list
display.hideAnchorItem boolean <optional>
false Hide the anchor item from the product list
Source:
Example
let widgetInstance = new StyliticsClassicWidget("account-name", "stylitics-widget-container", {
  api: {
    item_number: "1234567",
    // other optional API Params
    // tags: "glam,preppy",
    // from_accounts: "demo-men",
    min: 3,
    max: 6,
  },
  display: {
    disableMnM: true,
  }
  // optional config to change default text labels
  // text: {
    // viewDetailsCTA: "Shop Now",
    // itemLinkCTA: "SHOP THIS",
    // example of locale-based text override:
    // itemDetailsModalHeader: {
      // "fr-CA": "Liste de produits"
    // }
  // },

  // IMPORTANT information about the following responsive breakpoints param:
  // These breakpoints are NOT based on viewport width but rather the width of the widget container.
  // Only uncomment this section of the config if you plan to change the responsive breakpoint defaults, otherwise you can remove this section.
  // responsive: [
  //   [0,    { columns: 1 }],
  //   [640,  { columns: 2 }],
  //   [1024, { columns: 3 }],
  //   [1280, { columns: 4 }],
  //   [1536, { columns: 5 }],
  // ]
})
// put calls to widgetInstance.on(...), widgetInstance.override(...) etc. here
widgetInstance.start()

Methods

destroy()

Remove the widget completely from the page, should you need to.
Source:

doNotTrack()

IMPORTANT: Clients should consult with their account managers before toggling these tracking functions, as it may impact analytics results.
Source:

on(action, subject, f)

Add a callback to be called for an event type, likely for customization or metrics purposes
Parameters:
Name Type Description
action "click" | "view" | "swap" | "mount" Choose one
subject "bundle" | "bundles" | "item" | "replacement" | "replacements" Choose one
f function callback function that will be called with relevant arguments when the event occurs
Source:
Example
// Valid action/subject pairs:
// "click", "bundle"
// "click", "item"
// "view", "bundle"
// "view", "item"
// "swap", "item"
// "mount", "item"
// "mount", "bundle"
// "mount", "bundles"
// "mount", "replacement"
// "mount", "replacements"
// "load", "widget" // Deprecated, use "mount", "bundles" instead
// "load", "replacements" // Deprecated, use "mount", "replacements" instead

widgetInstance.on("click", "item", function (data) {
  console.log("user clicked item:", data)
});

widgetInstance.on("mount", "bundles", function(data) {
  console.log("bundles response:", data.bundles)
});

*  // Important details regarding Stylitics callbacks
     // All stylitics callbacks must be placed in your code before the .start() method is called.

     // To avoid unexpected behavior, do not use multiple instances of the same action-subject pair. For example, you can not have multiple instances of .on("mount", "bundles",) in the code. You can, however, place multiple actions underneath one callback.
     // For example, if you need multiple actions to occur when the widget loads, such as showing the widget title, the jumplink, and checking for any Shop the Model bundles. You can nest all those actions underneath one .on("mount", "bundles",) callback.
     widgetInstance.on("mount", "bundles", function (data) {
        //Checking if outfits are returned and unhiding title and jumplink if so
        if (data.bundles &amp;&amp; data.bundles.length) {
           let jumplinkElement = document.getElementById("stylitics-jumplink");
           let titleElement = document.getElementById("widget-title");
           // unhide jumplink after widget has loaded
           jumplinkElement.style.visibility = "visible";
           // unhide widget title after widget has loaded
            titleElement.style.visibility = "visible";

        // Checking for bundles that should be tagged shop the model and applying the badge
        let bundle = data.bundle;
        let element = data.element;
        // add if statement to make sure badge is added to the correct bundles
        if (bundle["on-model-image"]) {
          //create image element
          let badge = document.createElement("img");
          // add relative path to the img
          badge.setAttribute("src", "../img/shop_the_look.jpg");
          //append img to the "stylitics-bundle-badge" div
          element.querySelector(".stylitics-bundle-badge").appendChild(badge);
    }
  });

// All callback methods must be added before the .start() method
widgetInstance.start();

override(action, subject, f)

Override the default behavior for an event type. For instance, use this to open a "quickview" on click.
Parameters:
Name Type Description
action "click" Only click behaviors can be overriden for now
subject "bundle" | "item" Choose one
f function function that will will be called instead of the default behavior for that action/subject trigger
Source:
Example
widgetInstance.override("click", "item", function ({ item, bundle }) {
  openQuickView(item);
})

refresh()

Reload the widget passing in new params. Often useful if you would like to switch to a new colorway ID.
Source:
Example
let newItemNumber = "426088032";
widgetInstance.refresh({ api: { item_number: newItemNumber } });

start()

Call after initialization and after any calls to .on or .override Starts the process of fetching outfits from Stylitics in order to populate the widget.
Source:
Example
widgetInstance.start();

trackAddItemToCart(event, priceopt)

Send a tracking event when a user adds an item to the cart. This method supports two ways of being called. The first is to provide a context object with an itemId property, and optional contextual data, like price, and uiComponent. This is the recommended way to use this function.
Parameters:
Name Type Attributes Description
event object
Properties
Name Type Attributes Description
itemId string | number
placement "main" | "widget" <optional>
price number <optional>
price number <optional>
Deprecated. Optionally add the price the user sees. Defaults to the sale_price or price of the item. The recommended approach is to pass price as an attribute on the AddToCartEvent argument.
Deprecated:
  • The second way is to provide the item id as the first argument and an optional price as the second argument.
Source:
Example
// recommended
widgetInstance.trackAddItemToCart({ itemId: "a1b2c3" })
widgetInstance.trackAddItemToCart({ itemId: "a1b2c3", price: 29.99 })
widgetInstance.trackAddItemToCart({ itemId: "a1b2c3", price: 29.99, uiComponent: "pdp" })

// deprecated
widgetInstance.trackAddItemToCart("a1b2c3");
widgetInstance.trackAddItemToCart("a1b2c3", 29.99);

trackClickItem(remoteId)

Send a tracking event when a user clicks on an item outside of the Stylitics Widget, for instance, in a "quickview".
Parameters:
Name Type Description
remoteId string The item, identifier typically a colorway-level ID. In our data this the field named `remote_id`
Source:
Example
widgetInstance.trackClickItem("13093805");
Send a tracking event when a user clicks a jumplink
Source:

trackViewItem(remoteId)

Send a tracking event when a user views an item outside of the Stylitics Widget, for instance, in a "quickview".
Parameters:
Name Type Description
remoteId string The item, identifier typically a colorway-level ID. In our data this is the field named `remote_id`
Source:
Example
widgetInstance.trackViewItem("13093805");

(static) info()

Print information about the widget to the browser console
Source:
Example
StyliticsClassicWidget.info()