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
Show file tree
Hide file tree
Changes from all commits
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
117 changes: 105 additions & 12 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var refThis = this;
var onEventAdded = false;
var isPrebidPubMaticAnalyticsEnabled = CONFIG.isPrebidPubMaticAnalyticsEnabled();
var isSingleImpressionSettingEnabled = CONFIG.isSingleImpressionSettingEnabled();
var defaultAliases = CONSTANTS.DEFAULT_ALIASES;

/* start-test-block */
exports.isSingleImpressionSettingEnabled = isSingleImpressionSettingEnabled;
Expand Down Expand Up @@ -365,7 +366,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) && CONFIG.usePBSAdapter() != true){
util.log("Not calling adapter: "+ adapterID + ", for " + generatedKey +", as it is serverSideEnabled.");
return;
}
Expand Down Expand Up @@ -479,8 +482,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) && CONFIG.usePBSAdapter() != true){
util.log("Not calling adapter: "+ adapterID + ", for " + generatedKey +", as it is serverSideEnabled.");
return;
}
Expand Down Expand Up @@ -542,14 +546,15 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
var slotParams = {};
var mediaTypeConfig = adUnits[code].mediaTypes;
var sizes = adUnits[code].sizes;
var isWiidRequired = false;
if(mediaTypeConfig && util.isOwnProperty(mediaTypeConfig,"video") && adapterID != "telaria"){
slotParams["video"]= mediaTypeConfig.video;
}
util.forEachOnObject(keyConfig, function(key, value){
/* istanbul ignore next */
slotParams[key] = value;
});

if(isPrebidPubMaticAnalyticsEnabled){
slotParams["kgpv"] = generatedKey; // TODO : Update this in case of video, change the size to 0x0
slotParams["regexPattern"] = regexPattern;
Expand Down Expand Up @@ -580,6 +585,12 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
slotParams["video"]= mediaTypeConfig.video;
}
}
// for pubmaticServer partner we used to pass wiid when isPrebidPubMaticAnalyticsEnabled is false but now we do not
// get pubmaticServer partner when usePBSAdapter flag is true so we will be adding wiid conditionally.
if(isPrebidPubMaticAnalyticsEnabled === false && CONFIG.usePBSAdapter()){
slotParams["wiid"] = impressionID;
isWiidRequired = true;
}

var adapterName = CONFIG.getAdapterNameForAlias(adapterID) || adapterID;

Expand Down Expand Up @@ -616,6 +627,19 @@ 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(CONFIG.usePBSAdapter() == true && CONFIG.isServerSideAdapter(adapterID)) {
slotParams["wrapper"] = {
profile: parseInt(CONF.pwt.pid),
version: parseInt(CONF.pwt.pdvid)
};
// If mapping is regex then we should pass hashedKey to adSlot params earlier it was handled on s2s side.
if(slotParams["hashedKey"]) {
slotParams["adSlot"] = slotParams["hashedKey"];
}
}

// We are removing mimes because it merges with the existing adUnit mimes
// if(slotParams["video"] && slotParams["video"]["mimes"]){
// delete slotParams["video"]["mimes"];
Expand All @@ -630,6 +654,9 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
slotParams[key] = value;
});
slotParams["cf"] = size[0] + "x" + size[1];
if(isWiidRequired) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected indentation of 3 tabs but found 4.

