Docs

Android SDK

Overview

Our Software Development Kit (SDK) supports network calls your eCommerce application makes to the Unbxd platform and allows you to configure and integrate Unbxd Site Search within your web store.

The following features are currently supported with UnbxdSDK:

  • Search: Allows you to interact with the Unbxd platform and implement all search related functionality
  • Autosuggest: Allows to autocomplete search queries and showcase relevant products
  • Browse: Allows you to interact with the Unbxd platform and implement all category related functionality
  • Analytics: Allows integration of site event, session-related analytics
  • Recommendations: Allows you to integrate product recommendations with the help of recorded events

System Requirements

Before you can integrate our SDK, you need to:

  1. Set up your Site Search Dashboard
  2. Get your API key, Site key
  3. Upload your Product Feed

You need to have a:

  • Kotlin 1.2.71 or above
  • Okhttp3 3.8.1 or above

Our SDK is .arr programmed using Kotlin. This can be integrated with the Android application programmed with either Kotlin and Java.

Install SDK

Android SDK is hosted in a private maven repository and is integrated as a Gradle dependency.

The first step to install the Android SDK is to update the Android app’s build.gradle file to add a dependency on the mobile app, then do a gradle sync and you are ready to go

To add dependency go to file build.gradle and go to dependencies sections an add the code as shown below:


View code

repositories  
{
               maven {
               url 'http://3.95.143.246:8081/artifactory/libs-release-local/' 
               credentials {
               username ""
               password "" 
                           }
                      }
}
dependencies {  
               implementation fileTree(include: ['*.jar'], dir: 'libs')
                  - 
                  - 
                  -
               implementation 'com.squareup.okhttp3:okhttp:3.8.1'
               implementation (group: 'com.unbxd.sdk', name:'unbxdsdk', version: '1.0.1', ext:'aar')
               implementation project(path: ':unbxdsdk') 
              }

Credentials would be provided by Unbxd. Unbxd employees can view the credentials here and the procedures here.

After changes to build.gradle are done, do a gradle sync, so that gradle pulls in all the required resources to your project need and checks all the references, to make sure everything's ok.

Initialize SDK

To initialize SDK, import Unbxd framework:
import com.unbxd.sdk.Client

Unbxd is initialised with API key and Site key:

val client = Client(<site_key>,<api_key>, *applicationContext*)  

IMPORTANT: We advise you to use your API Key in encrypted form on your frontend and never share it with anyone.

Integrating Unbxd Commerce Search

Unbxd Site Search is an e-commerce search platform that enhances your on-site search to deliver fast, relevant, and tailored search results to visitors on your website/mobile application. Unbxd Site Search is platform-agnostic, which makes it incredibly versatile and easily implementable.

For more information, see here.

Using Search Methods

Search methods in SDK are used to integrate UNBXD search in your Android App.

Search method signature:

fun search(query: SearchQuery, completion: ICompletionHandler) {...}  

Let's see how these arguments can be composed and passed in search () method invocation.

Different arguments that can be passed with the search method are
1. SearchQuery
2. Format
3. Start
4. Rows
5. Spellcheck
6. Analytics
7. stats
8. Variants
9. Fields
10. Facets
11. Filtering
12. Multiple Filters
13. Sort

Let's discuss each of these in more details

1. Search Query

SearchQuery attaches the query which is searched on a website with search function as shown in the code below:
here Shirt is the search query.

View code

val searchQuery =  
               SearchQuery.Builder("Shirt").build() 
               client.search(searchQuery, object : 
               ICompletionHandler {
                                   override fun onSuccess(json: JSONObject, response: Response) 
                                  { //Handle success
                                  }
override fun onFailure(errorMessage: String, exception: Exception)  
                                 { //Handle failure
                                 }
                }
)

2. Format

The format parameter specifies the format of the response. Possible values are ‘JSON’ or ‘XML’.

This is an optional parameter. The default value is ‘JSON’.



View code

val searchQuery = SearchQuery.Builder("Shirt").responseFormat(ResponseFormat.XML).build()  
         client.search(searchQuery, object : ICompletionHandler 
                {
override fun onSuccess(json: JSONObject, response: Response)  
                {
                 //Handle success 
                }
                 override fun onFailure(errorMessage: String, exception: Exception) 
                { //Handle failure
                } 
                }
)

3. Start

The start parameter is used to offset the results by a specific number. It indicates offset in the complete result set of the products.
For instance, if there are 10 products in the search results page, and the offset is set at 5, then the results page will not list the first 5 products.

This is an optional parameter and the default value is 0.


View code

