Installation

The library is available for both node.js and the browser.

To use with Node.js:

$ npm install @lableb/javascript-sdk

To use on the browser include the following script in your html:

<script
  type='text/javascript'
  src='https://unpkg.com/@lableb/javascript-sdk/browser/lableb.min.js'
></script>

Initialize the sdk

Node.js:

const LablebSDK = require('@lableb/javascript-sdk');

const lableb = new LablebSDK('project name', 'search token', 'indexing token');

Browser:

const lableb = new window.LablebSDK(...)

NOTES

  • Use the library on the browser for Search, Autocomplete, Recommendations and Feedbacks.

  • DO NOT EXPOSE YOUR INDEXING TOKEN ON THE BROWSER, PUT AN EMPTY STRING INPLACE OF INDEXING TOKEN.

  • Use the library on the server side for Indexing and Deleting.

  • Indexing and Deleting won't work in the browser.

Configure session ID generation

Warining

This is required when using Node.js for search APIs

If you don't implement this when using Node.js, the analytics won't be accurate

A session ID is important for analytics and it's unique by each user session.

On the browser the library will automatically generate a random session ID for each session and send it to Lableb for analytics.

But on Node.js, we cannot know which user is sending the request, so you have to give each user a session ID and this session ID is unique by each user and stays the same for a period of time, for example 2 hours.

To tell the plugin how to know which user is sending the request, implement the function below and return the session ID of the user.

lableb.client.getSessionID = function () {
  return 'my custom session id of the user';
};

for example you could return the user ID as a session id, or generate a persistent session ID for the user in someway.

How helpful was this ?

star-emptystar-filledstar-emptystar-filledstar-emptystar-filledstar-emptystar-filledstar-emptystar-filled