JavaScript events

The Boxzilla plugin comes with several JavaScript events for you to hook into whenever certain box events occur.

You can run register your JavaScript functions by calling the Boxzilla.on( eventName, callback ) function. When the specified box event occurs, your function will be executed.

Here's an example where we run a function whenever a box is shown to a visitor.

Boxzilla.on('box.show', function(box) {
   console.log("Showing box " + box.id);
});

Available events

The following events are available.

box.show Fires when a box becomes visible
box.dismiss Fires when a box is manually dismissed
box.hide Fires when a box is hidden

Example

The following example demonstrates how to track an event with Hubspot.

var _hsq = window._hsq = window._hsq || [];
_hsq.push(["trackEvent", {
    id: "BOXZILLA_SHOW",
    value: box.id
}]);

Please note that Boxzilla initializes on the window.load event. This means that if you are trying to show a box immediately after loading a page, you have to ensure your code runs after this event is fired:

window.addEventListener('load', () => {
   Boxzilla.show(500)
});

Was this article helpful? ·