Kiwi Sizing Developer Docs

Kiwi Sizing Developer Docs

    ›Getting Started

    Getting Started

    • Product Page JS Integration

    How do I install on

    • BigCommerce: Stencil-based themes
    • WooCommerce
    • Magento 2
    • Shopify
    • Volusion
    • 3dcart
    • PrestaShop
    • OpenCart
    • PinnacleCart
    • ZenCart

    Shopify

    • Integration with other Shopify Apps
    • Integration with mobile app builders

    Product Page JS Integration

    Here you will find the documentation for setting up Kiwi Sizing script on your product pages. Note that if you installed the Shopify app, the script is automatically set up and you do not need to follow this guide.

    Integrating the Javascript snippet

    Integrate the script

    First thing you need to do is include the following script on your product page. You can add it right after the </body> close tag.

    <!-- KiwiSizing v1.0.0 Integration !-->
    <script>
    !function(t,n,s,e,i){function r(t){try{var s="; "+n.cookie,e=s.split("; "+t+"=");if(2==e.length)return e.pop().split(";").shift()}catch(i){}return null}t[i]=t[i]||{},t[i]._queue=[];const o="on setShopID setUserID setUserEmail setLanguage loadSizing".split(" ");for(var a=0;a<o.length;a++){const c=o[a];t[i][c]=function(){var n=Array.prototype.slice.call(arguments);return n.unshift(c),t[i]._queue.push(n),t[i]}}const l=r("_ks_scriptVersion")||t.ks_version||"";var u=n.createElement(s);n=n.getElementsByTagName(s)[0],u.async=1,void 0!==t.ks_load_async&&(u.async=t.ks_load_async),u.src=e+"?v="+l,u.id="ks-integration",n.parentNode.insertBefore(u,n)}(window,document,"script","https://cdn.static.kiwisizing.com/SizingPlugin.prod.js","ks");
    </script>
    <!-- End KiwiSizing Integration !-->
    

    Load size charts

    After the script is added, a global ks object becomes available on the page. You would need to call a few functions to properly load the size charts and recommenders on the product page.

    ks.setShopID("KIWI_SIZING_SHOP_ID");
    
    // if user is logged in
    ks.setUserID("USER_ID");
    
    ks.loadSizing({
      productData: PRODUCT_DATA, // (required) see below
      options: LOADING_OPTIONS, // (optional) see below
    });
    
    

    Product data object (required)

    Product data is used by the app to check against the product matching conditions of all the size charts in the app to decide which size charts to display on the product page.

    • Fields marked with * are required
    KeyValue typeExample Values
    productID*String"12345"
    tagsArray<String>["t-shirt", "male"]
    skuString"S12-GET-RS"
    categoriesArray<String>["dresses", "wedding"]
    brandString"Nike"
    title*String"Modern Skinny-fit Washable Turtleneck Sweater"
    images*Array<String>["https://example.com/image1.jpg", "https://example.com/image2.jpg"]

    Loading option object (optional)

    Passing this object is optional and you likely won't need it. All the loading options here is configurable through the app settings. Any options set here would override the app settings. Generally you only need to override the options if you're doing something special on the product page.

    Note that all of these are options you can set in the app's settings. Passing those data in JS will override the app settings values.

    KeyValue typeExample Values
    injectionSelectorCSS Selector".size-chart-wrapper" or "#size-chart-wrapper"
    displayMode0 for Inline
    1 for link modal
    2 for button modal
    0
    injectionOrder0 for inject before
    1 for inject after
    2 for inject at the beginning of
    3 for inject at the end of
    0
    calculatorDisplayModesame as displayMode0
    calculatorInjectionOrdersame as injectionOrder0
    modalHeaderTextString"Size Chart Header"
    modalSubHeaderTextString"Size Chart Subheader"
    buttonTextString"Size Chart"
    buttonIconString"Nike"

    Event listening

    It is often useful to listen for events from our app so that you can trigger your own analytics or perform other behaviors on product page.

    ks.on("EVENT_NAME", function(data) {
      console.log("Event is triggered", data);
    });
    
    Event NameDescriptionCallback data
    sizing_loadedTriggered when the size chart is finished loading after calling ks.loadSizing{sizeChartID: 123}
    modal_openTriggered when modal is opened{modalID: "modal-id-123"}
    modal_closeTriggered when modal is closednone
    modal_tab_changeTriggered when modal tab is changed{tabID: "size-chart-layout"}

    or

    {tabID: "recommender"}
    on_size_recommendationTriggered after user uses the recommender{status: "has_size", size: "M"}

    or

    {status: "no_size"}
    on_add_to_cartTriggered when the add-to-cart button from the recommender is triggered. This is important if you want the app to be able to dynamically add the recommended product to cart{size: "M"}

    FAQ

    Asynchronous script loading

    The KiwiSizing script is by default loaded asynchronously, meaning that it will wait for the content on the product page to load first. However, the ks object is immediately available to be called.

    If you wish for the script loading to be done synchronously, please do the following before the kiwi script:

    window.ks_load_async = 1;
    
    // load kiwi script
    
    BigCommerce: Stencil-based themes →
    • Integrating the Javascript snippet
      • Integrate the script
      • Load size charts
      • Product data object (required)
      • Loading option object (optional)
      • Event listening
    • FAQ
      • Asynchronous script loading