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.
Those examples are designed to expose simple data collection scenario. Do not hesitate to dive into advanced tutorials in order to compute advanced data.
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.
- Google DataLayer
- Google Analytics (gtag.js)
- Piano Analytics
- Adobe Analytics
/**
* 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);
/**
* Send Caast events into Google gtag.js
* */
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.gtag !== 'undefined') {
//********************************************************//
// //
// The send keys must be adapted to fit your need //
// //
//********************************************************//
window.gtag('event', eventName, {
eventCategory: 'caast',
eventLabel: contentId,
});
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);
/**
* Send Caast events into Piano Analytics
* */
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.pianoAnalytics !== 'undefined' && typeof window.pa !== 'undefined') {
//********************************************************//
// //
// The send keys must be adapted to fit your need //
// //
//********************************************************//
pa.sendEvent('caast', {
eventaction: eventName,
eventcategory: contentId,
eventlabel: productRef,
});
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);
/**
* Send Caast events into Adobe Analytics
* */
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.s !== 'undefined' && typeof window.s.tl !== 'undefined') {
//********************************************************//
// //
// The send keys must be adapted to fit your need //
// //
//********************************************************//
var y = new Object();
y.eVar1 = eventName;
y.eVar2 = productRef;
y.eVar3 = contentId;
y.linkTrackVars = 'eVar1, eVar2, eVar3';
s.tl(true, 'o', 'Caast', y);
}
})
.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
- Google DataLayer
- Google Analytics (gtag.js)
- Piano Analytics
- Adobe Analytics
/**
* 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);
/**
* Send Caast filtered events into Google gtag.js
* */
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.gtag !== 'undefined' && allowed_events.indexOf(eventName) > -1) {
//********************************************************//
// //
// The send keys must be adapted to fit your need //
// //
//********************************************************//
window.gtag('event', eventName, {
eventCategory: 'caast',
eventLabel: contentId,
});
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);
/**
* Send Caast filtered events into Piano Analytics
* */
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.pianoAnalytics !== 'undefined' && typeof window.pa !== 'undefined' && allowed_events.indexOf(eventName) > -1) {
//********************************************************//
// //
// The send keys must be adapted to fit your need //
// //
//********************************************************//
pa.sendEvent('caast', {
eventaction: eventName,
eventcategory: contentId,
eventlabel: productRef,
});
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);
/**
* Send Caast filtered events into Adobe Analytics
* */
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.s !== 'undefined' && typeof window.s.tl !== 'undefined' && allowed_events.indexOf(eventName) > -1) {
//********************************************************//
// //
// The send keys must be adapted to fit your need //
// //
//********************************************************//
var y = new Object();
y.eVar1 = eventName;
y.eVar2 = productRef;
y.eVar3 = contentId;
y.linkTrackVars = 'eVar1, eVar2, eVar3';
s.tl(true, 'o', 'Caast', y);
}
})
.then(function () {
window.caastIsListening = true;
});
}
clearInterval(checkExist);
}
}, 100);