Skip to content

Instantly share code, notes, and snippets.

@validkeys
Created September 23, 2014 17:37
Show Gist options
  • Select an option

  • Save validkeys/b72cd62c6953c251055e to your computer and use it in GitHub Desktop.

Select an option

Save validkeys/b72cd62c6953c251055e to your computer and use it in GitHub Desktop.
<script type="text/javascript">
// *******************************************************
// *********** BlueKAI Pixel Tracker **********
// *******************************************************
document.addEventListener( "DOMContentLoaded", function(){
if(typeof angular !== 'undefined'){
var _BK_els = [], _BK_els_cache = [];
_BK_els = [
{
type: "iframe",
attributes: {
"data-p-id": 1,
name: "__bkframe",
height: 0,
width: 0,
frameborder: 0,
src: "javascript:void(0)"
}
},
{
type: "script",
attributes: {
id: "p-remove-2",
type: "text/javascript",
src: "http://tags.bkrtx.com/js/bk-coretag.js"
}
},
{
type: 'script',
attributes: {
id: "p-remove-3",
type: "text/javascript",
src: "http://cdn.static.zdbb.net/js/page-segments.js"
}
}
];
function reloadBlueKai() {
// remove the existings scripts and iFrames (seems to necessary)
// in the context of an SPA
for (var i = 0; i < _BK_els_cache.length; i++) {
_BK_els_cache[i].parentNode.removeChild(_BK_els_cache[i]);
};
// reset the dom cache
_BK_els_cache = [];
for (var i = _BK_els.length - 1; i >= 0; i--) {
var item = _BK_els[i];
var e = document.createElement(item.type);
for (var key in item.attributes) {
e.setAttribute(key, item.attributes[key]);
};
e.setAttribute("data-test",new Date());
document.body.appendChild(e);
_BK_els_cache.push(e);
};
}
function blueKaiTrack(data) {
reloadBlueKai();
if(data.model.constructor.name == "Asset") {
// article view
} else {
// section view
}
}
angular.module('pressly.analytics').config(function(analyticsProvider){
analyticsProvider.registerTracker(function($log){
return {
trackPage: blueKaiTrack,
trackEvent: blueKaiTrack
};
});
});
} else {
console.warn("Angular not defined for head html tracker");
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment