When a jExperience AB Test or a personalization is being displayed, jExperience dispatches javascript events. This module ensures that these events are stored in the data layer (javascript objets), so they can be read by tag managers and sent to external analytiocs solutions if needed.
Below is the code to add to your tag manager in order to read the data about the jexperience variants that were displayed:
<script>
if(!window.digitalData.dispatchedEvents ) {
// Events not yet dispatched - Adding listener from GTM
document.addEventListener('displayWemVariant', function (event) {
logEvent(event.detail);
}, true);
} else if (window.digitalData && window.digitalData.dispatchedEvents) {
// Events already dispatched and available in window.digitalData.dispatchedEvents
for (var i = 0; i < window.digitalData.dispatchedEvents.length; i++) {
logEvent(window.digitalData.dispatchedEvents[i].detail);
}
}
function logEvent (eventDetail) {
console.log("wrapper.id:" + eventDetail.wrapper.id);
console.log("wrapper.name:" + eventDetail.wrapper.name);
console.log("wrapper.path:" + eventDetail.wrapper.path);
console.log("wrapper.displayableName:" + eventDetail.wrapper.displayableName.substring(0,64));
console.log("variant.id:" + eventDetail.id);
console.log("variant.name:" + eventDetail.name);
console.log("variant.path:" + eventDetail.path);
console.log("variant.displayableName:" + eventDetail.displayableName.substring(0,64));
console.log("variant.variantType:" + eventDetail.variantType);
console.log("type:" + eventDetail.type);
if (typeof ga !== 'undefined') {
var label = eventDetail.name;
// Sending an event to google analytics
ga('send', 'event', eventDetail.type, 'Display', label, 5, true);
}
}
</script>
Note: This module is not officially supported by the Jahia product team.