Adaptive JS SDK
Current Adaptive JS SDK Version: 0.0.12
Version History (change log)
Quick Start Guide
This guide will show you how to install and use the Adaptive JS SDK.
Prerequisites
Adaptive JS SDK operates as long as we have the Adaptive Session Token (AST) and we pass it to the SDK upon instantiation.
Installation
You can use either npm or yarn to fetch and install the Adaptive JS SDK in your project, as described below.
npm
Create an .npmrc
file in the root of your codebase with the following content:
@futurae-public:registry=https://git.futurae.com/api/v4/projects/148/packages/npm/
Install the package:
$ npm i @futurae-public/adaptive-js
yarn
Create an .yarnrc
file in the root of your codebase with the following content:
"@futurae-public:registry" "https://git.futurae.com/api/v4/projects/148/packages/npm/"
Install the package:
$ yarn add @futurae-public/adaptive-js
Access
The Adaptive JS SDK is built by using the Universal Module Definition pattern, so it can be accessed with the following ways:
- ES Module
- Global Variable
- AMD module
ES Module
Call it as an ES6 module in your codebase:
import Adaptive from '@futurae-public/adaptive-js';
//Pass the adaptive_session_token received from the Auth API /srv/auth/v1/user/adaptive/init endpoint, to the Adaptive JS SDK
const sdk = new Adaptive('adaptive_session_token');
Global Variable
Use it as a global variable:
<script src="./node_modules/@futurae-public/adaptive-js/dist/adaptive.min.js"></script>
<script>
const Adaptive = adaptive.default;
//Pass the adaptive_session_token received from the Auth API /srv/auth/v1/user/adaptive/init endpoint, to the Adaptive JS SDK
const sdk = new Adaptive('adaptive_session_token');
</script>
Usage
This is a basic example of how to call the Adaptive JS SDK’s most important function which is sendObservations
:
|
|
SDK Reference
Contents
Class: Adaptive
Constructors
Methods
Constructors
constructor
+ new Adaptive(adaptive_session_token
: Adaptive Session Token): Adaptive
Parameters:
Name | Type | Description |
---|---|---|
adaptive_session_token | String | The adaptive session token |
Returns: Adaptive
Methods
sendObservations
▸ sendObservations():
Sends the collected Adaptive observations to the Futurae backend. Requires the adaptive_session_token
which was retrieved from the server-side when calling Initialize Adaptive Session.
Returns: Promise
A promise that is fulfilled if the Adaptive send observations operation is successful or rejected with an error if the operation fails.