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
|
- 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 && 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
|
|||||||||||||||||
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");
trackClickJumpLink()
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()