roshanoracle
9/12/2019 - 12:02 PM

Orange FR - Maxymiser - Custom DMP Integration Tag

var config = {
    "timeout": 7000
};

// OPTIONAL : DMP JSON Return Implementation : START

var bkContainerID = 82838;

(function() {
  var scripts = document.getElementsByTagName('script')[0];
  var s = document.createElement('script');
  s.async = true;
  s.src = "https://tags.bluekai.com/site/" + bkContainerID + "?ret=js&limit=0"
  scripts.parentNode.insertBefore(s, scripts);
}());
// OPTIONAL : DMP JSON Return Implementation : END

campaign.scope.qualificationRules = campaign.scope.qualificationRules || [];
campaign.scope.qualificationRules.push(integration);
function integration() {
    var failed = false;
    setTimeout(function() {
        failed = true;
    }, config.timeout);
    var deferred = new Deferred();
    when(function() {
        return window.bk_results && window.bk_results.campaigns && window.bk_results.campaigns.push;
    }, function() {
        return failed;
    }).then(function() {
        var campaigns = window.bk_results.campaigns;
        var priorities = {};
        for (var i = campaigns.length; i--;) {
            var campaign = campaigns[i];
            var name = campaign.AttributeName;
            var value = campaign.AttributeValue;
            var priority = isNaN(+campaign.Priority) ? 1 : +campaign.Priority;
            if (!name) { continue; }
            if (!priorities[name] || priority < priorities[name]) {
                visitor.storeAttr(name, value);
                priorities[name] = priority;
            }
        }
        deferred.resolve();
    }, function(){
        deferred.resolve();
    });
    return deferred.promise();
}