Build UI
Modify Response

Overview

6min

Modify Response

To modify a search response, the incoming response object is intercepted and any of the available datapoints can be manipulated as needed prior to being sent to the UI templates.

There are two steps:

  1. Intercept the incoming response object
  2. Identify the data object to be modified



Intercept the Response Object

Any of the product attributes are available to be modified as needed or otherwise inject any custom values.

Use the klevu.modifyResponse function to intercept the response data.

klevu.modifyResponse("<scope>", "<callback>");



Identify the Data Object

The simplest way to get acquainted with the available data is to use console.log and review the output.

klevu.modifyResponse("landing", function(data, scope){ console.log('klevu.modifyResponse', data); });

For example, the following snippet loops through each record in the productList result and outputs the product object to the browser's developer console.log

klevu.modifyResponse("all", function(data, scope){ klevu.each(data.template.query.productList.result, function(indx, product) { console.log('Klevu Response Product ' + indx, product); }); });



Determining Scope

Note that each klevu.modifyResponse function requires definition within the corresponding scope of the override. We will chart these below.

Scope

Description

all

Applies to all scope modules

quick

QuickSearch module

landing

SRLP module

catnav

Category module

full_page

Both SRLP and Category modules (same as "landing,catnav")

Multiple klevu.modifyResponse functions can be applied in the same or mixed scope.



Examples

Please see the Modify Response Examples section for details of common uses.



.

Updated 30 Oct 2023
Doc contributor
Doc contributor
Doc contributor
Did this page help you?