Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging latest release changes #557

Merged
merged 13 commits into from
Sep 27, 2024
17 changes: 6 additions & 11 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ function setPrebidConfig(){
url: CONSTANTS.CONFIG.CACHE_URL + CONSTANTS.CONFIG.CACHE_PATH,
ignoreBidderCacheKey: true
},
bidderSequence: "random",
bidderSequence: CONF.pwt.bidderOrderingEnabled === "1" ? "fixed" : "random",
disableAjaxTimeout: CONFIG.getDisableAjaxTimeout(),
enableSendAllBids: CONFIG.getSendAllBidsStatus(),
targetingControls: {
Expand Down Expand Up @@ -1076,15 +1076,6 @@ function setPrebidConfig(){

exports.setPrebidConfig = setPrebidConfig;

function realignPubmaticAdapters(){
if(CONF.adapters && CONF.adapters["pubmatic"]){
var pubmaticAdpater = {"pubmatic": CONF.adapters["pubmatic"]};
CONF.adapters = Object.assign(pubmaticAdpater, CONF.adapters);
}
}

exports.realignPubmaticAdapters = realignPubmaticAdapters;

function gets2sConfig(prebidConfig){
var bidderParams = {};
var s2sBidders = CONFIG.getServerEnabledAdaptars();
Expand Down Expand Up @@ -1331,6 +1322,11 @@ function getPbjsAdServerTargetingConfig(){
val: function(bidResponse){
return bidResponse.creativeId ? bidResponse.creativeId : '';
}
}, {
key: 'pwtpb',
val: function(bidResponse){
return bidResponse[CONSTANTS.PRICE_GRANULARITY_KEYS[owpbjs.readConfig('priceGranularity')]] || null;
}
}
];
}
Expand Down Expand Up @@ -1420,7 +1416,6 @@ function initPbjsConfig(){
return;
}
window[pbNameSpace].logging = util.isDebugLogEnabled();
refThis.realignPubmaticAdapters();
refThis.setPrebidConfig();
refThis.configureBidderAliasesIfAvailable();
refThis.enablePrebidPubMaticAnalyticIfRequired();
Expand Down
3 changes: 2 additions & 1 deletion src_new/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ exports.pwt = {
gppTimeout: "10000",
pbGlobalVarNamespace: "owpbjs",
owGlobalVarNamespace: "PWT",
localStorageAccess: "1" // Added new field for allow local storage feature
localStorageAccess: "1", // Added new field for allow local storage feature
bidderOrderingEnabled: "0"
};

// singleImpression is used to enable feature of sending single impression for multiple size ad slot earlier there were multiple impression for multiple sizes
Expand Down
27 changes: 26 additions & 1 deletion src_new/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,32 @@ exports.isReduceCodeSizeFeatureEnabled = function(){
// endRemoveIf(removeAlways)

exports.getPriceGranularity = function(){
return config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY] || null;
var priceGranularity = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY] || null;

if (priceGranularity === CONSTANTS.COMMON.PRICE_GRANULARITY_CUSTOM) {
var bucketsValue = refThis.getPriceGranularityBuckets();
if(bucketsValue !== null) {
return bucketsValue;
} else {
util.logWarning(CONSTANTS.MESSAGES.M36);
return null;
}
}
else {
return priceGranularity;
}
};

exports.getPriceGranularityBuckets = function () {
var pgBuckets = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY_BUCKETS] || null;
if(pgBuckets === null)
return null;

// API would be providing us with ranges as keyword, we need to raplace it by buckets before processing
var transformedBuckets = {};
delete Object.assign(transformedBuckets, pgBuckets, {['buckets']: pgBuckets['ranges'] })['ranges'];

return transformedBuckets;
};

