Listen to Caast Events
If you want to implement custom analytics or override some Caast behaviour, you may want to start listening to our emitted events. Caast emits a lots of useful events that you may use, the complete list of events is available here.
This example show you how to listen to all our events, but do not hesitate to adapt it to listen only what you need.
In order to start listening to those events, please follow this really simple tutorial:
- Asynchrone
- Synchrone
info
If your listener is behind a cookie consent condition, or is not executed at the same time Caast is loaded, please use this template
var checkExist = setInterval(function () {
if (typeof window.caast !== 'undefined') {
if (typeof window.caastIsListening === 'undefined') {
window.caast
.on('all', function (response) {})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);
info
If this code is executed at the same time you load Caast main library, then choose this template
document.addEventListener('caast.onLoaded', function (response) {
if (!response.detail.preload && typeof window.caast !== 'undefined') {
window.caast.on('all', function (response) {});
}
});