JS Doc

Current version: 0.3.5

Our You May Also Like widget provides an image based recommendation engine for your site. This widget presents the recommended results in a slick carousel format as shown below:



From CDN

You can directly place our script into your page header to access this widget:

<script type="text/javascript" src="//cdn.visenze.com/visearch/dist/js/components/Recommendation-0.3.5.bundle.js"></script>

Quick start

This quick start guide demonstrates how to load and initialize our ViSenze You May Also Like widget. This guide uses default options to initialize the SDK. However, you can also customize these options if you want to do so.

Get the example

To get the demo site source code that is built using our widgets:

git clone git@github.com:visenze/visearch-widget-javascript-examples.git

To integrate our You May Also Like widget:

  1. Place the element in your html body
  2. Initialize the widgets in javascript

We will guide you through the configuration of the widget using this demo site as an example.

Place the element

You can place the carousel anywhere in your html body by assigning an ID. In our example, we name the element ID as vs-recommendation which will be used in the initialization of the widget in the javascript. You can find this source code in src/index.html:

    <div class="container">

        <div class="col-xs-12 article-1"></div>
        <div class="col-xs-12" id="vs-recommendation"></div>
        <div class="col-xs-12 article-2"></div>


Initialize the widget

To get real data working in the example, you need to initialize the following code snippet. The customizable parameter object contains three sub-objects:

  • vsSettings: parameters to customize the search options

  • displaySettings: parameters for presentation

  • recommendationOpts: parameters of the product

You can find the following code snippet in src/js/recommend.js:

