Widget events

Your page can react to the size button: show the recommended size elsewhere, preselect it, or log it. Every event is sent in two ways from the same moment: as a DOM event, and to the callbacks you add with widget.on(...). Events are sent with or without the shopper's analytics consent, because they stay on your page.

Each event names its widget in instanceId (also widget.instanceId and the data-fmt-widget attribute), so pages with several buttons can tell them apart. No event carries body measurements or the shopper's tracking id.

createWidget(params)

The SDK's JavaScript API, for themes that render the button themselves: load sdk.js, then call window.FitMyType.createWidget(params). It resolves the widget, or undefined when nothing is shown (the product is not eligible, a value is invalid, or the visitor is held out). It never rejects. FitMyType.widget(instanceId) gives a rendered widget back later.

<div id="fmt-size-recommender"></div>
<script>
  window.FitMyType.createWidget({
    client_id: 1000,
    product_id: "TEST-JACKET-01",
    available_sizes: "S,M,L",
    language: "en",
    target: document.getElementById("fmt-size-recommender"),
  }).then(function (widget) {
    if (!widget) return; // not eligible or held out: nothing is shown
    widget.on("recommendation", function (size) { /* … */ });
  });
</script>
Params
KeyTypeDescription
client_id string | integer Our client id (E01). Required unless brand_id is given.
brand_id string | integer The brand id (D19); the client is looked up with GET /v1/brands/{brand_id}/client.
product_id required string | integer The merchant's product id, equal to the feed product_id.
language required string One of the 17 language codes, or a BCP-47 tag (en-GB, pt-BR).
available_sizes string | array of string | number | object S,M,L or [{name, in_stock?}].
product_image string Absolute URL of the product image; relative URLs are dropped.
text string | object Label, or {lang: label}.
button_text string Label (the buttonText attribute).
channel string Free text, e.g. web, app, retail.
shop_country string ISO 3166-1 alpha-2 or ww.
logoStyle "default" | "s" | "ruler" | "scale" | "none" Shopify JSON config name of logo; logo wins.
target required object Imperative only: the element the button renders into.
size_picker_root object Imperative only: the element, or a CSS selector, that holds the size picker for end_behavior (default: the widget's closest form).

DOM events

They are sent on the widget element, bubble and cross shadow roots, so one listener on document gets each event once.

fmtReady

Sent when the button is on the page. event.detail: instanceId, productId.

document.addEventListener("fmtReady", function (event) {
  // Your custom code goes here ...
  const instanceId = event.detail.instanceId;
  const productId = event.detail.productId;
});

fmtAutoRecommendation

Sent when a size answer arrives: on page load for a returning shopper (auto-reco) and after the size finder. event.detail: instanceId, productId, recommendedSize, status, closestSize, alternatives, directionHint, isAutoReco, available.

document.addEventListener("fmtAutoRecommendation", function (event) {
  // Your custom code goes here ...
  const instanceId = event.detail.instanceId;
  const productId = event.detail.productId;
  const recommendedSize = event.detail.recommendedSize;
  const status = event.detail.status;
  const closestSize = event.detail.closestSize;
  const alternatives = event.detail.alternatives;
  const directionHint = event.detail.directionHint;
  const isAutoReco = event.detail.isAutoReco;
  const available = event.detail.available;
});

fmtSizeSelected

Sent when the shopper chooses a size in the size finder. event.detail: instanceId, productId, size.

document.addEventListener("fmtSizeSelected", function (event) {
  // Your custom code goes here ...
  const instanceId = event.detail.instanceId;
  const productId = event.detail.productId;
  const size = event.detail.size;
});

fmtClose

Sent when the size finder closes, for any reason. event.detail: instanceId, productId, reason.

document.addEventListener("fmtClose", function (event) {
  // Your custom code goes here ...
  const instanceId = event.detail.instanceId;
  const productId = event.detail.productId;
  const reason = event.detail.reason;
});

fmtWidgetEnd

Sent when the shopper ends the size finder (once per opening). event.detail: instanceId, productId, recommendedSize, reason.

document.addEventListener("fmtWidgetEnd", function (event) {
  // Your custom code goes here ...
  const instanceId = event.detail.instanceId;
  const productId = event.detail.productId;
  const recommendedSize = event.detail.recommendedSize;
  const reason = event.detail.reason;
});

fmtWidgetEnd reasons

reasonWhen
closethe close button, or a swipe down on a phone
escthe Escape key
backdropa tap outside the panel
back_to_shoppingthe Back to shopping button
size_selecteda size was chosen (select-size or add-to-cart)

Size answer status

status is one of recommended, between_sizes, needs_measurements, no_match. recommendedSize is null unless the status is recommended. available says whether that size is on your page and in stock.

Callbacks

widget.on(name, callback) adds a callback to one widget and returns a function that removes it. An unknown name logs a warning. A callback that throws does not stop the others.

NameWhenPayload
readyat once (the button is already rendered)the button element
recommendation-fetcha size answer arrives{recommended_size, found, is_auto_reco, status, closest_size, alternatives, direction_hint, available, instanceId}
recommendationthe shopper chooses a size{name, …your size entry, status, instanceId}
validatethe shopper chooses a size (same as recommendation){name, …your size entry, status, instanceId}
closethe size finder closes{reason, instanceId}
widget-endthe shopper ends the size finder{name, reason, instanceId}
const widget = FitMyType.widget(instanceId); // or the widget createWidget() resolved
const off = widget.on("recommendation-fetch", function (payload) {
  // Your custom code goes here ...
});
// off() removes it again.