Skip to main content

Link Caast to a tracking solution

As we said, There is no place like home, and you may want to retrieve inject some Caast events into your own data solution.

This tutorial is for you, we have tried to provide you with the main tracking solutions and we hope you find the right example to meet your needs. Do not hesitate to contact us if you use another solution and we will be happy to help you with the implementation.

info

Those examples are designed to expose simple data collection scenario. Do not hesitate to dive into advanced tutorials in order to compute advanced data.

caution

Collecting data is subject of user's approval throught your own GDPR policies, please be sure to use those scripts after your user has given his consent.

/**
* Send Caast events into Google DataLayer
* */
var checkExist = setInterval(function () {
if (typeof window.caast !== 'undefined') {
if (typeof window.caastIsListening === 'undefined') {
window.caast
.on('all', function (response) {
/**
* Caast event name
* */
var eventName = response.type;

/**
* Retrieve product ref if available
* */
var productRef = '';
if (response.data.product_ref) {
productRef = response.data.product_ref;
}

/**
* Retrieve content id if available
* */
var contentId = '';
if (response.data.contentId) {
contentId = response.data.contentId;
}

if (typeof window.dataLayer !== 'undefined') {
//********************************************************//
// //
// The dataLayer keys must be adapted to fit your need //
// //
//********************************************************//
window.dataLayer.push({
eventCategory: 'caast',
eventAction: eventName,
eventLabel: contentId,
event: 'basic',
});
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);

Filtering events​

Caast is emitting a lots of events (detailed list available here) so you may want to retrieve only a set of specific events. To retrieve only some events you could use the following code and adapt it to stick to your needs. Simply adapt the allowed_events variable to contain only the needed events

/**
* Send Caast filtered events into Google DataLayer
* */
var checkExist = setInterval(function () {
if (typeof window.caast !== 'undefined') {
if (typeof window.caastIsListening === 'undefined') {
window.caast
.on('all', function (response) {
/**
* Caast event name
* */
var eventName = response.type;

/**
* Caast allowed events - This a proposed list, check what events you want to allow
* */
var allowed_events = [
'onModalShow',
'onModalClose',
'onLivePlay',
'onLivePause',
'onProductClick',
'onProductDetailsClick',
'onProductDetailsShow',
'onProductOpen',
'onQuestionClick',
'onBasketAdd',
'onShare',
];

/**
* Retrieve product ref if available
* */
var productRef = '';
if (response.data.product_ref) {
productRef = response.data.product_ref;
}

/**
* Retrieve content id if available
* */
var contentId = '';
if (response.data.contentId) {
contentId = response.data.contentId;
}

if (typeof window.dataLayer !== 'undefined' && allowed_events.indexOf(eventName) > -1) {
//********************************************************//
// //
// The dataLayer keys must be adapted to fit your need //
// //
//********************************************************//
window.dataLayer.push({
eventCategory: 'caast',
eventAction: eventName,
eventLabel: contentId,
event: 'basic',
});
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);