Foot Sizing Without a Product
You can use StrutFit to measure a shopper's feet and get the result back in your own code, without a product or a StrutFit size button. Your own button opens the assistant, the shopper does a foot scan or answers the usual size questions, and StrutFit sends you their foot measurements in an event. What you do with them next is up to you, for example showing your own size recommendation or saving them to the shopper's account.
How it works
- Load the Assistant Manager script.
- When the shopper clicks your button, call
window.StrutFit.openAssistant('sizing:footwear'). - The shopper completes a foot scan or the usual size questions. The assistant ends on a screen showing their measurements.
- StrutFit dispatches
strutfit:footMCodeUpdatedonwindowwith the measurements inevent.detail. - Optionally, close the assistant yourself with
window.StrutFit.closeAssistant().
Foot sizing must be turned on for your organization, either foot scanning or usual size. Contact StrutFit if it isn't.
Add the Assistant Manager
<script
src="https://store-assistant-assistantmanager.strut.fit"
async
data-organization-id="{{OrganizationId}}"
></script>See Assistant Manager Options for the other attributes, such as data-language.
Open foot sizing from your button
Call openAssistant with the 'sizing:footwear' mode. It doesn't take a product code.
document.querySelector('#find-my-size').addEventListener('click', () => {
window.StrutFit?.openAssistant('sizing:footwear');
});window.StrutFit is only usable once the Assistant Manager has loaded, so we recommend keeping your button hidden or disabled until StrutFit is ready and foot sizing is enabled:
function onStrutFitReady(callback) {
if (window.StrutFit?.ready) {
callback();
return;
}
window.addEventListener('strutfit:ready', callback, { once: true });
}
onStrutFitReady(() => {
window.StrutFit.isModeEnabled('sizing:footwear').then((enabled) => {
document.querySelector('#find-my-size').disabled = !enabled;
});
});Options
openAssistant takes an optional third argument. Pass undefined as the product code to use it.
audience—'unisex','mens','womens'or'kids'. For example,'kids'shows the kids foot scan instructions.defaultFootwearSizeUnit— The size unit to start the usual size questions in, for example'US'or'EU'.
window.StrutFit?.openAssistant('sizing:footwear', undefined, {
audience: 'kids',
defaultFootwearSizeUnit: 'US',
});Listen for the result
strutfit:footMCodeUpdated fires when the shopper's foot measurements change. event.detail contains:
| Field | Type | Description |
|---|---|---|
mCode | string | null | The shopper's StrutFit measurement code |
leftLength | number | Length of the left foot, in millimetres |
leftMaxWidth | number | Widest point of the left foot, in millimetres |
rightLength | number | Length of the right foot, in millimetres |
rightMaxWidth | number | Widest point of the right foot, in millimetres |
longestFootLength | number | Length of the longer foot, in millimetres |
longestFootMaxWidth | number | Widest point of the longer foot, in millimetres |
Any measurement can be undefined if it isn't available, for example when the measurements couldn't be loaded. Most integrations only need longestFootLength and longestFootMaxWidth, since shoes are sized to the longer foot.
window.addEventListener('strutfit:footMCodeUpdated', (event) => {
const { mCode, longestFootLength, longestFootMaxWidth } = event.detail;
if (!mCode) {
return;
}
// Use the measurements on your site
});This event isn't only fired at the end of your flow. It also fires with mCode: null when the
shopper's measurements are cleared, for example when they sign out, and with their saved
measurements when a shopper signs in to their StrutFit account. Ignore null codes, and if you
only want results from the flow you opened, only act on the event while the assistant is open (see
below).
Close the assistant after the result
By default the assistant stays open on the measurements screen until the shopper closes it. To close it yourself once you have the result, call window.StrutFit.closeAssistant(). It closes the assistant the same way the shopper would, and dispatches strutfit:assistantClosed. It does nothing if the assistant isn't open.
Track whether foot sizing is open with strutfit:assistantOpened and strutfit:assistantClosed, so you only use and close on results from the flow you started:
let footSizingOpen = false;
window.addEventListener('strutfit:assistantOpened', (event) => {
footSizingOpen = event.detail.mode === 'sizing:footwear';
});
window.addEventListener('strutfit:assistantClosed', () => {
footSizingOpen = false;
});
window.addEventListener('strutfit:footMCodeUpdated', (event) => {
const { mCode, longestFootLength, longestFootMaxWidth } = event.detail;
if (!footSizingOpen || !mCode) {
return;
}
window.StrutFit.closeAssistant();
// Use the measurements on your site
});If you'd rather the shopper briefly sees their measurements before it closes, wrap closeAssistant in a setTimeout.
strutfit:assistantClosed also fires when the shopper closes the assistant before finishing, so you can use it to handle a shopper who gives up partway through.
Full example
<head>
<script
src="https://store-assistant-assistantmanager.strut.fit"
async
data-organization-id="{{OrganizationId}}"
></script>
</head>
<body>
<button id="find-my-size" disabled>Find my size</button>
<script>
const button = document.querySelector('#find-my-size');
let footSizingOpen = false;
function onStrutFitReady(callback) {
if (window.StrutFit?.ready) {
callback();
return;
}
window.addEventListener('strutfit:ready', callback, { once: true });
}
onStrutFitReady(() => {
window.StrutFit.isModeEnabled('sizing:footwear').then((enabled) => {
button.disabled = !enabled;
});
});
button.addEventListener('click', () => {
window.StrutFit?.openAssistant('sizing:footwear');
});
window.addEventListener('strutfit:assistantOpened', (event) => {
footSizingOpen = event.detail.mode === 'sizing:footwear';
});
window.addEventListener('strutfit:assistantClosed', () => {
footSizingOpen = false;
});
window.addEventListener('strutfit:footMCodeUpdated', (event) => {
const { mCode, longestFootLength, longestFootMaxWidth } = event.detail;
if (!footSizingOpen || !mCode) {
return;
}
window.StrutFit.closeAssistant();
console.log('Foot measurements (mm):', longestFootLength, longestFootMaxWidth);
});
</script>
</body>If you use TypeScript, see TypeScript for the window.StrutFit types.