Tracking Banner Impressions in Adobe Analytics via Ensighten

Previously, a client asked me to set up banner impression tracking within Ensighten for their Adobe Analytics implementation.  This blog posting will provide the code I used to get this to happen (please note that the get attribute of class and data-id will need to be changed to whatever you have in place).

Below is the code that you can use to track banner impressions within Ensighten.  You will need to set this up as a custom JS script outside of the appMeasurement library:

<pre class=”prettyprint”>

window.isScrolledIntoView = function(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();

var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();

return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};

window.isDescendant = function(parent, child) {
var node = child.parentNode;
while (node != null) {
if (node == parent) {
return true;
}
node = node.parentNode;
}
return false;
};
window.list1_unload = “”;

//wait for hero banner to load and if it does, grab it for list1_unload
Bootstrapper.propertyWatcher.create(function() {
return $(“.hero”).length;
}).change = function(oldValue, newValue) {
if(newValue>0)
{
window.list1_unload = $(“.hero”)[0].getAttribute(‘class’)+”:”+$(“.hero”)[0].getAttribute(‘data-id’);
}
};

/*
if($(“.hero”).length>0)
window.list1_unload = $(“.hero”)[0].getAttribute(‘class’)+”:”+$(“.hero”)[0].getAttribute(‘data-id’);
console.log(window.list1_unload);
*/

Bootstrapper.propertyWatcher.create(function() {
if(navigator.userAgent.match(/firefox/i))
return document.documentElement.scrollTop;
else
return document.body.scrollTop;
}).change = function(oldValue, newValue) {
if (oldValue !== newValue) {
elemArr = $(“#module-container section a”);
for (var ind=0; ind< elemArr.length; ind++) {
var elem = elemArr[ind];
if (window.isScrolledIntoView(elem)) {
var par = false;
var parentArr = $(“#module-container section”);
for (var a=0; a< parentArr.length; a++) {
if (window.isDescendant(parentArr[a], elem)) {
par = parentArr[a];
break;
}
}
if (par !== false) {
var str = par.getAttribute(‘class’) + “:” + par.getAttribute(“data-id”);
if(window.list1_unload.match(str)===null){
if(!!window.list1_unload && window.list1_unload.length>0)
window.list1_unload += “|”+str;
else
window.list1_unload = str;
}
}
}
}
}
};

window.onbeforeunload = function(){
s.linkTrackVars = “eVar90,list3,events”;
s.linkTrackEvents = “event100”;
s.list1 = window.list1_unload;
s.eVar90 = window.s.pageName;
s.events = (typeof s.events !== “undefined” && s.events.indexOf(“event100″)===-1)?(s.events+”,event100″):”event100″;
s.tl(this,”o”,”banner impressions”);
};

</pre>

That’s it.  With this you can now successfully track banner impressions and banner names within Ensighten to pass to Adobe Analytics.

Posted in Adobe Analytics, Ensighten, Tag Management Solution