val searchQuery = SearchQuery.Builder("Shirt").start(2).build() client.search(searchQuery, object : ICompletionHandler {  
override fun onSuccess(json: JSONObject, response: Response)  
                  {
                   //Handle success
                   override fun onFailure(errorMessage: String, exception: Exception)  
                  { //Handle failure
                  } 
                  }
)

4. Rows

The rows parameter is used to paginate the results of a query. It indicates the number of products on a single page. It is an optional parameter and the default value is 10, the maximum value is 100.

This is an optional parameter and the default value is 10, Permitted range is 1 - 100.


View code

val searchQuery = SearchQuery.Builder("Shirt").rows(20).build() client.search(searchQuery, object : ICompletionHandler {  
override fun onSuccess(json: JSONObject, response: Response)  
                                         {
                                          //Handle success 
                                         }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                       { 
                                         //Handle failure
                                       } 
                                       }
)

5. Spellcheck

The spellcheck feature provides spelling suggestions or spell-checks for misspelled search queries.


View code

val searchQuery = SearchQuery.Builder("Shirt").spellCheck(true).build() client.search(searchQuery, object : ICompletionHandler  
                                       {
                                       override fun onSuccess(json: JSONObject, response: Response) { //Handle success
                                       }
                                       override fun onFailure(errorMessage: String, exception: Exception) 
                                       { 
                                       //Handle failure
                                       } 
                                       }
)

6. Analytics

This parameter allows you to enable or disable analytics tracking the site search event.

This is an optional Parameter. By default, tracking is enabled.


View code

val searchQuery = SearchQuery.Builder("Shirt").analytics(false).build() client.search(searchQuery, object : ICompletionHandler  
                                       {
                                       override fun onSuccess(json: JSONObject, response: Response) 
                                       { 
                                       //Handle success
                                       }
                                       override fun onFailure(errorMessage: String, exception: Exception) 
                                       {
                                       //Handle failure 
                                       }
                                       }
)

7. Stats

This parameter provides information about all the products within your catalog that have the highest and lowest field values.


View code

val searchQuery = SearchQuery.Builder("Shirt").showStatsForField("vPrice").build()  
client.search(searchQuery, object : ICompletionHandler  
                                       {
                                       override fun onSuccess(json: JSONObject, response: Response) 
                                       {
                                       //Handle success 
                                       }
                                       override fun onFailure(errorMessage: String, exception: Exception) 
                                       { 
                                       //Handle failure
                                       } 
                                       }
)

8. Variants

Products in the feed can be available in different sizes, colors, styles, materials, etc. For example, a dress can be available in different sizes, colors and/or styles.
Variant 1 : Color - Blue, Size: Small, Style - Solid print
Variant 2 : Color - Red, Size: Small, Style - Solid print
Variant 3 : Color - Blue, Size: Large, Style - Polka-dot
Variants parameter enables or disables variants in the API response. It can take two values: “true” or “false”. Default value is “false”.

For more information, see here (Request Parameters section).

The variants parameter enables or disables variants in the API response. Variants have two values:

  • True
  • False

    Default value is “false”.


    View code

    val variant = Variant(true, 2)  
    val searchQuery = SearchQuery.Builder("Shirt").variant(variant).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    If you want to get multiple variants in the API response, you can use the ‘variantCount’ parameter. The variantCount parameter can have any numerical value (eg, 1,2,3, etc).

    9. Fields

    The fields parameter is used to specify the set of fields to be returned as the response, otherwise, all the fields will be returned in the response by default.

    Fore more information, see here (Request Parameters section).


    View code

    val searchQuery = SearchQuery.Builder("Shirt").fields(arrayOf("title","vPrice")).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    here in this example, only Title and Price of the product would be returned in the response, as opposed to all the fields.

    10. Facets

    Facets are filters in the UI that allow visitors to narrow down result set based on product fields. It is usually known as Layered Navigation or Guided Navigation.
    Facets can be easily configured from the Manage -> Configure Search -> Configure Facet section of the Console.

    Facets can be of three types:

    • Multi-level: Facets on categories. For a given API response, multi-level facets would represent the top-most categories those products lie under.
    • Text: Facets on text fields in the feed. For example, color, brand, etc.
    • Range: Facets on numeric fields in the feed. For example, price, discount, etc.

    For more information, see here (Request Parameters section).

    10.1. Multi-level

    MultiLevelFacet() parameter is used to enable Multi-level facet in the API in search response.


    View code

    val searchQuery = SearchQuery.Builder("Shirt").facet(MultiLevelFacet()).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    10.2. Multi-select

    This feature enables or disables the option to select multiple values within a facet or across facets for visitors.
    For example, for a query “red dress”, facets of gender and size fields are displayed. If the value for facet.multiselect is set as true and if a visitor selects Women in the Gender facet, the search results will be refined according to the selection. However, all values in the gender facet will still be sent in the response as if the gender filter isn’t applied (and other filters are applied, if any).


    View code

    val searchQuery = SearchQuery.Builder("Shirt").facet(MultiSelectFacet()).build() client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           { 
                                           //Handle success
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    10.3. Selected

    This feature enables or disables the option to select multiple values within a facet or across facets for visitors.

    Selected facet with fieldId and valueId:


    View code

    val idFilter = IdFilter("76678", "5001")  
    val searchQuery = SearchQuery.Builder("Shirt").facet(SelectedFacet(idFilter)).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    Selected facet with field name and value name:


    View code

    let query = SearchQuery(key: “Shirt", facet: .Selected(NameFilter(field: "Brand_uFilter", value: "Vince Camuto")))  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           { 
                                           //Handle success
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    11. Filtering

    You can refine fields using fieldId or fieldName.
    Three types of filters are supported:

    • Text
    • Range
    • Multi-level
    11.1. Text

    This filter is used to refine products based on fields with string values such as color, gender, brand, etc. It can be defined in the API call in two ways:

    # Using Field IDs

    idFilter can be formed with 2 parameters:

    • field: The ID of the field on which the text filter is applied.
    • value: The ID of the value on which the results are filtered.


    View sample code

    val idFilter = IdFilter("76678", "5001")  
    val searchQuery = SearchQuery.Builder("Shirt").filter(idFilter).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
    override fun onFailure(errorMessage: String, exception: Exception)  
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )                                       
    

    # Using Field Names

    Again nameFilter can be formed with 2 parameters.

    • type: The ID of the field on which the text filter is applied.
    • value: The ID of the value on which the results are filtered.


    View sample code

    val nameFilter = NameFilter("vColor_uFilter","Black")  
    val searchQuery = SearchQuery.Builder("Shirt").filter(nameFilter).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           }
                                           }
    )
    

    11.2. Range

    Used to refine products based on fields with datatypes, like:

    • Date
    • Number
    • decimal.

    The API can be defined in two ways:

    # Using Field IDs

    Filter Range of type ID is built using IdFilterRange class and it can be initialized with parameters below:

    • field: The ID of the field on which the text filter is applied.
    • lower: The ID of the lower limit of the range.
    • upper: The ID of the upper limit of the range.


    View sample code

    val idFilterRange = IdFilterRange("76678","2034", "8906")  
    val searchQuery = SearchQuery.Builder("Shirt").filter(idFilterRange).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           { 
                                           //Handle failure
                                           } 
                                           }
    )
    

    # Using Field Names

    Filter Range of type name is built using NameFilterRange class and it can be initialized with parameters below:

    • field: The name of the field on which the text filter is applied.
    • lower: The name of the lower limit of the range.
    • upper: The name of the upper limit of the range.


    View sample code

    val nameFilterRange = NameFilterRange("vColor","red", "blue")  
    val searchQuery = SearchQuery.Builder("Shirt").filter(nameFilterRange).build()  
    let query = SearchQuery(key: "Shirt", filter: NameFilterRange(field: "vColor", lower: "red", upper: "blue"))  
    client.search(searchQuery, object : ICompletionHandler  
                                           {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success 
                                           }
                                           override fun onFailure(errorMessage: String, exception: Exception) 
                                           {                                        
                                           //Handle failure
                                           }                                        
                                           }
    )
    

    11.3. Multi-level

    The multilevel filter is used to refine products based on categories.

    The API call can be defined in two ways:

    # Using Field IDs

    “CategoryIdFilter” is used to filter the results using a category path comprised of category IDs.


    View sample code

    val categoryIdFilter = CategoryIdFilter(ReferenceType.TypeId, arrayOf("FA", "A0485"))  
    val searchQuery = SearchQuery.Builder("Shirt").categoryFilter(categoryIdFilter).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                           { 
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                           {
                                           //Handle success
                                           }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          }                                       
                                          }
    )
    

    # Using Field Names

    “CategoryNameFilter” is used to filter the results using a category path comprised of category names.


    View sample code

    val categoryNameFilter = CategoryNameFilter(ReferenceType.TypeName, arrayOf("Fashion", "Shirts"))  
    val searchQuery = SearchQuery.Builder("Shirt").categoryFilter(categoryNameFilter).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    12. Multiple Filters

    There are two types of filter operations:
    • AND • OR

    12.1. AND
    Using Field IDs

    MultipleIdFilter takes 2 parameters:

    • fieldId
    • valueId.

    Multiple filters can be added and ‘operatorType' is set to ‘AND’.


    View code

    var idFilters = ArrayList<FilterBase>() idFilters.add(IdFilter("76678", "5001")) idFilters.add(IdFilter("76678", "5021"))  
    val searchQuery = SearchQuery.Builder("Shirt").multipleFilter(MultipleIdFilter(idFilters, FilterOperatorType.AND)).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    # Using Field Names

    MultipleNameFilter takes 2 parameters, field name and value name. Multiple filters can be added and ‘operatorType' is set to ‘AND’.


    View code

    var nameFilters = ArrayList<FilterBase>() nameFilters.add(NameFilter("vColor_uFilter", "Black")) nameFilters.add(NameFilter("vColor_uFilter", "White"))  
    val searchQuery = SearchQuery.Builder("Shirt").multipleFilter(MultipleIdFilter(nameFilters,  
     FilterOperatorType.AND)).build()
    client.search(searchQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    12.2. OR
    Using Field IDs

    MultipleIdFilter takes 2 parameters:

    • fieldId
    • valueId

    Multiple filters can be added and ‘operatorType' is set to ‘OR’.


    View code

    var idFilters = ArrayList<FilterBase>() idFilters.add(IdFilter("76678", "5001")) idFilters.add(IdFilter("76678", "5021"))  
    val searchQuery = SearchQuery.Builder("Shirt").multipleFilter(MultipleIdFilter(idFilters, FilterOperatorType.OR)).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                          { override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    # Using Field Names

    MultipleNameFilter takes 2 parameters:

    • field name
    • value name

    Multiple filters can be added and ‘operatorType' is set to ‘OR’.


    View code

    var nameFilters = ArrayList<FilterBase>() nameFilters.add(NameFilter("vColor_uFilter", "Black")) nameFilters.add(NameFilter("vColor_uFilter", "White"))  
    val searchQuery = SearchQuery.Builder("Shirt").multipleFilter(MultipleIdFilter(nameFilters, FilterOperatorType.OR)).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: 
    JSONObject, response: Response)  
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    13. Sort

    The sort parameter is used to rank the products based on specified fields in the specified order.

    Sort can be done on a single field or multiple fields.

    Single Field

    • fieldName: The field on which the sort is applied.
    • sortOrder: The order in which the sort is applied.

    This value can be "ASC" (for ascending) or "DSC" (for descending).


    View code

    var fieldsOrder = ArrayList<FieldSortOrder>() fieldsOrder.add(FieldSortOrder("vPrice", SortOrder.ASC))  
    val searchQuery = SearchQuery.Builder("Shirt").fieldsSortOrder(fieldsOrder).build() client.search(searchQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    Multiple Fields

    When two or more FieldSortOrder instances are added:


    View code

    var fieldsOrder = ArrayList<FieldSortOrder>() fieldsOrder.add(FieldSortOrder("vPrice", SortOrder.ASC))  
    fieldsOrder.add(FieldSortOrder("title", SortOrder.DSC))  
    val searchQuery = SearchQuery.Builder("Shirt").fieldsSortOrder(fieldsOrder).build()  
    client.search(searchQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    Integrating Unbxd Autosuggest

    The Autosuggest feature provides query suggestions, which helps your visitors to search faster in your site. Unbxd supports autocompletion of search queries and showcasing products relevant to query as they type.

    Unbxd Autosuggest comprises of different types of suggestions that are known as doctypes. A standard Unbxd Autosuggest is segmented into five doctypes:

    FeaturesDescription
    In-fieldsThe In-fields doctype suggest groups of relevant products along with their associated field values the query may belong to.
    These field values can be categories, brands, occasion, etc. For example, a visitor types ‘Sh’, the In-field doctype will have the following suggestions:
    • Shirts
      • In Men (based on gender)
      • In Nike, (based on brand)
      • In Blue (based on occasion)
    Keyword SuggestionsThese are intelligent suggestions generated by Unbxd based on the query being typed and suggests relevant products based on your product feed accordingly.
    For example, a visitor types ‘Sh’, the keyword suggestions doctype will have the following suggestions:
    • Shirts
    • Shorts
    • Shoes
    • Shapewear
    Top QueriesThis doctype displays the frequently searched queries in your e-commerce store populated with the help of Unbxd Analytics, which keeps a track of your store.
    Popular ProductsThis doctype displays popular products with thumbnail images. Similar to Top Queries doctype, to render Popular products, Unbxd analytics needs to be integrated in your e-commerce store.
    Promoted SuggestionsThese are documents that a customer can configure directly from merchandising console.
    For example, if a customer configures “jogging shoes” and “running shoes” as promoted suggestions, and a shopper searches for “sh”, the intended results are returned.

    For more information, see here (Request Parameters section).

    Using Autosuggest Query

    Arguments used to for Autosuggest query are as follows:
    1. AutosuggestQuery
    2. Variants
    3. DocType
    4. Filters

    Let's discuss each of these in details

    1. AutosuggestQuery

    AutoSuggest can be initialized with ‘Key’ for suggestions.

    This is a mandatory parameter.

    Shir in below example, the sample query types by the user.


    View sample code

    val autosuggestQuery = AutosuggestQuery.Builder("Shir").build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    2. Variant

    Variants can be enabled or disabled in AutoSuggest query responses. Variant status can be set to true/false as below.


    View sample code

    val autosuggestQuery = AutosuggestQuery.Builder("Shir").variant(Variant(true, 2)).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    3. DocType

    Autosuggest comprises of different types of suggestions that are known as doctypes as discussed above. A standard Unbxd Autosuggest is segmented into five doctypes:

    • InField
    • Keyword Suggestions
    • Top Queries
    • Promoted Suggestions
    • Popular Products

    Let's discuss how to integrate each of these DocTypes, in your autosuggest response.

    3.1 InField

    The inField doctype with result count can be configured as shown below:


    View sample code

    val docType = DocTypeInField.Builder().resultCount(3).build()  
    val autosuggestQuery = AutosuggestQuery.Builder("Shir").inField(docType).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    If resultCount is not set, default value 2 will be considered as results count for inField doctype.

    3.2 Keyword Suggestions

    Keyword Suggestions doctype with result count can be configured as shown below:


    View sample code

    val docType = DocTypeKeywordSuggestions.Builder().resultCount(4).build()  
    val autosuggestQuery = AutosuggestQuery.Builder("Shir").keywordSuggestions(docType).build() client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response)                                       
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    If resultCount is not set, default value 2 will be considered as results count for Keyword Suggestions doctype.

    3.3 Top Queries

    Top Queries doctype with result count can be configured as below:


    View sample code

    val docType = DocTypeTopQueries.Builder().resultCount(3).build() val autosuggestQuery =  
    AutosuggestQuery.Builder("Shir").topQueries(docType).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    If resultCount is not set, default value 2 will be considered as results count for Top Queries doctype.

    3.4 Promoted Suggestions

    Promoted Suggestions are product recommendations that a merchandiser can configure from the console.

    This gives you the flexibility to manually insert keyword suggestions in autosuggest which may not be part of the default relevance results.
    Promoted Suggestions doctype with result count can be configured as below:


    View sample code

    val docType = DocTypePromotedSuggestions.Builder().resultCount(5).build() val autosuggestQuery = AutosuggestQuery.Builder("Shir").promotedSuggestions(docType).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success }
    override fun onFailure(errorMessage: String, exception: Exception)  
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    If resultCount is not set, default value 2 will be considered as results count for Promoted Suggestions doctype.

    3.5 Popular Products

    The Popular Products doctype displays products most searched for in your eCommerce store with thumbnail images.

    Popular Products doctype with fields and result count can be configured as below:


    View sample code

    val docType = DocTypePopularProducts.Builder().resultCount(3).fields(arrayOf("vColor", "price")).build()  
    val autosuggestQuery = AutosuggestQuery.Builder("Shir").popularProducts(docType).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    If resultCount is not set, default value 3 will be considered as results count for Promoted Suggestions doctype.

    4. Filters

    Filters, when used in AutoSuggest, helps to restrict products based on criteria passed.

    Two types of filters are supported

  • Text
  • Range

    4.1 Text

    The text filter is used to filter products based on fields with string values such as color, gender, brand, etc. It can be defined in the API call in two ways:

    Using Field IDs

    IdFilter can be formed with 2 parameters.
    field: The id of the field on which the text filter is applied. value: The id of the value on which the results are filtered.


    View sample code

    val idFilter = IdFilter("76678", "5001")  
    val autosuggestQuery = AutosuggestQuery.Builder("Shir").filter(idFilter).build() client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    Using Field Names

    Again NameFilter can be formed with 2 parameters.

    • field: The ID of the field on which the text filter is applied.
    • value: The ID of the value on which the results are filtered.


    View sample code

    val nameFilter = NameFilter("vColor", "Black")  
    val autosuggestQuery = AutosuggestQuery.Builder("Shir").filter(nameFilter).build() client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    4.2 Range

    The range filter is used to refine products based on fields with datatypes:

  • date
  • number
  • decimal

    You can define the API in two ways:

    Using Field IDs

    Filter Range of type id is built using FilterIdRange class and it can be initialized with below parameters.

    • field: The ID of the field on which the text filter is applied.
    • lower: The ID of the lower limit of the range.
    • upper: The ID of the upper limit of the range.


    View sample code

    val idFilterRange = IdFilterRange("76678","2034", "8906") val autosuggestQuery = AutosuggestQuery.Builder("Shir").filter(idFilterRange).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          //Handle success
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          {
                                          //Handle failure 
                                          }
                                          }
    )
    

    Using Field Names

    Filter Range of type name is built using FilterNameRange class and it can be initialized with below parameters.

    • field: The name of the field on which the text filter is applied.
    • lower: The name of the lower limit of the range.
    • upper: The name of the upper limit of the range.


    View sample code

    val nameFilterRange = NameFilterRange("vColor","red", "blue") val autosuggestQuery = AutosuggestQuery.Builder("Shir").filter(nameFilterRange).build()  
    client.autosuggest(autosuggestQuery, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          //Handle success 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          //Handle failure
                                          } 
                                          }
    )
    

    Integrating Unbxd Analytics

    The actions a visitor takes on your e-commerce store are known as Events. Tracking visitor analytics and behavior is essential in order to provide accurate and visitor-specific search and category page results and also help showcase how your business benefits from Unbxd through the reporting.

    Unbxd Analytics tracks different events:

    • Visitor
    • Search Hit
    • Category Page Hit
    • Product Click
    • Add to Cart
    • Order
    • Product Page View
    • Cart Removal
    • AutoSuggest
    • Recommendation Widget Impression
    • Search Impression
    • Category Page Impression
    • Dwell time (time spent on a product page)

    For more information about different events, see here.

    Using UserId Method

    SDK generates user ID internally and using below method in Client, App can get UserId and Visit type.


    View sample code

    fun userId(): UserId  
    User Id instance would have,  
    val id: String  
    val visitType: String  
    

    Getting Request Id

    RequestId should be passed to all the analytics APIs. It should be parsed from response header for key “Unbxd-Request-Id” from the request to Unbxd framework.


    View sample code

    fun Response.unbxdRequestId(): String?  
                                          {
                                          val allHeaders = this.headers()
    var requestId = allHeaders.get("Unbxd-Request-Id") if (!requestId.isNullOrEmpty())  
                                          {
                                          return requestId 
                                          }
                                          requestId = allHeaders.get("x-request-id") if (!requestId.isNullOrEmpty()) 
                                          {
                                          return requestId 
                                          }
                                          return null
                                          }
    

    Using Analytics Method

    Using Analytics methods app can publish event details and the merchandiser would be able to track those events in the portal.

    Below are the events, analytics method support

    • Visitor
    • Search Hit
    • Category Page Hit
    • Product Click
    • Add to Cart
    • Order
    • Product Page View
    • Cart Removal
    • AutoSuggest
    • Recommendation Widget Impression
    • Search Impression
    • Category Page Impression
    • Dwell time (time spent on a product page)

    Let's discuss each of these in detail.

    1. Tracking Visitor Event

    Whenever a new user visits the app, a visitor event is fired, containing information about whether a user is a first time visitor or a repeat visitor.

    This information is extracted from a 'visitor' cookie which is set every time the visitor event is fired. The cookie maintains the information about "visitType" parameter (also used by other events). Its value can be either 'first-time' or 'repeat'.

    The SDK will generate a randomized unique identifier (UUID)- UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to a storage device so that it will persist across sessions.

    Whenever a new user installs, launches and do some activity such as search, click, etc.. on the application, a visitor event is fired from SDK, that contains information that shopper is a 'first-time' user.

    Each session of the shopper on the application has an expiry time of 30 minutes and after it expires, the visitor event is fired again and reset the 'visitType' as "repeat" user. Next time the shopper opens the application, if the last visitor event was fired more than 30 minutes ago, the visitor event is fired again with 'visitType' as "repeat" user. This means, that if the shopper is logged on to the application for more than 30 minutes, his/her visitType will be changed from 'first-time' to 'repeat' and will be "repeat" forever until he uninstalls and re-installs the application.

    Note All of the above-mentioned tracking is done by the SDK itself and you as an application developer has to do nothing in order to track visitor event.


    View sample code

    val userId = client.userId()  
    val visitorAnalytics = VisitorAnalytics(userId.id, userId.visitType, requestId)  
    client.track(visitorAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response)                                                                 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    You can retrieve the UID and visit type using the userId method.

    2. Tracking Search Event

    A search event is fired when a shopper types something in the search box and presses enter or clicks on the search button. This will take the user to the search results page.


    View sample code

    val userId = client.userId()  
    val searchAnalytics = SearchAnalytics(userId.id, userId.visitType, requestId,  
    "Shirt")
    client.track(searchAnalytics, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    here in this example, "Shirt" is the string shopper types in the search box and presses enter or clicks the search button.

    userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    requestId: The unbxd request id returned in the search/category page/recommendations api call response.

    Tracking Category Page Event

    Category Page event is fired when a user navigates through the categories on the online store and visits a category page.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("cat3380002"))  
    val categoryPageAnalytics = CategoryPageAnalytics(userId.id, userId.visitType,  
    requestId, categoryPath, PageType.Boolean)  
    client.track(categoryPageAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Here,
    userId.id: The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions. userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'. requestId: The unbxd request id returned in the search/category page/recommendations API call response.

    *categoryPath: *:unique identifier for the page passed in the category page API as parameter ‘p’ in case of Category Page. for instance, If you have integrated category pages using the API call: https://search.unbxd.io/api-key/site-key/category?p=categoryName then categoryQuery will be called as

    let categoryQuery = CategoryNamePath(withCategories:["categoryName"])  
    

    but if you have integrated category pages using the API call: https://search.unbxd.io/api-key/site-key/category?p=category:categoryName

    then categoryQuery will be called as

    let categoryQuery = CategoryNamePath(withCategories: ["category:\(categoryName)"])  
    

    PageType: Its an enum defined in SDK. it accepts the following values

    1. URL
    2. CATEGORY_PATH
    3. TAXONOMY_NODE
    4. ATTRIBUTE
    5. BOOLEAN
    4. Tracking Product Click Event

    Whenever a user clicks on a particular product in the search or category page results, a 'click' action is generated.

    The following code needs to be called along with the appended data as described below:


    View sample code

    val userId = client.userId()  
    val productClickAnalytics = ProductClickAnalytics(userId.id, userId.visitType, requestId, "2301609", "Socks", RecommendationType.RecommendedForYou.boxType)  
    client.track(productClickAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id: The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    requestId: The unbxd request id returned in the search/category page/recommendations api call response.

    pageId(in example-2301609): Sends the unique identifier for the page passed in the category page API as parameter ‘p’ in case of Category Page.

    query( in example-Socks): Sends search query in case of search in the products listing page

    boxType: Recommendation widget clicked in case product is clicked from Recommendation Widget. Possible Values are

    Widget TypeBox Type
    Recommended For You RECOMMENDED_FOR_YOU
    Recently Viewed RECENTLY__VIEWED
    More Like These MORE_LIKE__THESE
    Viewed also Viewed ALSO__VIEWED
    Bought also Bought ALSO__BOUGHT
    Cart Recommendations CART__RECOMMEND
    HomePage Top Sellers TOP__SELLERS
    Category Top Sellers CATEGORY__TOP__SELLERS
    PDP Top Sellers PDP__TOP__SELLERS
    Brand Top Sellers BRAND__TOP__SELLERS
    5. Tracking Add to Cart Clicks

    An Add to Cart click event is fired every time shopper adds an item to cart.


    View sample code

    val userId = client.userId()  
    val addToCartAnalytics = ProductAddToCartAnalytics(userId.id, userId.visitType, requestId, "2301609", "231221", 2)  
    client.track(addToCartAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
    override fun onFailure(errorMessage: String, exception: Exception)  
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    *requestId *: The unbxd request id returned in the search/category page/recommendations API call response.

    PID: SKU id of the product. For example "2301609" in the above code.

    variantId: Id of the variant being added. For example "231221" in the above code.

    quantity: Quantity of the product added to the checkout bag. For example "2" in the above code.

    6. Tracking Order Event

    A product order event is fired upon order completion after the shopper returns to a product page from the payment gateway.


    View sample code

    val userId = client.userId()  
    val orderAnalytics = ProductOrderAnalytics(userId.id, userId.visitType, requestId, "2301609", 20.5, 2)  
    client.track(orderAnalytics, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
    Log.d("Client Response",json.toString())  
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    requestId: The unbxd request id returned in the search/category page/recommendations API call response.

    *pid: *SKU id of the product. For example "2301609" in the above code.

    Price: Order Payment of the product paid by the customer. For example "20.5" in the above code.

    qty: Quantity of the product bought. For example "2" in the above code.

    7. Tracking Product Display Page Views

    A product display page view event is fired every time a shopper visits a Product Display Page (PDP).


    View sample code

    val userId = client.userId()  
    val productDisplayAnalytics = ProductDisplayPageViewAnalytics(userId.id, userId.visitType, requestId, "2034")  
    client.track(productDisplayAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType:This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    requestId:The unbxd request id returned in the search/category page/recommendations api call response.

    pid:SKU id of the product. For example "2034" in the above code.

    8. Tracking Cart Removals

    A cart removal event is fired when a shopper removes an item from the cart.


    View sample code

    val userId = client.userId()  
    val cartRemovalAnalytics = CartRemovalAnalytics(userId.id, userId.visitType, requestId, "2034", "231221", 2)  
    client.track(cartRemovalAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType:This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    requestId:The unbxd request id returned in the search/category page/recommendations api call response.

    pid:SKU id of the product. For Example "2034" in the above code.

    variantId:Id of the variant being removed. For example "231221" in the above code.

    qty:Quantity of the product removed. For example "2" in the above code.

    9. Tracking Autosuggest

    An autosuggest event is fired when a shopper searches for a product and clicks on a product within the autosuggest widget/panel.


    View sample code

    val userId = client.userId()  
    val autoSuggestAnalytics = AutoSuggestAnalytics(userId.id, userId.visitType, requestId, "2034", "Red Socks", DocType.INFIELD.jsonKey, "red", "Red socks", "infield1", "color type", 6)  
    client.track(autoSuggestAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString())                       
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    *requestId: *The unbxd request id returned in the search/category page/recommendations api call response.

    pid:SKU id of the product.It is set non-null when autosuggest_type is POPULAR_PRODUCTS. For example "2034" in the above code.

    query: Autosuggest suggestion returned by Unbxd.

    *docType : *It can be IN_FIELD, POPULAR_PRODUCTS TOP_SEARCH_QUERIES, KEYWORD_SUGGESTION, PROMOTED_SUGGESTIONS.

    *internalQuery : *Query for which autosuggest results were generated. For example "red" in the above code.

    fieldValue : Set when autosuggest_type is IN_FIELD. Set to the value of the "infield" in unbxd response. It is set to null otherwise. For example "Red socks" in the above code.

    fieldName : Set when autosuggest_type is IN_FIELD. Name of the autosuggest field in the search response. It is set to null otherwise. For Example "infield1" in the above code.

    * sourceField:* Name of the fields present in the catalog on the combination of which in fields are generated. It is set when autosuggest_type is not null. For example "color type" in the above code.

    * unbxdPrank:* unbxdPrank is the position of selected suggestion the list of items/suggestions received in Autosuggest response. For example "6" in the above code.

    skuId, query, doctype, internalQuery, etc are obtained from Autosuggest response data.

    10. Tracking Recommendation Widget Impression

    If you are subscribed to Unbxd Recommendations, every time the shopper clicks on a Recommendation widget, the API below will be called.


    View sample code

    val userId = client.userId()  
    val recommendationWidgetAnalytics = RecommendationWidgetAnalytics(userId.id,  
    userId.visitType, requestId, RecommendationType.RecommendedForYou, arrayOf("1692741, 01692015, 1692908"))  
    client.track(recommendationWidgetAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id: The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    requestId: The unbxd request id returned in the search/category page/recommendations API call response.

    recommendationType : Specifies the type of recommendation widget. For different permissible values, refer the table below.

    Widget TypeBox Type
    Recommended For You RECOMMENDED_FOR_YOU
    Recently Viewed RECENTLY__VIEWED
    More Like These MORE_LIKE__THESE
    Viewed also Viewed ALSO__VIEWED
    Bought also Bought ALSO__BOUGHT
    Cart Recommendations CART__RECOMMEND
    HomePage Top Sellers TOP__SELLERS
    Category Top Sellers CATEGORY__TOP__SELLERS
    PDP Top Sellers PDP__TOP__SELLERS
    Brand Top Sellers BRAND__TOP__SELLERS

    * productIds:* List of product IDs rendered.

    11. TrackingSearch Results Impression

    A search impression event is fired when a search results page loads for the first time, and whenever results changes on applying pagination, auto scroll, sort, and filters. For each of these actions, the uniqueIds' of the products visible on the search page will be sent as payload.


    View sample code

    val userId = client.userId()  
    val searchImpressionAnalytics = SearchImpressionAnalytics(userId.id, userId.visitType, requestId, "Shoes", arrayOf("1692741", "01692015", "1692908"))  
    client.track(searchImpressionAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    productIds : List of product ids of products visible in the window when the event occurs. For example "arrayOf("1692741", "01692015", "1692908"))" in above code.

    *userId.id: *The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the device storage so that it will persist across sessions.

    userId .visitType: This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    * requestId:* The unbxd request id returned in the search/category page/recommendations API call response.

    query:For example "shirt" in the above code.

    12. Tracking Category Page Impression

    Similar to a search page impression event, a category page impression event is fired when a category page results loads for the first time, and every time the results changes on applying pagination, auto scroll, sort, and filters. For each of these actions, the uniqueIds' of the products visible on the search page will be sent as payload.


    View sample code

    val categoryPath = CategoryNamePath(arrayOf("home", "furniture", "entrywayfurniture"))  
    val categoryPageImpressionAnalytics = CategoryPageImpressionAnalytics(userId.id, userId.visitType, requestId,  
    categoryPath, PageType.Url, arrayOf("1692741", "01692015", "1692908"))  
    client.track(visitorAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    userId.id:The SDK will generate a randomized unique identifier - UID to each unique user, who installs your application and it would be used to identify the user as first time visitor or a repeat visitor. This distinct ID is saved to the storage device so that it will persist across sessions.

    userId.visitType:This information is extracted from a 'visitor' cookie setup by SDK. Its value can be either 'first-time' or 'repeat'.

    categoryPath: unique identifier for the page passed in the category page API as parameter ‘p’ in case of Category Page. for instance, If you have integrated category pages using the API call: https://search.unbxd.io/api-key/site-key/category?p=categoryName
    then categoryQuery will be called as

    let categoryQuery = CategoryNamePath(withCategories:  
    ["categoryName"])
    

    but if you have integrated category pages using the API call: https://search.unbxd.io/api-key/site-key/category?p=category:categoryName

    then categoryQuery will be called as

    let categoryQuery = CategoryNamePath(withCategories: ["category:\(categoryName)"])  
    

    * pageType: * It is an enum defined in SDK. it accepts the following values

    1. URL
    2. CATEGORY_PATH
    3. TAXONOMY_NODE
    4. ATTRIBUTE
    5. BOOLEAN

    requestId: The unbxd request id returned in the search/category page/recommendations API call response.

    productIds : List of product ids of products visible in the window when the event occurs. For example "arrayOf("1692741", "01692015", "1692908"))" in above code.

    13. Tracking Dwell time

    A dwell time event is used to capture the amount of time a shopper spends on the product description page.


    View sample code

    val userId = client.userId()  
    val dwellTimeAnalytics = DwellTimeAnalytics(userId.id, userId.visitType, requestId,  
    "2301609", 60.0)
    client.track(dwellTimeAnalytics, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    14. Tracking Facets

    A facet event is fired when a filter is applied on Search or Category pages.


    View sample code

    val userId = client.userId()  
    val facetAnalytics = FacetAnalytics(userId.id, userId.visitType, requestId, "Shirts", NameFilter("fit_fq", "Fitted"))  
    client.track(facetAnalytics, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Integrating Unbxd Browse

    The SDK lets you customize your page experience by leveraging various built-in features of Browse. You can also power any type of page, such as Category, Brand, or any other attribute.

    Let's see how the Browse Query can be composed and passed in browse() method invocation.

    Using Browse Method

    Browse methods operate on Category fields query which is configured part of Browse Query.

    Browse Methods has the following parts
    1. Browse Query
    2. Format
    3. Start
    4. Rows
    5. Spellcheck
    6. Analytics
    7. Stats
    8. Variants
    9. Fields
    10. Facets
    11. Filtering
    12. Multiple Filter
    13. Sort

    1. Browse Query

    BrowseQuery consists of Category path or field details parameter Query with Category can be build as shown below:

    Using Field IDs


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Using Field Names


    View sample code

    val categoryPath = CategoryNamePath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Using Page IDs


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Using Page Names


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    2. Format

    The format parameter specifies the format of the response. Possible values are:
    * JSON * XML

    It is an optional parameter and the default value is ‘json’.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath). responseFormat(ResponseFormat.XML).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }                                     
    )
    

    3. Start

    This parameter is used to offset the results by a specific number. It indicates offset in the complete result set of the products.

    This is an optional parameter and the default value is 0.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath).pageIndex(2).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    4. Rows

    This parameter is used to paginate the results of a query. It indicates the number of products on a single page.

    It is an optional parameter and the default value is 10, the maximum value is 100.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath).rowsCount(20).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    5. Spellcheck

    The spellcheck feature checks for misspelled search queries and recommends autocorrect suggestions.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath).spellCheck(true).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    6. Analytics

    The analytics parameter enables or disables tracking the query hit for analytics.

    By default, tracking is enabled.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath).analytics(false).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    7. Stats

    The stats parameter gives information about the products with highest and lowest field value.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath).showStatsForField("vPrice").build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    8. Variants

    This parameter enables or disables variants in the API response.
    It can take two values:

  • true
  • false

    Default value is “false”.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val variant = Variant(true, 2)  
    val browseQuery = BrowseQuery.Builder(categoryPath).variant(variant).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    If you want to get more than one variants in the API response, you can use ‘variantCount’ parameter. It can have any numerical value (eg, 1,2,3, etc) or “.max” (to get all the variants).

    9. Fields

    The fields parameter is used to specify the set of fields to be returned.
    When returning the results, only fields in the list will be included.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath). fields(arrayOf("title","vPrice")).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          {
                                          Log.d("Client Response",errorMessage) 
                                          }
                                          }
    )
    

    10. Facets

    Facets are the filters in the interface that allow shoppers to refine results based on product fields.

    Facet option can have three values:

  • 1. Multi-level
  • 2. Multi-select
  • 3. Selected

    10.1 Multi-level

    The facer multilevel parameter is used to enable multi-level facets in the API response.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath). facet(MultiLevelFacet()).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client 
    Response",json.toString())  
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    10.2 Multi-select

    This feature enables or disables the option to select multiple values within a facet or across facets for shoppers.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath). facet(MultiSelectFacet()).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    10.3 Selected

    The selected facet parameter enables or disables the Selected Facets in the API response.
    Selected facet with field id and value id:


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val idFilter = IdFilter("76678", "5001")  
    val browseQuery = BrowseQuery.Builder(categoryPath). facet(SelectedFacet(idFilter)).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Selected facet with field name and value name:


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val nameFilter = NameFilter("Brand_uFilter", "Vince Camuto")  
    val browseQuery = BrowseQuery.Builder(categoryPath).  
    facet(SelectedFacet(nameFilter)).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    11. Filtering

    Filtering can be performed on fields using field Id or field Name.
    Three types of filters are supported:
    1. Text
    2. Range
    3. MultiLevel

    11.1 Text

    The text filter is used to filter products based on fields with string values such as color, gender, brand, etc. It can be defined in the API call in two ways:

    # Using Field IDs

    IdFilter can be formed with 2 parameters.
    field: The id of the field on which the text filter is applied. value: The id of the value on which the results are filtered.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val idFilter = IdFilter("76678", "5001")  
    val browseQuery = BrowseQuery.Builder(categoryPath).filter(idFilter).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    # Using Field Names

    Again NameFilter can be formed with 2 parameters.

    • type: The ID of the field on which the text filter is applied.
    • value: The ID of the value on which the results are filtered.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val nameFilter = NameFilter("vColor_uFilter","Black")  
    val browseQuery = BrowseQuery.Builder(categoryPath).filter(nameFilter).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    11.2 Range

    The range filter is used to filter products based on fields with datatypes - date, number or decimal. It can be defined in the API in two ways:

    # Using Field IDs

    Filter Range of type id is built using IdFilterRange class and it can be initialized with below parameters.

    • field: The ID of the field on which the text filter is applied.
    • lower: The ID of the lower limit of the range.
    • upper: The ID of the upper limit of the range.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val idFilterRange = IdFilterRange("76678","2034", "8906")  
    val browseQuery = BrowseQuery.Builder(categoryPath).filter(idFilterRange).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
    override fun onFailure(errorMessage: String, exception: Exception)  
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    # Using Field Names

    Filter Range of type name is built using NameFilterRange class and it can be initialized with parameters:

    • field: The name of the field on which the text filter is applied.
    • lower: The name of the lower limit of the range.
    • upper: The name of the upper limit of the range.


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val nameFilterRange = NameFilterRange("vColor","red", "blue")  
    val browseQuery = BrowseQuery.Builder(categoryPath). filter(nameFilterRange).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    11.3 Multi-level

    The multilevel filter is used to filter products based on categories.
    The API call can be defined in two ways:

    # Using Field IDs

    “CategoryIdFilter” is used to filter the results using category path comprised of category IDs


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val categoryIdFilter = CategoryIdFilter(ReferenceType.TypeId, arrayOf("BC", "B0485"))  
    val browseQuery = BrowseQuery.Builder(categoryPath). categoryFilter(categoryIdFilter).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    # Using Field Names

    “CategoryNameFilter” is used to filter the results using category path comprised of category Names


    View sample code

    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val categoryNameFilter = CategoryNameFilter(ReferenceType.TypeName,  
    arrayOf("Fashion", "Shirts"))  
    val browseQuery = BrowseQuery.Builder(categoryPath). categoryFilter(categoryNameFilter).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    12. Multiple Filters

    There are two types of filter operations:

  • AND
  • OR

    12.1. And
    # Using Field IDs

    MultipleIdFilter takes 2 parameters, field Id and value id. Multiple filters can be added and ‘operatorType' is set to ‘AND’.


    View sample code

    var idFilters = ArrayList<FilterBase>() idFilters.add(IdFilter("76678", "5001")) idFilters.add(IdFilter("76678", "5021"))  
    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath). multipleFilter(MultipleIdFilter(idFilters, FilterOperatorType.AND)).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    # Using Field Names

    MultipleNameFilter takes 2 parameters, field name and value name. Multiple filters can be added and ‘operatorType' is set to ‘AND’.


    View sample code

    var nameFilters = ArrayList<FilterBase>() nameFilters.add(NameFilter("vColor_uFilter", "Black")) nameFilters.add(NameFilter("vColor_uFilter", "White"))  
    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath). multipleFilter(MultipleIdFilter(nameFilters, FilterOperatorType.AND)).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception)                                       
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    12.2. OR
    # Using Field IDs

    MultipleIdFilter is takes 2 parameter, field Id and value id. Multiple filters can be added and ‘operatorType' is set to ‘OR’.


    View sample code

    var idFilters = ArrayList<FilterBase>() idFilters.add(IdFilter("76678", "5001")) idFilters.add(IdFilter("76678", "5021"))  
    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath). multipleFilter(MultipleIdFilter(idFilters, FilterOperatorType.OR)).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    # Using Field Names

    MultipleNameFilter takes 2 parameters, field name and value name. Multiple filters can be added and ‘operatorType' is set to ‘OR’.


    View sample code

    var nameFilters = ArrayList<FilterBase>() nameFilters.add(NameFilter("vColor_uFilter", "Black")) nameFilters.add(NameFilter("vColor_uFilter", "White"))  
    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484"))  
    val browseQuery = BrowseQuery.Builder(categoryPath). multipleFilter(MultipleIdFilter(nameFilters, FilterOperatorType.OR)).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    13. Sort

    The sort parameter is used to rank the products based on specified fields in the specified order.
    Sort can be done on a single field or multiple fields.

    13.1. Single Field

    fieldName: The field on which the sort is applied.
    sortOrder: The order in which the sort is applied. This value can be "ASC" (for
    ascending) or "DSC" (for descending)


    View sample code

    var fieldsOrder = ArrayList<FieldSortOrder>() fieldsOrder.add(FieldSortOrder("vPrice", SortOrder.ASC))  
    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath). fieldsSortOrder(fieldsOrder).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception)                                       
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    13.2. Multiple Fields

    Here 2 or more FieldSortOrder instances are added.


    View sample code

    var fieldsOrder = ArrayList<FieldSortOrder>() fieldsOrder.add(FieldSortOrder("vPrice", SortOrder.ASC)) fieldsOrder.add(FieldSortOrder("title", SortOrder.DSC))  
    val categoryPath = CategoryIdPath(arrayOf("FA", "FA0484")) val browseQuery = BrowseQuery.Builder(categoryPath). fieldsSortOrder(fieldsOrder).build()  
    client.browse(browseQuery, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
    Log.d("Client Response",json.toString())  
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Integrating Unbxd Recommendations

    Unbxd Recommendations offers a wide range of widgets for every page. Recommendations API returns product details for options like MoreLikeThis, RecentlyViewed, etc.

    The Unbxd SDK supports the following types of widgets:

    1. Recommended For You
    2. Recently Viewed
    3. More Like This
    4. Viewed also Viewed
    5. Bought also Bought
    6. Cart Recommendations
    7. Top Sellers
    8. Top Sellers - Category page
    9. Top Sellers - Product page
    10. Top Sellers - Brand
    11. Complete the look.

    Let's look at how to implement each of these.

    1. Recommendations for you

    The Recommended For You method returns recommendations based on the shopper’s interaction history on the online store or app.


    View sample code

    val userId = client.userId()  
    val recommendedForYour = RecommendedForYourRecommendation.Builder(userId.id).region("US").currency(" USD").build()  
    client.recommend(recommendedForYour, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception)                                       
                                          {
                                          Log.d("Client Response",errorMessage) 
                                          }
                                          }
    )
    

    UID should be unique string value which is generated by the app and retained throughout the application life. * region: ISO standard country code. * currencyFormat: ISO standard currency code. * responseFormat: .JSON or XML

    2. Recently Viewed

    The Recently Viewed method recommends products that were recently viewed by a shopper.


    View sample code

    val recentlyViewedRecommendation = RecentlyViewedRecommendation.Builder(userId.id, "2312314").region("US").currency("USD").build()  
    client.recommend(recentlyViewedRecommendation, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    3. More like these

    The "More Like These" method is built to recommend products similar to the one being viewed on the Product Detail Page (PDP).


    View sample code

    val moreLikeThisRecommendation = MoreLikeThisRecommendation.Builder(userId.id, "2312314").region("US").currency("USD").build()  
    client.recommend(moreLikeThisRecommendation, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    4. Viewed also viewed

    As the name suggests, this method recommends products viewed by other shoppers.


    View sample code

    val viewedAlsoViewedRecommendation = ViewedAlsoViewedRecommendation.Builder(userId.id, "2312314").region("US").currency("USD").build()  
    client.recommend(viewedAlsoViewedRecommendation, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    5. Bought also bought

    Similar to the "Viewed also Viewed" method, the Bought also Bought method recommends products bought by other shoppers.


    View sample code

    val boughtAlsoBoughtRecommendation = BoughtAlsoBoughtRecommendation.Builder(userId.id, "2312314").region("US").currency("USD").build()  
    client.recommend(boughtAlsoBoughtRecommendation, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    6. Cart Recommendations

    This method recommends complementary products on the "Cart page" for those present in the shopper's cart.


    View sample code

    val cartRecommendation =  
    CartRecommendation.Builder(userId.id).region("US").currency("USD").build()  
    client.recommend(cartRecommendation, object : ICompletionHandler  
                                          { 
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    7. Top Sellers - Home page

    This method recommends top selling products bought from the homepage.


    View sample code

    val homePageTopSellersRecommendation = HomePageTopSellersRecommendation.Builder(userId.id).region("US"). currency("USD").build()  
    client.recommend(homePageTopSellersRecommendation, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception)                                       
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    8. Top Sellers - Category page

    This method recommends top selling products from a specific category.


    View sample code

    val categoryTopSellersRecommendation = CategoryTopSellersRecommendation.Builder(userId.id, <category_name>).region("US").currency("USD").build()  
    client.recommend(categoryTopSellersRecommendation, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    9. Top Sellers - Product page

    This method recommends top selling products from a specific product.


    View sample code

    val pdpTopSellersRecommendation = PDPTopSellersRecommendation.Builder(userId.id, "23121").region("US").currency("USD").build()  
    client.recommend(pdpTopSellersRecommendation, object : ICompletionHandler  
                                          {
                                           override fun onSuccess(json: JSONObject, response: Response) 
                                          {
                                          Log.d("Client Response",json.toString()) 
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    10. Top Sellers - Brand

    This method recommends top selling products from a specific brand.


    View sample code

    val brandTopSellersRecommendation = BrandTopSellersRecommendation.Builder(userId.id, "Nike").region("US").currency("USD").build()  
    client.recommend(brandTopSellersRecommendation, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    11. Complete the look

    The Complete the Look method showcases curated products on a PDP that are usually associated with the original product.


    View sample code

    val completeTheLookRecommendation = CompleteTheLookRecommendation.Builder(userId.id, "23121").region("US").currency("USD").build()  
    client.recommend(completeTheLookRecommendation, object : ICompletionHandler  
                                          {
                                          override fun onSuccess(json: JSONObject, response: Response) 
                                          { 
                                          Log.d("Client Response",json.toString())
                                          }
                                          override fun onFailure(errorMessage: String, exception: Exception) 
                                          { 
                                          Log.d("Client Response",errorMessage)
                                          } 
                                          }
    )
    

    Sample App

    For sample app, click the link below:
    Android Home Decor