Javascript API

This document describes the functionality available of the Crobox Javascript API.

Accessing the API

The Javascript API exposes one global variable onto the window object called crobox

Because the Crobox Javascript library may be loaded asynchronously, for example, using a tag manager, you should use the following logic to get a callback when the API is ready for usages.

<script type="text/javascript">
window.crobox = window.crobox || [];
crobox.push(function(crobox) {
// Crobox API is now ready to used and methods are available
});
</script>

Event system

There is an events API available that can be used to communicate with the third-parties to have a stable connection between the Crobox Platform and the integrating party. This could be used to integrate with third-party analytics or:

crobox.on(event, callback)

Use this method to register a new event-listener on the event system.

Argument

Type

Description

event

string

Name of the event that needs to be listened to.

callback

function

Functionality that needs to be executed when the event fires, as arguments it received the extra arguments that are added when an event is fired

crobox.off(event, callback)

Use this method to de-register an existing event-listener on the event system. Note: for this, you do need to have a reference to the existing callback.

Argument

Type

Description

event

string

Name of the event that needs to be stopped listening to

callback

function

Functionality that was previously registered

crobox.emit(event, args...)

Use this method to fire a new event in the event system.

Argument

Type

Description

event

string

Name of the event that you want to emit a new event for

args...

vararg

Extra argument that are passed will be add as arguments to the callback function that are registered on the event.