Developers

Cross Selling

Cross selling

The cross selling section is a module to manage cross selling with Inbenta.

Getting started

The first thing to do is configure the cross selling in the Knowledge module. This example sets a cross selling with id = 1 and the attribute 'img'.

Once you have the cross selling configured in the Knowledge module, call the method of the client to retrieve the cross selling.

This example uses the SDK, not the client directly. If you use the client, you need to generate a session to track the information with the generateSession method.

// We should call a client method when sdk is ready.
sdk.untilReady().then(function(){
  sdk.client.getCrossSellingById(1).then(function(response){
    manageCrossSelling(response.data.results);
  });
});

When you receive the cross selling endpoint results, print them in the crossSelling div and add the click event to track click in each cross selling:

// HTML for cross selling
<div id="crossSelling"></div>
// Function to manage cross selling 
function manageCrossSelling(results){
  var crossSellings = document.getElementById("crossSelling");
  results.forEach(function(result) {
    // Create img
    var element = document.createElement("img");
    element.className = "cross-selling__"+result.name;
    element.src = result.attributes.img;

    // Manage click
    element.onclick = function (e){
      var code = result.tracking.clickCode;
      sdk.client.track('click', {code: code});
    }

    // Append to crossSelling div
    crossSellings.appendChild(element);
  });
}