Skip to content

Commit

Permalink
adds support for pbjs.bidderSetting "suppressEmptyKeys". (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
snapwich authored and Nate Guisinger committed Aug 23, 2016
1 parent bddc360 commit a7d4f49
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,25 @@ function setKeys(keyValues, bidderSettings, custBidObj) {

if (utils.isFn(value)) {
try {
keyValues[key] = value(custBidObj);
value = value(custBidObj);
} catch (e) {
utils.logError('bidmanager', 'ERROR', e);
}
}

if (
typeof bidderSettings.suppressEmptyKeys !== "undefined" && bidderSettings.suppressEmptyKeys === true &&
(
utils.isEmptyStr(value) ||
value === null ||
value === undefined
)
) {
utils.logInfo("suppressing empty key '" + key + "' from adserver targeting");
} else {
keyValues[key] = value;
}

});

return keyValues;
Expand Down
9 changes: 9 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ exports.isEmpty = function (object) {
return true;
};

/**
* Return if string is empty, null, or undefined
* @param str string to test
* @returns {boolean} if string is empty
*/
exports.isEmptyStr = function(str) {
return this.isStr(str) && (!str || 0 === str.length);
};

/**
* Iterate object with the function
* falls back to es5 `forEach`
Expand Down
26 changes: 26 additions & 0 deletions test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,32 @@ describe('bidmanager.js', function () {

});

it('suppressEmptyKeys=true' , function() {
$$PREBID_GLOBAL$$.bidderSettings =
{
standard: {
suppressEmptyKeys: true,
adserverTargeting: [
{
key: "aKeyWithAValue",
val: 42
},
{
key: "aKeyWithAnEmptyValue",
val: ""
}
]
}
};

var expected = {
"aKeyWithAValue": 42
};

var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid);
assert.deepEqual(response, expected);
})

});

describe('adjustBids', () => {
Expand Down

0 comments on commit a7d4f49

Please sign in to comment.