var vsSettings = {
  appKey: 'APP_KEY',
  fl: ["im_url", "price", "title", "product_url", 'brand', "discount_price"],
  limit: 15,
  detection: "all"

var displaySettings = {
  cardsToShow: 4,
  cardsToScroll: 4

var recommendationOpts = {
  imName: 'IM_NAME',
  productDetails: {
    heading: 'title',
    productUrl: 'product_url',
    label: 'brand',
    price: "price",
    discountPrice: "discount_price"
  addToCartHoverIcon: false,
  addToCartStaticIcon: true,
  findSimilarHover: false,
  findSimilarStatic: true

var options = {
  vsSettings: vsSettings,
  displaySettings: displaySettings,
  recommendationOpts: recommendationOpts

$(document).ready(function() {
    Recommendation(document.getElementById("vs-recommendation"), options);

Please update the following parameters in the code snippet according to your own app configurations:

Parameters Explanation
APP_KEY This is the credential to call our API. You should be able to find these in the Integration/Client-side Integration section on dashboard. Detailed explanation on key pairs can be found here.
fl The list of schema field values to be displayed in the result along with the image. The value of the schema should be the one that is being configured in your schema setting. You can find the full list in the Your Images -> Schema section on dashboard. Detailed explanation on schema configuration can be found here.
IM_NAME The index id (im_name) of the product to find recommendations for. This should be the same im_name used for datafeed indexing.

Run the example

The example project is managed by gulp. If you don't have gulp, please follow the getting started guide to install it. The following command will start a server and run the example at http://localhost:8080:

// Remember to configure before starting or else there will be error
gulp start

If the parameters are configured correctly, you should be able to see the widget working like this:


Advanced options

Customize product card layout

You might want to customize the layout of the product card to fit the design of your site. productDetails is an object that maps the corresponding card details to search results. The image below illustrates a visual representation of the product card and its details. You can pass the field schema value to the placeholder in order for the correct value to be rendered. Note that the widget will not render the product detail field unless it is set.


Example: Configure productDetails as shown below in order to display the product title first and product brand below that:

  productDetails: {
    label: "title",
    heading: "brand",
    description: "",
    price: "price",
    discountPrice: "discount_price"

Customize product card style

Of special interest is the ability to customize the style of the widget so it matches the look and feel of your website. The widget is made of up multiple JavaScript elements which can be modified by adding CSS styling to your site.


You can find the sample css files to customize the look for the example in the directory src/styles. Here is sample css that customizes the product card layout as shown above:

/*Product details*/
.vs-product-details {
  color: #333333;
  font-size: 14px;
  padding-top: 5px;
  padding-bottom: 5px;
  font-family: 'Roboto-Regular', sans-serif;
.vs-product-details .vs-ellipsis {
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  overflow: hidden;
.vs-product-details .vs-elli-one {
  -webkit-line-clamp: 1;
.vs-product-details .vs-product-label {
  height: 22px;
  font-family: 'Roboto-Bold', sans-serif;
.vs-product-details .vs-product-heading {
  position: relative;
  line-height: 1.4em;
  height: 40px;
.vs-product-details .vs-product-description {
  font-size: 12px;
  height: 35px;
  font-family: 'Roboto-Light', sans-serif;
  color: #777777;
.vs-product-details .vs-product-price {
  display: inline-block;
  margin-top: 5px;
  margin-bottom: 5px;
  margin-right: 10px;
.vs-product-details .vs-strikethrough {
  text-decoration: line-through;
  color: #999999;
  font-weight: 400;
.vs-product-details .vs-product-discount-price {
  display: inline-block;
  color: #d03535;
  font-weight: 400;
.vs-product-details .vs-product-more_details {
  color: white;
  text-align: center;
  background-color: black;
  line-height: 30px;
.vs-product-details .vs-product-more_details:hover {
  color: white;
  text-decoration: none !important;
  background-color: #676767;
.vs-product-details .vs-cart-static {
  height: 20px;
  width: 20px;
  margin-left: 15%;
  cursor: pointer;
  opacity: 0.7;
  float: right;
.vs-product-details .vs-cart-static:hover {
  opacity: 1;
.vs-product-details .vs-cart-icon {
  height: 100%;
  width: 100%;



Key Type Description
appKey string (compulsory) app key
fl array (compulsory) list of schema values returned from the API. The list needs to match the schema set in the API.
fq object (optional) list of pre-defined filters to filter your search results. e.g. fq: ['country:singapore', 'brand:nike']. Detailed explanation of the filters can be found here.
limit integer (optional) the number of search results returned. Default set to 15.


Key Type Description
imName string (compulsory) the index id of the product to recommend on. This is the same id used for API indexing.
productDetails object (compulsory) result in widget mapped to the product card display. See below for product card layout. Each of the card elements will be matched to the response result. Widget will not render the card element if the key is not given.
productContainer html element (optional) area for additional customization on top of the default layout provided. Recommended to have simple additional buttons.
onProductContainerClicked function (optional) method to be executed when the productContainer is clicked.
rcTitle string (optional) title of the widget to be displayed. Default is set as "You may also like".
hasHoverCartIcon boolean (optional) show the "Add to cart" icon when image is hovered. Default set to true. See an example.
hasStaticCartIcon boolean (optional) show the "Add to cart" icon permanently below the image. Default set to false. See an example.
onAddToCartClicked function (optional) method to be executed when "Add to cart" icon is clicked.
cartText string (optional) text to represent "Add to cart". Default set to "Add to cart". It will always show to the right of the icon.
afterCartText string (optional) text to represent "Add to cart" after clicked. Default set to "Added". It will always show to the right of the icon.
findSimilarText string (optional) add a text description on the right of the "Find Similar" icon (applicable to only the hover button). Default is empty.
hasHoverFindSimilar boolean (optional) show the "Find Similar" icon when image is hovered. Default set to true. See an example.
hasStaticFindSimilar boolean (optional) show the "Find Similar" icon permanently below the image. Default set to false. See an example.


Key Type Description
hasQueryProduct boolean (optional) show the details of the query product within "Find Similar". Default set to false. Note that query product detail is automatically mapped to the query product.
cardsToShow integer (optional) number of results in a single strip. Default set to 4.
cardsToScroll integer (optional) number of results in a single scroll. Default set to 4.
hasInfiniteScroll boolean (optional) enable infinite scroll. Default set to false.
isDraggable boolean (optional) enable mouse drag within browser. Default set to false.
hasDots boolean (optional) show the dots at the bottom as page indicator. Default set to true.
nextArrowSrc string (optional) url to image source for the next arrow.
prevArrowSrc string (optional) url to image source for the previous arrow page indicator. Default set to true.
hasAutoplay boolean (optional) enable auto scrolling of results. Default set to false.
autoplaySpeed integer (optional) delay time in terms of milliseconds between each scroll. Default set to 3000ms.
currencySymbol string (optional) currency symbol before prices and discount_prices. Default set to '$'.
errorMessage string (optional) message to be displayed when an error occurs. Default set to "System busy. Please try again later".