Completing the Integration

In this section you will find a series of more advanced functionalities that require a more complex development. We recommend that a developer be in charge of this configuration.

Callbacks offered by the SDK

Our SDK offers various callbacks that help you have greater control of the execution flow and implement custom behaviors.

This is a code snippet to use a callback that does the initialization of indigitall. It is necessary to add the indigitall.init inside the onDigitallLoaded method and load it into the script.

<script>
  function onNewUserRegistered(device){}

  function onIndigitallInitialized(permissions,device){}

  function onLocationUpdated(location){}

  function onError(error){}

  function requestPushPermission(permission){}

  function requestLocationPermission(permission){}

  // Remember to replace with your appKey
  function onIndigitallLoaded(){
    indigitall.init({
      appKey:'YOUR_APPKEY',
      workerPath:'./ROOT_FOLDER/worker.min.js',
      requestLocation: true,
      onInitialized: onIndigitallInitialized,
      requestPushPermission: requestPushPermission,
      onNewUserRegistered: onNewUserRegistered,
      requestLocationPermission: requestLocationPermission,
      onLocationUpdated: onLocationUpdated,
      onError: onError            
    });
  }
</script>

<script src="./ROOT_FOLDER/sdk.min.js" onload="onIndigitallLoaded()" ></script>

Initialized SDK
The onIndigitallInitialized method will execute when the SDK finishes initializing and the device is ready to receive notifications from indigitall.

To receive as parameter:

  • An array of Permission objects. The first item is the status of the notification permission. The second item is the status of the locate permission
  • A Device object with the information associated with the device.

Here is an example that prints logs about the status of permissions and device information.

<script>
  function onIndigitallInitialized(permissions,device){
    console.log("Push Permission: ",permissions.push)
    console.log("Location Permission: ",permissions.location)
    console.log("Device: ", device)
  }
</script>

<script
  src="/en/indigitall/sdk.min.js"
  onload="indigitall.init({
    ...
    onInitialized: onIndigitallInitialized
    ...
  })"
  async>
</script>

New registered device
To verify that a user has registered, you need to associate the callback onNewUserRegistered in the initial configuration.

You can check the code extract with the implementation below:

<script>
  function onNewUserRegistered(device){
    console.log("Device onNewUserRegistered: ",device)
  }
</script>

<script
  src="/en/indigitall/sdk.min.js"
  onload="indigitall.init({
    ...
    onNewUserRegistered: onNewUserRegistered
    ...
  })"
  async>
</script>

An error has occurred
Unexpected behavior can occur within the entire SDK flow.
To check the error logs, you need add 'onError' callback to initial configuration. To check the error logs in the log, the callback onError must be added for the initial configuration.

<script>
  function onError(error){
    console.log(error);
  }
</script>

<script
  src="/en/indigitall/sdk.min.js"
  onload="indigitall.init({
    ...
    onError: onError
    ...
  })"
  async>
</script>