roshanoracle
4/9/2018 - 3:48 PM

BlueKai CoreTag : with built in campaign ID grabber

Fire this to pull campaign IDs per user from the JSON return tag

<!-- Begin BlueKai Tag -->
<script type='text/javascript'>
window._bk_adv = window._bk_adv || {};
window._bk_adv.functions = window._bk_adv.functions || {};
window._bk_adv.data = window._bk_adv.data || {};

// Config
window._bk_adv.data.data_collection_container_id = 'DATACOLLECTIONID'; // Replace with container ID for data collection
window._bk_adv.data.json_return_container_id = 'JSONRETURNID'; // Replace with container ID for JSON Return Tag
 
// Data to fire
window._bk_adv.functions.bk_async_adv = function() {
  
  // ALLOW MULTIPLE CALLS/SINGLE PAGE APPS
  bk_allow_multiple_calls = true;
  bk_use_multiple_iframes = true;
 
  // Grab Campaign IDs
  bk_addPageCtx('bk_campaign_ids',window._bk_adv.functions.campaign_id_grabber());
   
  
  // Send Data to BlueKai
  BKTAG.doTag(window._bk_adv.data.data_collection_container_id, 4);
  
};
   
// FUNCTION : Coretag Loaded
window.bk_async = function(){
 
  if(window._bk_adv.data.jsonretfire){
 
    window._bk_adv.data.coretagfire = true;
    window._bk_adv.functions.bk_async_adv(); // Fire Data
 
  }
 
}
 
// FUNCTION : JSON Return Loaded
window._bk_adv.functions.bk_json_ret = function(){
 
  window._bk_adv.data.jsonretfire = true;
  if(!window._bk_adv.data.coretagfire){
 
    window._bk_adv.functions.bk_async_adv(); // Fire Data
 
  }
 
};
 
// Grab Campaign IDs
window._bk_adv.functions.campaign_id_grabber = function(){
 
  var campaign_ids = [];
  if(window.bk_results && bk_results.campaigns.length !== 0){
    for (var i = 0; i < bk_results.campaigns.length; i++) {
      if(bk_results.campaigns[i].campaign){
        campaign_ids.push(bk_results.campaigns[i].campaign)
      };
    }
  campaign_result = "," + campaign_ids.join(',') + ",";
  return campaign_result;
  }
 
};
 
// JSON Return
(function() {
  var scripts = document.getElementsByTagName('script')[0];
  var bk_json_ret = document.createElement('script'); 
  bk_json_ret.onload = function(){
 
    // Function Code
    window._bk_adv.functions.bk_json_ret();
 
  }
  bk_json_ret.src = '//tags.bluekai.com/site/'+ window._bk_adv.data.json_return_container_id + '?ret=js&limit=1';
  scripts.parentNode.insertBefore(bk_json_ret, scripts);
}());
 
// Coretag.js
(function() {
  var scripts = document.getElementsByTagName('script')[0];
  var s = document.createElement('script');
  s.async = true;
  s.src = '//tags.bkrtx.com/js/bk-coretag.js';
  scripts.parentNode.insertBefore(s, scripts);
}());
</script>
<!-- End BlueKai Tag -->