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

UOE-7256: PrebidServerBidAdapatar to support banner profiles #329

Open
wants to merge 33 commits into
base: nightly5.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5984209
Generate adUnit config for PBS
Feb 1, 2022
faa7660
Refactored code
Feb 2, 2022
1733749
Fixed code review comments
Feb 4, 2022
9476dc7
Added query params to endpoint
Feb 10, 2022
831991d
Fixed test case for endpoint secnario
Feb 14, 2022
4445231
Linting fixes
Feb 14, 2022
066a48a
Linting fixes
Feb 15, 2022
6506609
Removed query params changes
Feb 16, 2022
f14a45b
Linitng fixes
Feb 16, 2022
5be1a80
Fix for mi value and removed test param from auction request
Feb 19, 2022
11d9581
changed accountId from 1 to publisher id
Feb 22, 2022
d5e0362
Passing psltime to logger call in case of PrebidServerBidAdapter
Feb 22, 2022
31d8631
Passing psltime to logger call in case of PrebidServerBidAdapter
Feb 22, 2022
53285ab
Removed unwanted constant for account id field
Feb 24, 2022
2bda6bc
Passed secure config to buildrequest to get secured creative
Feb 24, 2022
9936844
Handled error scenario
Feb 24, 2022
6f1c8ee
Fix to calculate psl for scenarios like bids and zerobids
Feb 25, 2022
5bdf76e
Fix for psl scenarios
Feb 26, 2022
fc3bfcb
Fixed regex mapping issue
Feb 28, 2022
b7f21d2
Fix for kgpv key
Mar 2, 2022
da5aac3
Fixed logger not fired issue
Mar 2, 2022
a845be4
Linting fixes
Mar 2, 2022
3920869
Added conditional check for psl when there is no server side bidder
Mar 2, 2022
68489dc
Passing macros to s2s config
Mar 3, 2022
a1a0f79
Fix for logger not showing PubMatic details for zero bid
Mar 7, 2022
60937f3
Reverted code for zero bid scenario
Mar 7, 2022
6de9055
Fix for zero bid scenario
Mar 8, 2022
af58129
Fix for psl when no adslot is enabled and passing correct key to dfp
Mar 15, 2022
728c7f4
Removed code for pwtbuyid key
Mar 15, 2022
21cd2a7
Fix for zero bid and no bid for PubMatic and alias
Mar 15, 2022
1b6ee95
Fix for pubmatic slot not mapped scenario
Mar 23, 2022
73053c4
Rebased with nightly5.x
Mar 24, 2022
1baf938
Fix for wiid is not passing to pubmatic when adg/pulsepoint/ix partne…
Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Generate adUnit config for PBS
Kapil Tuptewar authored and Kapil Tuptewar committed Feb 1, 2022
commit 5984209ff189345ebb6767944dd13b964352b300
90 changes: 79 additions & 11 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
@@ -362,7 +362,9 @@ function generatedKeyCallbackForPbAnalytics(adapterID, adUnits, adapterConfig, i
var mediaTypeConfig;
var partnerConfig;

if(CONFIG.isServerSideAdapter(adapterID)){
//If we are using PubMaticServerBidAdapatar then serverSideEabled: do not add config into adUnits.
//If we are using PrebidServerBidAdapatar then we need to add config into adUnits.
if(CONFIG.isServerSideAdapter(adapterID) && CONF.pwt.usePBSAdapatar != "1"){
util.log("Not calling adapter: "+ adapterID + ", for " + generatedKey +", as it is serverSideEnabled.");
return;
}
@@ -476,8 +478,9 @@ function generatedKeyCallback(adapterID, adUnits, adapterConfig, impressionID, g
}
}

//serverSideEabled: do not add config into adUnits
if(CONFIG.isServerSideAdapter(adapterID)){
//If we are using PubMaticServerBidAdapatar then serverSideEabled: do not add config into adUnits.
//If we are using PrebidServerBidAdapatar then we need to add config into adUnits.
if(CONFIG.isServerSideAdapter(adapterID) && CONF.pwt.usePBSAdapatar != "1"){
util.log("Not calling adapter: "+ adapterID + ", for " + generatedKey +", as it is serverSideEnabled.");
return;
}
@@ -613,6 +616,15 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
if((adapterID != "pubmatic2" && adapterName != "pubmatic2") && window.PWT.udpv){
slotParams["verId"] = CONFIG.getProfileDisplayVersionID();
}

// If we will be using PrebidServerBidAdaptar add wrapper object with profile and version
if(CONF.pwt.usePBSAdapatar == '1' && CONFIG.isServerSideAdapter(adapterName)) {
slotParams["wrapper"] = {
profile: parseInt(CONF.pwt.pid),
version: parseInt(CONF.pwt.pdvid)
}
}

// We are removing mimes because it merges with the existing adUnit mimes
// if(slotParams["video"] && slotParams["video"]["mimes"]){
// delete slotParams["video"]["mimes"];
@@ -859,15 +871,29 @@ function generateAdUnitsArray(activeSlots, impressionID){
/* istanbul ignore else */
if(adapterID !== refThis.parentAdapterID){

//serverSideEabled: we do not want to throttle them at client-side
// If we will be using PrebidServerBidAdapatar then we need to check throttling for
// serverEnabled partners at client-side
/* istanbul ignore if */
if(CONFIG.isServerSideAdapter(adapterID) || refThis.throttleAdapter(randomNumberBelow100, adapterID) == false){
util.forEachOnObject(activeSlots, function(j, slot){
bidManager.setCallInitTime(slot.getDivID(), adapterID);
});
refThis.generatePbConf(adapterID, adapterConfig, activeSlots, adUnits, impressionID);
}else{
util.log(adapterID+CONSTANTS.MESSAGES.M2);
if(CONF.pwt.usePBSAdapatar == "1" && CONFIG.isServerSideAdapter(adapterID)) {
if(refThis.throttleAdapter(randomNumberBelow100, adapterID) == false) {
util.forEachOnObject(activeSlots, function(j, slot){
bidManager.setCallInitTime(slot.getDivID(), adapterID);
});
refThis.generatePbConf(adapterID, adapterConfig, activeSlots, adUnits, impressionID);
} else {
util.log(adapterID+CONSTANTS.MESSAGES.M2);
}
} else {
// serverSideEabled: we do not want to throttle them at client-side
/* istanbul ignore if */
if(CONFIG.isServerSideAdapter(adapterID) || refThis.throttleAdapter(randomNumberBelow100, adapterID) == false){
util.forEachOnObject(activeSlots, function(j, slot){
bidManager.setCallInitTime(slot.getDivID(), adapterID);
});
refThis.generatePbConf(adapterID, adapterConfig, activeSlots, adUnits, impressionID);
}else{
util.log(adapterID+CONSTANTS.MESSAGES.M2);
}
}
}
});
@@ -947,6 +973,10 @@ function setPrebidConfig(){
refThis.assignCurrencyConfigIfRequired(prebidConfig);
refThis.assignSchainConfigIfRequired(prebidConfig);
refThis.assignSingleRequestConfigForBidders(prebidConfig);
// if usePBSAdapatar is 1 then add s2sConfig
if(CONF.pwt.usePBSAdapatar == "1") {
refThis.gets2sConfig(prebidConfig);
}
// Adding a hook for publishers to modify the Prebid Config we have generated
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
//todo: stop supporting this hook let pubs use pbjs.requestBids hook
@@ -959,6 +989,44 @@ function setPrebidConfig(){

exports.setPrebidConfig = setPrebidConfig;

function gets2sConfig(prebidConfig){
var s2sBidders = CONFIG.getServerEnabledAdaptars();
var defaultAliases = {
adg: "adgeneration",
districtm: "appnexus",
districtmDMX: "dmx",
pubmatic2: "pubmatic"
};
var allAliases = Object.assign({}, defaultAliases, CONF.alias);
var pubmaticAndAliases = s2sBidders.filter(function(adapter) {
if(CONF.alias && CONF.alias[adapter] && CONF.alias[adapter].includes('pubmatic') || adapter.includes('pubmatic')) {
return adapter;
}
})
var bidderParams = {};
pubmaticAndAliases.forEach(function(bidder) {
bidderParams[bidder] = {};
})
prebidConfig["s2sConfig"] = {
accountId: CONSTANTS.PBSPARAMS.accountId,
adapter: CONSTANTS.PBSPARAMS.adapter,
enabled: true,
bidders: s2sBidders,
endpoint: CONSTANTS.PBSPARAMS.endpoint,
syncEndpoint: CONSTANTS.PBSPARAMS.syncEndpoint,
timeout: CONFIG.getTimeoutForPBSRequest(),
extPrebid: {
aliases: allAliases,
bidderparams: bidderParams,
targeting: {
pricegranularity: CONFIG.getPriceGranularity()
}
}
}
}

exports.gets2sConfig = gets2sConfig;

function getFloorsConfiguration(prebidConfig){
if(CONFIG.isFloorPriceModuleEnabled() == true){
prebidConfig["floors"]={
23 changes: 22 additions & 1 deletion src_new/config.js
Original file line number Diff line number Diff line change
@@ -394,4 +394,25 @@ exports.getAdapterNameForAlias = function(aliasName){

exports.isSSOEnabled = function() {
return parseInt(config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.SSO_ENABLED]) === 1;
}
}

exports.getServerEnabledAdaptars = function() {
var s2sBidders = Object.keys(config.adapters).filter(function(adapter){
if(config.adapters[adapter]['serverSideEnabled'] == "1") {
return adapter;
}
});
return s2sBidders;
}

exports.getTimeoutForPBSRequest = function() {
var ssTimeOut = parseInt(config.pwt.ssTimeout);
var maxTimeout = CONSTANTS.TIMEOUT_CONFIG.MaxTimeout;
var minTimeout = CONSTANTS.TIMEOUT_CONFIG.MinTimeout;
if(ssTimeOut >= minTimeout && ssTimeOut <= maxTimeout) {
return ssTimeOut;
} else if(ssTimeOut >= minTimeout) {
return maxTimeout;
}
return minTimeout;
}
12 changes: 12 additions & 0 deletions src_new/constants.js
Original file line number Diff line number Diff line change
@@ -285,3 +285,15 @@ exports.BID_STATUS = {
}
// Add list of PubMatic aliases here.
exports.PUBMATIC_ALIASES = ["pubmatic2"];

exports.PBSPARAMS = {
accountId: "1",
adapter: "prebidServer",
endpoint: "https://ow.pubmatic.com/pbs/openrtb2/auction",
syncEndpoint: "https://ow.pubmatic.com/cookie_sync/?sec=1"
}

exports.TIMEOUT_CONFIG = {
MaxTimeout: 500,
MinTimeout: 200
}
60 changes: 60 additions & 0 deletions test/adapters/prebid.spec.js
Original file line number Diff line number Diff line change
@@ -1501,6 +1501,66 @@ describe('ADAPTER: Prebid', function() {
});
})

// Test cases to generate s2sConfig
describe('generates2sConfig',function(){
var prebidConfig = {};
var expectedResult = {};
var defaultAliases = {
adg: "adgeneration",
districtm: "appnexus",
districtmDMX: "dmx",
pubmatic2: "pubmatic"
};
var allAliases = Object.assign({}, defaultAliases, CONF.alias);

beforeEach(function(done){
var s2sBidders = CONFIG.getServerEnabledAdaptars();
var pubmaticAndAliases = s2sBidders.filter(function(adapter) {
if(CONF.alias && CONF.alias[adapter] && CONF.alias[adapter].includes('pubmatic') || adapter.includes('pubmatic')) {
return adapter;
}
})
var bidderParams = {};
pubmaticAndAliases.forEach(function(bidder) {
bidderParams[bidder] = {};
})

expectedResult = {
accountId: "1",
adapter: "prebidServer",
enabled: true,
bidders: s2sBidders,
endpoint: "https://ow.pubmatic.com/pbs/openrtb2/auction",
syncEndpoint: "https://ow.pubmatic.com/cookie_sync/?sec=1",
timeout: CONFIG.getTimeoutForPBSRequest(),
extPrebid: {
aliases: allAliases,
bidderparams: bidderParams,
targeting: {
pricegranularity: CONFIG.getPriceGranularity()
}
}
};
done();
});

afterEach(function(done){
prebidConfig = {};
done();
});

it('should be a functiion',function(done){
PREBID.gets2sConfig.should.be.a('function');
done();
});

it('should set s2sConfig properties',function(done){
PREBID.gets2sConfig(prebidConfig);
expect(prebidConfig.s2sConfig).to.be.deep.equal(expectedResult);
done();
});
})

describe('#addOnBidRequestHandler',function(){
beforeEach(function(done) {
sinon.stub(UTIL, 'isFunction');