Javascript API

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.

1) 	<script type="text/javascript">
2)	window.crobox = window.crobox ||[]; 
3)	crobox.push(function(crobox){ 
4) 	// Crobox API is now ready to used and methods are available
5) 	}); 
6)	</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:

Register a new event-listener on the event system

crobox.on(event, callback)
	

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

De-register an existing event-listener on the event system

crobox.off(event, callback)
		

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

Fire a new event in the event system

crobox.emit(event, args...)
	

Argument Type Description
event string Name of the event that you want to emit a new event for
args... vararg Extra arguments that are passed will be added as arguments to the callback function that are registered on the event.

Still need help? Contact Us Contact Us