JS Client On SDK

The JS-Client can be a useful tool to perform specific actions or to create a new custom component.

Usage

The JS-Client is a property of the SDK. You can use it after the SDK is initialized. You must wait until the SDK is ready before you can use it. For more information, see JS-Client.

sdk.client.untilReady().then( function (response) {
    sdk.client.<your_component>
});
Example

When you use the Last chance component, you must send the contact_ticket event when the user send a ticket. To send this event, you must use the client. For more information, see Last chance.

The following example sends the event after a user clicks on the "Submit" button:

var lastChance = sdk.component('lastChance', '#last-chance', {});
lastChance.linkToInput(document.getElementById('textarea'));
// Submit form
document.getElementById('form').addEventListener('submit', function(event) {
    lastChance.show();
});
lastChance.$on('submit', function() {
    // Send ticket
    <code to send the ticket>
    // Track the contact_ticket event
    sdk.client.track(
        'contact_ticket',
        {
            'value': lastChance.getQuery()
        }
    );
});

If you want to manage clicks from external instances, you must use the client to send the external_click event. For more information, see External management page.

//SDK creation
var sdkA = InbentaKmSDK.createFromDomainKey("Domain_Key_instance_a","API_Key_instance_a");
var sdkB = InbentaKmSDK.createFromDomainKey("Domain_Key_instance_b","API_Key_instance_b");

//Searchbox creation
var searchBox = sdkA.component('searchBox', '#search-box'); //sdk of the searchBox is not important

//Results creation
var resultsA = sdkA.component('results', '#resultsA');
resultsA.linkToSearchBox(searchBox);
var resultsB = sdkB.component('results', '#resultsB');
resultsB.linkToSearchBox(searchBox);

//Manage click in instance A to send external click to instance B
resultsA.$on('expand', function(content){
    sdkB.client.track('external_click',{externalCode:content.tracking.externalCode,searchCode:resultsB.getSearchCode()});
});

//Manage click in instance B to send external click to instance A
resultsB.$on('expand', function(content){
    sdkA.client.track('external_click',{externalCode:content.tracking.externalCode,searchCode:resultsA.getSearchCode()});
});