Suggested change
if(isWiidRequired) {
if(isWiidRequired) {

slotParams["wiid"] = impressionID;
}
adUnits[ code ].bids.push({ bidder: adapterID, params: slotParams });
});
break;
Expand All @@ -643,6 +670,9 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
});
slotParams["width"] = size[0];
slotParams["height"] = size[1];
if(isWiidRequired) {
slotParams["wiid"] = impressionID;
}
if(!(refThis.isSingleImpressionSettingEnabled && isAdUnitsCodeContainBidder(adUnits, code, adapterID))){
adUnits[ code ].bids.push({ bidder: adapterID, params: slotParams });
}
Expand All @@ -657,6 +687,9 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
slotParams[key] = value;
});
slotParams["adSize"] = size[0] + "x" + size[1];
if(isWiidRequired) {
slotParams["wiid"] = impressionID;
}
if(!(refThis.isSingleImpressionSettingEnabled && isAdUnitsCodeContainBidder(adUnits, code, adapterID))){
adUnits[ code ].bids.push({ bidder: adapterID, params: slotParams });
}
Expand All @@ -681,6 +714,9 @@ function pushAdapterParamsInAdunits(adapterID, generatedKey, impressionID, keyCo
sltParams["id"] = keyConfig["id"];
}
sltParams["size"] = size;
if(isWiidRequired) {
sltParams["wiid"] = impressionID;
}
adUnits [code].bids.push({bidder: adapterID, params: sltParams});
});
break;
Expand Down Expand Up @@ -862,15 +898,23 @@ 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(CONFIG.usePBSAdapter() == true&& CONFIG.isServerSideAdapter(adapterID)) {
if(refThis.throttleAdapter(randomNumberBelow100, adapterID) == false) {
refThis.generateConfig(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){
refThis.generateConfig(adapterID, adapterConfig, activeSlots, adUnits, impressionID);
}else{
util.log(adapterID+CONSTANTS.MESSAGES.M2);
}
}
}
});
Expand All @@ -889,6 +933,14 @@ function generateAdUnitsArray(activeSlots, impressionID){

exports.generateAdUnitsArray = generateAdUnitsArray;

function generateConfig(adapterID, adapterConfig, activeSlots, adUnits, impressionID) {
util.forEachOnObject(activeSlots, function(j, slot){
bidManager.setCallInitTime(slot.getDivID(), adapterID);
});
refThis.generatePbConf(adapterID, adapterConfig, activeSlots, adUnits, impressionID);
}
exports.generateConfig = generateConfig;

// removeIf(removeLegacyAnalyticsRelatedCode)
function addOnBidResponseHandler(){
if(util.isFunction(window[pbNameSpace].onEvent)){
Expand Down Expand Up @@ -950,6 +1002,10 @@ function setPrebidConfig(){
refThis.assignCurrencyConfigIfRequired(prebidConfig);
refThis.assignSchainConfigIfRequired(prebidConfig);
refThis.assignSingleRequestConfigForBidders(prebidConfig);
// if usePBSAdapter is 1 then add s2sConfig
if(CONFIG.usePBSAdapter()) {
refThis.gets2sConfig(prebidConfig);
}
// Check for yahoossp bidder and add property {mode: 'all'} to setConfig
refThis.checkForYahooSSPBidder(prebidConfig);
// Adding a hook for publishers to modify the Prebid Config we have generated
Expand All @@ -964,6 +1020,43 @@ function setPrebidConfig(){

exports.setPrebidConfig = setPrebidConfig;

function gets2sConfig(prebidConfig){
var bidderParams = {};
var s2sBidders = CONFIG.getServerEnabledAdaptars();
for(var key in CONF.alias) {
defaultAliases[key] = CONF.alias[key];
}
var pubmaticAndAliases = CONFIG.getPubMaticAndAlias(s2sBidders);
if(pubmaticAndAliases.length) {
pubmaticAndAliases.forEach(function(bidder) {
bidderParams[bidder] = {};
})
}

prebidConfig["s2sConfig"] = {
accountId: CONFIG.getPublisherId(),
adapter: CONSTANTS.PBSPARAMS.adapter,
enabled: true,
bidders: s2sBidders,
endpoint: CONSTANTS.PBSPARAMS.endpoint,
syncEndpoint: CONSTANTS.PBSPARAMS.syncEndpoint,
timeout: CONFIG.getTimeoutForPBSRequest(),
secure: 1,// request needs secure assets pass 1
extPrebid: {
aliases: defaultAliases,
bidderparams: bidderParams,
targeting: {
pricegranularity: CONFIG.getPriceGranularity()
},
isPrebidPubMaticAnalyticsEnabled: CONFIG.isPrebidPubMaticAnalyticsEnabled(),
isUsePrebidKeysEnabled: CONFIG.isUsePrebidKeysEnabled(),
macros: CONFIG.createMacros()
}
}
}

exports.gets2sConfig = gets2sConfig;

function getFloorsConfiguration(prebidConfig){
if(CONFIG.isFloorPriceModuleEnabled() == true){
prebidConfig["floors"]={
Expand Down
5 changes: 4 additions & 1 deletion src_new/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ Bid.prototype.setMi = function(mi){
// endRemoveIf(removeLegacyAnalyticsRelatedCode)

// removeIf(removeLegacyAnalyticsRelatedCode)
Bid.prototype.getMi = function(){
Bid.prototype.getMi = function(partnerName){
if(UTIL.isUndefined(this.mi)) {
this.mi = window.matchedimpressions && window.matchedimpressions[partnerName];
}
return this.mi;
};
// endRemoveIf(removeLegacyAnalyticsRelatedCode)
Expand Down
29 changes: 27 additions & 2 deletions src_new/bidManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,12 @@ function getAdDomain(bidResponse) {

// removeIf(removeLegacyAnalyticsRelatedCode)
function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o : done
var usePBSAdapter = CONFIG.usePBSAdapter();
var startTime = bmEntry.getCreationTime() || 0;
var pslTime = undefined;
var pslTime = (usePBSAdapter && window.pbsLatency) ? 0 : undefined;
var impressionID = bmEntry.getImpressionID();
var adUnitInfo = refThis.getAdUnitInfo(slotID);
var latencyValue = {};
const isAnalytics = true; // this flag is required to get grossCpm and netCpm in dollars instead of adserver currency
/* istanbul ignore else */
if (bmEntry.getAnalyticEnabledStatus() && !bmEntry.getExpiredStatus()) {
Expand All @@ -545,6 +547,24 @@ function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o
}

util.forEachOnObject(adapterEntry.bids, function(bidID, theBid) {
if(usePBSAdapter) {
// In PrebidServerBidAdapater we are capturing start and end time of request
// fetching these values here to calculate psl time for logger call
latencyValue = window.pbsLatency && window.pbsLatency[impressionID];
if(latencyValue && latencyValue['endTime'] && latencyValue['startTime']) {
pslTime = latencyValue['endTime'] - latencyValue['startTime'];
}
// When we use PrebidServerBidAdapter we do not get seatbid for zero bid / no bid partners
// as we need to log PubMatic partner in logger will be changing db = 0.
if((adapterID === "pubmatic" || adapterID === "pubmatic2") && (util.isOwnProperty(window.partnersWithoutErrorAndBids, impressionID) && window.partnersWithoutErrorAndBids[impressionID].includes(adapterID))) {
theBid.defaultBid = 0;
} else if(util.isOwnProperty(window.partnersWithoutErrorAndBids, impressionID) &&
window.partnersWithoutErrorAndBids[impressionID].includes(adapterID) &&
CONFIG.getAdapterNameForAlias(adapterID).includes('pubmatic')) {
theBid.defaultBid = 0;
}
}

var endTime = theBid.getReceivedTime();
if (adapterID === "pubmaticServer") {
if ((util.isOwnProperty(window.PWT.owLatency, impressionID)) &&
Expand Down Expand Up @@ -612,7 +632,7 @@ function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o
"ss": theBid.getServerSideStatus(),
"t": theBid.getPostTimeoutStatus() === false ? 0 : 1,
"wb": theBid.getWinningBidStatus() === true ? 1 : 0,
"mi": theBid.getServerSideStatus() ? theBid.getMi() : undefined,
"mi": theBid.getServerSideStatus() ? theBid.getMi(adapterID) : undefined,
"af": theBid.getAdFormat(),
"ocpm": CONFIG.getAdServerCurrency() ? theBid.getOriginalCpm() : theBid.getGrossEcpm(),
"ocry": CONFIG.getAdServerCurrency() ? theBid.getOriginalCurrency() : CONSTANTS.COMMON.ANALYTICS_CURRENCY,
Expand All @@ -623,6 +643,11 @@ function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o
});

impressionIDMap[impressionID].push(slotObject);
// special handling when all media types are disabled for adunit and
// if we are using PrebidServerBidAdapter with
if(usePBSAdapter && CONFIG.getServerEnabledAdaptars().length && pslTime == undefined && !window.pbsLatency) {
pslTime = 0;
}
if (pslTime !== undefined) {
impressionIDMap[impressionID].psl = pslTime;
}
Expand Down
45 changes: 45 additions & 0 deletions src_new/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,49 @@ 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;
}

exports.getPubMaticAndAlias = function(s2sBidders) {
var pubMaticaliases = s2sBidders.filter(function(adapter) {
if(config.alias && config.alias[adapter] && config.alias[adapter].includes("pubmatic") || adapter.includes("pubmatic")) {
return adapter;
}
});
return pubMaticaliases;
}

exports.usePBSAdapter = function() {
if(config.pwt.usePBSAdapter == "1") {
return true;
}
return false;
}

exports.createMacros = function() {
return {
"[PLATFORM]": util.getDevicePlatform().toString(),
"[PROFILE_ID]": refThis.getProfileID().toString(),
"[PROFILE_VERSION]": refThis.getProfileDisplayVersionID().toString()
}
}
19 changes: 18 additions & 1 deletion src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,21 @@ exports.BID_STATUS = {
// Add list of PubMatic aliases here.
exports.PUBMATIC_ALIASES = ["pubmatic2"];

exports.YAHOOSSP = "yahoossp";
exports.PBSPARAMS = {
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
}

exports.DEFAULT_ALIASES = {
adg: "adgeneration",
districtm: "appnexus",
districtmDMX: "dmx",
pubmatic2: "pubmatic"
}
exports.YAHOOSSP = "yahoossp";
Loading