Recommendation Callbacks

The JS API can be used to register callbacks to hook into the recommendation events. To register a listener for a callback, use api.listen(callbackId, callbackFunction) function.

Post Render Callback

Called when Nosto has responded and finished recommendation placement.

nostojs(api => {
  api.listen('postrender', event => {
    console.log(event.filledElements);
    console.log(event.unFilledElements); 
  });
});

Fields

FieldTypeReason

filledElements

Array

Contains a list of recommendation slots that contain recommendations

unFilledElements

Array

Contains a list of recommendations slots that did not have get recommendations.

Pre Render Callback

Called when Nosto has responded but not yet rendered content. The event contains information about the visitor's preferences.

nostojs(api => {  
  api.listen('prerender', event => {    
    console.log(event);
  });
});

Fields

FieldTypeReason

affinityScores

Object

Describes visitor's most preferred brands and categories, the object has two attributes top_brands and top_categories which are arrays that contain maximum 5 most preferred brands/categories for the visitor. Example content:

{

top_brands:[

{name:"Acme", score:0.8},

{name:"Universal", score:0.3}

]

}

segments

Object

Information about which segments the visitor falls into. active_segments field contains a list of segment identifiers that were active on the latest request to Nosto. Segment identifiers can be retrieved from the Nosto backend, or queried from the GraphQL API. Example content:

{

active_segments:[

{id:"5a497a000000000000000004"},

{id:"5aa12b8960b2352d326d77f1"}

]

}

Last updated