Installing the SDK

The Benji Connect SDK can be added to your application by including the SDK script in your html headers.

<script src="https://d1ochlq3jv1msw.cloudfront.net/connect/sdk/connect-sdk.js"></script>

Initializing the SDK

The SDK is initialized with the following parameters :

token
string
required

This is the token that you created using the Create Token API in the previous step

onSuccess
callbak function
required

This is your callback function method, which will be triggered when a member has succesfully connected with a partner loyalty program

onExit
callbak function
required

This is your callback function method, which will be triggered when a member has closed the Benji Connect Modal. Note that this function can be whether the onSuccess callback has been called or not.

onError
callbak function
required

This is your callback function method, which will be triggered when a member encountered an error while connecting with their account.

onEvent
callbak function
required

This is your callback function method, which will be triggered for various events throughout the user journey within the Benji Connect flow.

let sdk = null;

function initializeSDK(token) {
    sdk = new AuthSDK({
        token: token,
        onSuccess: (token, metadata) => {
            console.log('Connect successful', token, metadata);
                      
            // Handle success event in your code, such as displaying a sucess message on your site and storing the returned token
           
        },
        onExit: () => {
            console.log('Connect flow exited');
            // Handle close Connect flow, such as log in your systen or disokay a message to the user
        },
        onEvent: (event, metadata) => {
            console.log('Event received:', event);
            //Listen and react to various events in the user flow.
        }
    });
}