exports.getGranularityMultiplier = function(){
Expand Down
15 changes: 14 additions & 1 deletion src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ exports.COMMON = {
"TEST_GROUP_DETAILS": "testConfigDetails",
"TEST_PWT": "test_pwt",
"PRICE_GRANULARITY" : "priceGranularity",
"PRICE_GRANULARITY_CUSTOM" : "custom",
"PRICE_GRANULARITY_BUCKETS" : "customPriceGranularityConfig",
"GRANULARITY_MULTIPLIER" : "granularityMultiplier",
"TEST_PARTNER": "test_adapters",
"REDUCE_CODE_SIZE": "reduceCodeSize",
Expand Down Expand Up @@ -167,7 +169,8 @@ exports.WRAPPER_TARGETING_KEYS = {
"CACHE_PATH": "pwtcpath",
"ACAT": "pwtacat",
"CRID": "pwtcrid",
"DSP": "pwtdsp"
"DSP": "pwtdsp",
"PRICE_BUCKET": "pwtpb"
};

exports.IGNORE_PREBID_KEYS = {
Expand Down Expand Up @@ -226,6 +229,7 @@ exports.MESSAGES = {
"M33": "AdUnitsArray response should be an array.",
"M34": "Invalid HTML Element selected for ad rendering.",
"M35": "Winning bid not found for Div Id :",
"M36": "Price Buckets should be set for custom price granularity",
IDENTITY: {
M1: "Unable to get User Id from OpenIdentity",
M2: "Setting UserIds to EB ",
Expand Down Expand Up @@ -364,3 +368,12 @@ exports.REGEX_BROWSERS = [/\b(?:crmo|crios)\/([\w\.]+)/i,/edg(?:e|ios|a)?\/([\w\
/(firefox)\/([\w\.]+)/i,/(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,/(links) \(([\w\.]+)/i];
exports.BROWSER_MAPPING = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,42,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90];

exports.PRICE_GRANULARITY_KEYS = {
auto: "pbAg",
dense: "pbDg",
low: "pbLg",
medium: "pbMg",
high:"pbHg",
custom: "pbCg"
};
2 changes: 1 addition & 1 deletion src_new/controllers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function findWinningBidAndGenerateTargeting(divId) {
util.forEachOnObject(keyValuePairs, function(key) {
// if winning bid is not pubmatic then remove buyId targeting key. Ref : UOE-5277
/* istanbul ignore else*/
if (util.isOwnProperty(ignoreTheseKeys, key) || util.isOwnProperty({"pwtpb":1}, key) || (winningBid && winningBid.adapterID !== "pubmatic" && util.isOwnProperty({"hb_buyid_pubmatic":1,"pwtbuyid_pubmatic":1}, key))) {
if (util.isOwnProperty(ignoreTheseKeys, key) || (winningBid && winningBid.adapterID !== "pubmatic" && util.isOwnProperty({"hb_buyid_pubmatic":1,"pwtbuyid_pubmatic":1}, key))) {
delete keyValuePairs[key];
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src_new/controllers/gpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function findWinningBidAndApplyTargeting(divID, parentArgs) { // TDD, i/o : done
delete keyValuePairs[key];
}
/* istanbul ignore else*/
else if (!util.isOwnProperty(ignoreTheseKeys, key) && !util.isOwnProperty({"pwtpb":1}, key)) {
else if (!util.isOwnProperty(ignoreTheseKeys, key)) {
googleDefinedSlot.setTargeting(key, value);
// adding key in wrapperTargetingKeys as every key added by OpenWrap should be removed before calling refresh on slot
refThis.defineWrapperTargetingKey(key);
Expand Down
50 changes: 36 additions & 14 deletions test/adapters/prebid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2127,20 +2127,6 @@ describe('ADAPTER: Prebid', function() {
expect(response).to.deep.equal(outputObj);
done();
});
})

describe('realignPubmaticAdapters', function() {
it('should be a functiion',function(done){
PREBID.realignPubmaticAdapters.should.be.a('function');
done();
});
it('should realignPubmaticAdapters', function(done) {
PREBID.realignPubmaticAdapters();
expect(CONF.adapters['pubmatic']).should.have.object;
expect(CONF.adapters['pubmatic']).to.be.an('object');
expect(CONF.adapters['pubmatic']).to.have.property('throttle');
done();
});
});

describe('getPbjsAdServerTargetingConfig', function() {
Expand Down Expand Up @@ -2261,4 +2247,40 @@ describe('ADAPTER: Prebid', function() {
done();
});
})

describe('dynamicBidderOrdering', function() {
let originalOwPbJs;
let mockSetConfig;
beforeEach(() => {
// Save the original owpbjs and setConfig function
originalOwPbJs = window['owpbjs'];
mockSetConfig = sinon.spy();
window['owpbjs'] = {
setConfig: mockSetConfig,
};
})

afterEach(() => {
// Restore the original owpbjs
window['owpbjs'] = originalOwPbJs;
CONF.pwt.bidderOrderingEnabled = '0';
});

it('should set bidderSequence to random when dynamic bidder ordering is disabled', function(done) {
PREBID.setPrebidConfig();
expect(mockSetConfig.calledOnce).to.be.true;
const configArg = mockSetConfig.getCall(0).args[0];
expect(configArg).to.have.property('bidderSequence', 'random');
done();
});

it('should set bidderSequence to fixed when dynamic bidder ordering is enabled', function(done) {
CONF.pwt.bidderOrderingEnabled = '1';
PREBID.setPrebidConfig();
expect(mockSetConfig.calledOnce).to.be.true;
const configArg = mockSetConfig.getCall(0).args[0];
expect(configArg).to.have.property('bidderSequence', 'fixed');
done();
});
})
});
50 changes: 49 additions & 1 deletion test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2183,11 +2183,13 @@ describe('Config', function() {
describe('#getPriceGranularity',function(){
beforeEach(function(done){
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY] = "high";
sinon.spy(UTIL, "logWarning");
done();
});

afterEach(function(done){
delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY] ;
delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY];
UTIL.logWarning.restore();
done();
})

Expand All @@ -2207,6 +2209,52 @@ describe('Config', function() {
expect(CONFIG.getPriceGranularity()).to.equal(null);
done();
});

it('should return PriceGranularity Buckets if price granularity is custom', function(done){
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY] = 'custom';
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY_BUCKETS] = {'ranges':'customBuckets'};
var expectedResult = {'buckets':'customBuckets'};
expect(CONFIG.getPriceGranularity()).to.deep.equal(expectedResult);
done();
});

it('should return null and log warning if Buckets are missing for custom price granularity', function(done){
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY] = 'custom';
delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY_BUCKETS]

expect(CONFIG.getPriceGranularity()).to.equal(null);
UTIL.logWarning.calledWith(CONSTANTS.MESSAGES.M36).should.be.true;
done();
});
});

describe('#getPriceGranularityBuckets',function(){
beforeEach(function(done){
CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY_BUCKETS] = {'ranges':'customBuckets'};
done();
});

afterEach(function(done){
delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY_BUCKETS];
done();
})

it('is a function', function(done) {
CONFIG.getPriceGranularityBuckets.should.be.a('function');
done();
});

it('should return the buckets by reading from config', function(done) {
var expectedResult = {'buckets':'customBuckets'};
CONFIG.getPriceGranularityBuckets().should.be.deep.equal(expectedResult);
done();
});

it('should return null if bucket is not present',function(done){
delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.PRICE_GRANULARITY_BUCKETS];
expect(CONFIG.getPriceGranularityBuckets()).to.equal(null);
done();
});
});

describe('#getGranularityMultiplier',function(){
Expand Down
2 changes: 0 additions & 2 deletions test/controllers/custom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,6 @@ describe("CONTROLLER: CUSTOM", function() {
sinon.spy(CUSTOM, "setWindowReference");
sinon.spy(CUSTOM, "defineWrapperTargetingKeys");
sinon.spy(CUSTOM, "initSafeFrameListener");
sinon.stub(PREBID, "realignPubmaticAdapters");
sinon.stub(UTIL, "getGeoInfo").returns({});
done();
});
Expand All @@ -909,7 +908,6 @@ describe("CONTROLLER: CUSTOM", function() {
CUSTOM.setWindowReference.restore();
CUSTOM.defineWrapperTargetingKeys.restore();
CUSTOM.initSafeFrameListener.restore();
PREBID.realignPubmaticAdapters.restore();
UTIL.getGeoInfo.restore();
done();
});
Expand Down
2 changes: 0 additions & 2 deletions test/controllers/gpt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2965,7 +2965,6 @@ describe("CONTROLLER: GPT", function() {
sinon.spy(GPT, "defineGPTVariables");
sinon.spy(GPT, "addHooksIfPossible");
sinon.spy(GPT, "initSafeFrameListener");
sinon.stub(PREBID, "realignPubmaticAdapters")
sinon.stub(UTIL, "getGeoInfo").returns({});
done();
});
Expand All @@ -2977,7 +2976,6 @@ describe("CONTROLLER: GPT", function() {
GPT.defineGPTVariables.restore();
GPT.addHooksIfPossible.restore();
GPT.initSafeFrameListener.restore();
PREBID.realignPubmaticAdapters.restore();
UTIL.getGeoInfo.restore();
done();
});
Expand Down