Make sure that you have all your credentials and necessary assets available before you start.
The Search SDK uses a javascript call to create an Inbenta User Interface (UI) quickly and easily. You can set certain configuration parameters to tune it to your specifications.
This page describes to set up the Search SDK and introduces available configuration and customization options.
All examples shown are set in a Production environment.
The Search SDK consists of three different tools:
First, you must include the Search SDK in your website. The Search SDK is available in two versions, with or without polyfills. Polyfills transform newer code methods into methods compatible with IE11 browsers by updating the JS prototype objects. Use a script tag to integrate the Search SDK in a webpage. If you need compatibility with IE11 browsers, use the version with polyfills:
<script src="https://sdk.inbenta.io/search/<version>/inbenta-search-sdk.js"></script>
If you do not need compatibility with IE11 browsers, you can use the version without polyfills:
<script src="https://sdk.inbenta.io/search/<version>/inbenta-search-sdk-no-polyfills.js"></script>
Please keep in mind that Inbenta APIs accept HTTPS requests only. If you need to send API requests using other protocols, the only way to do this is to set up a proxy to convert those protocols to the HTTPS protocol before the requests reach the API.
When you set up the SDK for your Inbenta product, you need to specify the version like this:
<script src="https://sdk.inbenta.io/search/<version>/inbenta-search-sdk.js"></script>
Versions are written in MAJOR.MINOR.PATCH format.
• For best security and performance, Inbenta recommends that you store these files on your own server.
• If you decide to use Inbenta-hosted SDK files, Inbenta strongly recommends that you use a MAJOR.MINOR.PATCH version, as well as a SDK Subresource Integrity for additional security for your website.
Examples
<script src="https://sdk.inbenta.io/search/1/inbenta-search-sdk.js"></script>
<script src="https://sdk.inbenta.io/search/1.19/inbenta-search-sdk.js"></script>
<script src="https://sdk.inbenta.io/search/1.19.1/inbenta-search-sdk.js" integrity="sha384-viZG/3OfKopmj0koWN4ppT4qZ+eAFy5BMTYAIiWcmaDyJDPzVzIW+ajLnV4tfTcl" crossorigin="anonymous"></script>
Starting from version 1.27.0 (2019.05.15), the SDK automatically logs the version in the user info with two keys. sdk_selected_version
logs the version specified in your script (which can be MAJOR, MAJOR.MINOR, or full, depending on your preference). sdk_used_version
logs the full version that was actually used. This allows the Dashboards to show the version used in a specific session. To configure the Dashboards, contact your Inbenta representative.
An SRI check is available for this SDK. For more information, see the SDK Subresource Integrity page. Remember that SRI only works with full versions.
For a complete description of keys and authorization methods, see the Authorization section.
You need a valid access token to use Inbenta APIs. Follow the steps listed in the Authorization section to set up your page with your token and refresh it automatically.
To create your SDK with a domain key, first obtain the key, then use createFromDomainKey
like this:
var sdk = InbentaSearchSDK.createFromDomainKey(<your_Domain_Key>,<your_API_Key>);
To create our SDK using an access token, first make a server-side call to the /auth
endpoint, then use createFromAccessToken
like this:
var sdk = InbentaSearchSDK.createFromAccessToken(<your_access_token>,<your_API_Key>);
If you create the SDK with an access token, you must call the server before it expires to receive a new access token. (See the Authorization section.)
If the function returns a promise and the access token cannot be refreshed, it will retry the calls made while the token was valid. For more information, consult Promises support.
Example
In this example, the AJAX call returns the same access token and expiration as the endpoint does. The response is in JSON format:
sdk.setCallbackWhenInvalidAccessToken(function(){
return new Promise((resolve, reject) => {
var xhttp = new XMLHttpRequest();
xhttp.addEventListener( 'load', function() {
if (this.readyState == 4 && this.status == 200) {
var object = JSON.parse(this.responseText);
sdk.client.setAccessToken(object.accessToken, object.expirationAt);
resolve('success');
} else {
reject('error');
}
});
xhttp.open("GET", "?action=getAccesToken", true);
xhttp.send();
});
});
This is the recommended integration for the Search SDK. This integration prevents sending extra requests to the API. The idea is that the SDK sends /auth
requests to the API automatically when it is set up. You want to prevent these unnecessary requests when the user does not use the Search SDK.
Inbenta recommends that you use this integration in the following scenarios:
To summarize, you should not load the SDK until you are sure that the user is using the Search functionality. To do this, use the different DOM events: this way, you avoid sending extra /auth
requests when users simply access the page without using the functionality.
Each situation is different and it depends a lot on the kind of page you want to create.
Example In the following example, you wait until the user puts the focus on the input element before loading the SDK. If the user does not put the focus on the input element, the SDK does not load.
<body>
<div id="app">
<input id="input" type="text">
<div class="container">
<div id="results"></div>
</div>
</div>
<script src="https://sdk.inbenta.io/search/1.X.X/inbenta-search-sdk.js"></script>
<script>
var domainkey = '<your_Domain_Key>';
var apiKey = '<your_API_Key>';
var sdk;
document.querySelector("#input").addEventListener('focus', function(e){
if (!sdk) {
// Create the SDK instance using your access token and configuration.
sdk = InbentaSearchSDK.createFromDomainKey(domainkey, apiKey);
// Components initialization
}
});
</script>
</body>
This integration is not recommended. Use it only if there is no other option.
This integration may apply to the following scenarios:
SearchBox
component, and iprints the results on the page automatically when a user accesses it.This implementation loads the SDK on the page as the page loads. This means that every time a user accesses this page, it sends an /auth
request, because it uses the Search SDK.
Example This example below loads the integration with the page, which means that the entire SDK functionality is loaded when the user enters.
<body>
<div id="product-tabs"></div>
<div id="inbentaContainer">
<div id="inbenta"></div>
</div>
<script type="text/javascript" src="https://sdk.inbenta.io/search/1.X.X/inbenta-search-sdk.js"></script>
<script>
var domainkey = '<your_Domain_Key>';
var apiKey = '<your_API_Key>';
var options = {
"stats":{
"text":"Results {{ first }}-{{ last }} of {{ totalResults }} for: {{ query }}"
},
"results":{
"resultsPerPage":5
},
"searchBox": {
"autocompleter":{
"settingsToShow": ["URL"],
"showViewAllButton":false
}
},
"refinementLists":{"refinements":[]},
"refinementTabs":{attributeName: 'XXX'},
"router": true
};
// Create the SDK instance using your access token and configuration.
var sdk = InbentaSearchSDK.createFromDomainKey(domainkey, apiKey);
var builder = sdk.build('#inbenta',options);
</script>
</body>
You can use templates
to customize how to render a component with string-based templates or functions.
In text format, templates must be written using mustache. You can only do this for specific parts of the rendered component. Most of the components allow this functionality. Please refer to the specific component documentation and SDK templates for more information.
<div id="app"></div>
<script>
sdk.build('app', '#app', {
results: {
templates: {
item: '<a href="{{ __url }}" {{{ __clickable }}}>'
+ '{{ title }} ({{ id }})'
+ '</a>'
+ '<p>{{ attributes.PARAGRAPHS }}</p>'
}
}
});
</script>
Upon loading, the SDK automatically calls the API to initiate a session, either with the createFromAccessToken
function or createFromDomainKey
. This is done from the /tracking/session
endpoint.
Main section: Styles
You can change the skin using the skin
parameter. There are two skins available and three choices:
space-cowboy
: (default) loads the space-cowboy
skin using the space-cowboy.css file.ocean-flow
: loads the ocean-flow
skin using the ocean-flow.css file.tatooine-sunset
: loads the tatooine-sunset
skin using the tatooine-sunset.css
file.imperial-black
: loads the imperial-black
skin using the imperial-black.css file.teth-sunrise
: loads the teth-sunrise
skin using the teth-sunrise.css file.newtral
: loads the newtral
skin using the newtral.css file.You can also load the SDK without a skin. To do so, set the skin
parameter to false
:
false
: only loads the layout.css file. This loads only layout information, without loading any skin.If you want to use your own design, Inbenta recommends that you load a skin, then change specific styles using the CSS guide.
config = {
skin: 'ocean-flow',
}
Remember that if you modify the structural elements, it will affect how the product is displayed. Inbenta strongly recommends that you leave structural elements unchanged.
If you want to build your own CSS from scratch, you can disable the default skin, which will load the layout.css only:
config = {
skin: false,
}
Then, include your own CSS link:
<link rel="stylesheet" href="https://clientwebsite.com/base.css"></script>
The SDK modifies the HTML class to add browserDetection
to ensure that the styles are correctly displayed in different browsers.
The client can be used either alone or with the normal SDK integration. To access it with the SDK, use the .client
parameter:
sdk.client.<client thing>
You have to start the SDK before using the client.
For more information, see the js-client section.
See the external management section.
When using the Domain token, the SDK automatically refreshes the Access token when needed (see the Authorization section). When using the Access token integration, it depends on the configuration parameters autoRefresh
and expirationTime
. Using these parameters, you can also autorefresh the AccessToken when needed.
If you prefer a custom handling when the Access token expires, you can use the method setCallbackWhenInvalidAccessToken
available in the SDK.
The JavaScript SDK depends on:
The following browsers are supported:
Supported in WebView mobile applications using: