Skip to content

Commit

Permalink
PAAPI: fix bug where configuration is not picked up correctly by the …
Browse files Browse the repository at this point in the history
…PBS adapter (prebid#11899)
  • Loading branch information
dgirardi authored and mefjush committed Jul 19, 2024
1 parent e5dd5ac commit ce40079
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 150 deletions.
83 changes: 48 additions & 35 deletions modules/paapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function init(cfg) {
}

getHook('addPaapiConfig').before(addPaapiConfigHook);
getHook('makeBidRequests').before(addPaapiData);
getHook('makeBidRequests').after(markForFledge);
events.on(EVENTS.AUCTION_END, onAuctionEnd);

Expand Down Expand Up @@ -332,38 +333,50 @@ function getRequestedSize(adUnit) {
})();
}

export function addPaapiData(next, adUnits, ...args) {
if (isFledgeSupported() && moduleConfig.enabled) {
adUnits.forEach(adUnit => {
// https://github.com/InteractiveAdvertisingBureau/openrtb/blob/main/extensions/community_extensions/Protected%20Audience%20Support.md
const igsAe = adUnit.ortb2Imp?.ext?.igs != null
? adUnit.ortb2Imp.ext.igs.ae || 1
: null;
const extAe = adUnit.ortb2Imp?.ext?.ae;
if (igsAe !== extAe && igsAe != null && extAe != null) {
logWarn(MODULE, `Ad unit defines conflicting ortb2Imp.ext.ae and ortb2Imp.ext.igs, using the latter`, adUnit);
}
const ae = igsAe ?? extAe ?? moduleConfig.defaultForSlots;
if (ae) {
deepSetValue(adUnit, 'ortb2Imp.ext.ae', ae);
adUnit.ortb2Imp.ext.igs = Object.assign({
ae: ae,
biddable: 1
}, adUnit.ortb2Imp.ext.igs);
const requestedSize = getRequestedSize(adUnit);
if (requestedSize) {
deepSetValue(adUnit, 'ortb2Imp.ext.paapi.requestedSize', requestedSize);
}
adUnit.bids.forEach(bidReq => {
if (!getFledgeConfig(bidReq.bidder).enabled) {
deepSetValue(bidReq, 'ortb2Imp.ext.ae', 0);
bidReq.ortb2Imp.ext.igs = {ae: 0, biddable: 0};
}
})
}
})
}
next(adUnits, ...args);
}

export function markForFledge(next, bidderRequests) {
if (isFledgeSupported()) {
bidderRequests.forEach((bidderReq) => {
const {enabled, ae} = getFledgeConfig(bidderReq.bidderCode);
const {enabled} = getFledgeConfig(bidderReq.bidderCode);
Object.assign(bidderReq, {
paapi: {
enabled,
componentSeller: !!moduleConfig.componentSeller?.auctionConfig
}
});
bidderReq.bids.forEach(bidReq => {
// https://github.com/InteractiveAdvertisingBureau/openrtb/blob/main/extensions/community_extensions/Protected%20Audience%20Support.md
const igsAe = bidReq.ortb2Imp?.ext?.igs != null
? bidReq.ortb2Imp.ext.igs.ae || 1
: null;
const extAe = bidReq.ortb2Imp?.ext?.ae;
if (igsAe !== extAe && igsAe != null && extAe != null) {
logWarn(MODULE, `Bid request defines conflicting ortb2Imp.ext.ae and ortb2Imp.ext.igs, using the latter`, bidReq);
}
const bidAe = igsAe ?? extAe ?? ae;
if (bidAe) {
deepSetValue(bidReq, 'ortb2Imp.ext.ae', bidAe);
bidReq.ortb2Imp.ext.igs = Object.assign({
ae: bidAe,
biddable: 1
}, bidReq.ortb2Imp.ext.igs);
const requestedSize = getRequestedSize(bidReq);
if (requestedSize) {
deepSetValue(bidReq, 'ortb2Imp.ext.paapi.requestedSize', requestedSize);
}
}
});
});
}
next(bidderRequests);
Expand All @@ -378,18 +391,6 @@ export function setImpExtAe(imp, bidRequest, context) {

registerOrtbProcessor({type: IMP, name: 'impExtAe', fn: setImpExtAe});

function paapiResponseParser(configs, response, context) {
configs.forEach((config) => {
const impCtx = context.impContext[config.impid];
if (!impCtx?.imp?.ext?.ae) {
logWarn(MODULE, 'Received auction configuration for an impression that was not in the request or did not ask for it', config, impCtx?.imp);
} else {
impCtx.paapiConfigs = impCtx.paapiConfigs || [];
impCtx.paapiConfigs.push(config);
}
});
}

export function parseExtIgi(response, ortbResponse, context) {
paapiResponseParser(
(ortbResponse.ext?.igi || []).flatMap(igi => {
Expand All @@ -411,6 +412,18 @@ export function parseExtIgi(response, ortbResponse, context) {
)
}

function paapiResponseParser(configs, response, context) {
configs.forEach((config) => {
const impCtx = context.impContext[config.impid];
if (!impCtx?.imp?.ext?.ae) {
logWarn(MODULE, 'Received auction configuration for an impression that was not in the request or did not ask for it', config, impCtx?.imp);
} else {
impCtx.paapiConfigs = impCtx.paapiConfigs || [];
impCtx.paapiConfigs.push(config);
}
});
}

// to make it easier to share code between the PBS adapter and adapters whose backend is PBS, break up
// fledge response processing in two steps: first aggregate all the auction configs by their imp...

Expand Down
4 changes: 3 additions & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ export function PrebidServer() {
}
},
onFledge: (params) => {
addPaapiConfig({auctionId: bidRequests[0].auctionId, ...params}, {config: params.config});
config.runWithBidder(params.bidder, () => {
addPaapiConfig({auctionId: bidRequests[0].auctionId, ...params}, {config: params.config});
})
}
})
}
Expand Down
1 change: 1 addition & 0 deletions modules/prebidServerBidAdapter/ortbConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ const PBS_CONVERTER = ortbConverter({
adUnitCode: impCtx.adUnit.code,
ortb2: bidderReq?.ortb2,
ortb2Imp: bidReq?.ortb2Imp,
bidder: cfg.bidder,
config: cfg.config
};
}));
Expand Down
Loading

0 comments on commit ce40079

Please sign in to comment.