HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Search results page

Describes how to configure tracking on a search results page for Javascript 1.3 and 1.4.

📘

Note

This information applies to JavaScript API versions 1.3 and 1.4. See information for versions 1.1-1.2 here.

You can track the search results page by providing the search term used and the reference codes of the returned products. Ensure the reference codes match the codes supplied in the product catalog feed.

Name Descriptions and usage
searchResults

Note: From version 1.3 of the JavaScript API, the request payload for search tracking has changed in order to track more accurate information. 

  term [String]

The search term used.
  personalisationAttributesId [Optional] [String]

The unique identifier of the set of recommendations attributes generated by the recommendations request.

Currently for use with Personalized Search & Navigation (formerly Find) only. Use this ID in tracking requests to identify the set of recommendations attributes.
  totalNumberOfResults [Int]

The number of search results.
  pageNumber [Optional] [Int]

The number of the current page.
  resultsOnPage [Optional] [Int]

The number of search results on the page.

If not provided, the value defaults to the total number of results.
  topResults The product codes of the top 3 search results.

An array of 3 elements containing a refCode property that indicates the reference codes of the top products returned by the search term.
    refCode The product ID returned in the search results.

The refCode provided here must exactly match the refCode (guid) specified in the product catalog feed.

Note: If you have a custom feed, contact Optimizely to find out which field from the feed is used as a product identifier.

  filters [Optional]

A list of filters on the page. See examples in the code sample below.

An array of elements containing the following parameters.
    filter [String]

The attribute name of the filter.
    operator [Optional]

The operation between the filter and the value.

[String]
  • IN  = include
  • EX  = exclude
  • BW  = between for ranges
  • GT  = greater than
  • LT  = less than
    values List[String]

The attribute values of the filter.

Example: Valid search

{
      "type"          : "searchresults",
      "lang"          : "en-gb",
      "searchResults" : {
                          "term"                        : "bags",
                          "personalisationAttributesId" : "abcd1234",
                          "totalNumberOfResults"        : 50,
                          "pageNumber"                  : 1,
                          "resultsOnPage"               : 18,
                          "filters"                     : [{
                                                             "filter"   : "colour",
                                                             "operator" : "IN",
                                                             "values"   : ["red", "orange", "yellow"]
                                                            }, 
                                                            {
                                                              "filter"   : "price",
                                                              "operator" : "BW",
                                                              "values"   : ["0", "50"]
                                                            }, 
                                                            {
                                                              "filter"   : "size",
                                                              "operator" : "IN",
                                                              "values"   : ["XS", "S"]
                                                           }],
                          "topResults"                   : [
                                                             {"refCode" : "RC1"}, 
                                                             {"refCode" : "RC2"}, 
                                                             {"refCode" : "RC3"}
                                                           ]
                        }
    }

Example: 0-search

{
      "type"          : "searchresults",
      "lang"          : "en-gb",
      "searchResults" : {
                          "term"                        : "bags",
                          "personalisationAttributesId" : "abcd1234",
                          "totalNumberOfResults"        : 0,
                          "pageNumber"                  : 1,
                          "resultsOnPage"               : 0,
                          "filters"                     : [{
                                                             "filter"   : "colour",
                                                             "operator" : "IN",
                                                             "values"   : ["red", "orange", "yellow"]
                                                            }, 
                                                            {
                                                              "filter"   : "price",
                                                              "operator" : "BW",
                                                              "values"   : ["0", "50"]
                                                            }, 
                                                            {
                                                              "filter" : "size",
                                                              "operator" : "IN",
                                                              "values"   : ["XS", "S"]
                                                           }],
                          "topResults": []
                        }
    }

📘

Note

You can also add the customAttributes or customer elements to this page tracking request. For more information, see Add customAttributes or customer elements (Optional).