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

PBS Bid Adapter: Fix duplicate imp.id #6933

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Changes from all commits
Commits
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
25 changes: 18 additions & 7 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,24 @@ const OPEN_RTB_PROTOCOL = {
const firstBidRequest = bidRequests[0];

// transform ad unit into array of OpenRTB impression objects
let impIds = new Set();
adUnits.forEach(adUnit => {
// in case there is a duplicate imp.id, add '-2' suffix to the second imp.id.
// e.g. if there are 2 adUnits (case of twin adUnit codes) with code 'test',
// first imp will have id 'test' and second imp will have id 'test-2'
let impressionId = adUnit.code;
let i = 1;
while (impIds.has(impressionId)) {
i++;
impressionId = `${adUnit.code}-${i}`;
}
impIds.add(impressionId);

const nativeParams = processNativeAdUnitParams(utils.deepAccess(adUnit, 'mediaTypes.native'));
let nativeAssets;
if (nativeParams) {
try {
nativeAssets = nativeAssetCache[adUnit.code] = Object.keys(nativeParams).reduce((assets, type) => {
nativeAssets = nativeAssetCache[impressionId] = Object.keys(nativeParams).reduce((assets, type) => {
let params = nativeParams[type];

function newAsset(obj) {
Expand Down Expand Up @@ -563,10 +575,9 @@ const OPEN_RTB_PROTOCOL = {
const bannerParams = utils.deepAccess(adUnit, 'mediaTypes.banner');

adUnit.bids.forEach(bid => {
// OpenRTB response contains the adunit code and bidder name. These are
// OpenRTB response contains imp.id and bidder name. These are
// combined to create a unique key for each bid since an id isn't returned
bidIdMap[`${adUnit.code}${bid.bidder}`] = bid.bid_id;

bidIdMap[`${impressionId}${bid.bidder}`] = bid.bid_id;
// check for and store valid aliases to add to the request
if (adapterManager.aliasRegistry[bid.bidder]) {
const bidder = adapterManager.bidderRegistry[bid.bidder];
Expand Down Expand Up @@ -647,7 +658,7 @@ const OPEN_RTB_PROTOCOL = {
return acc;
}, {...utils.deepAccess(adUnit, 'ortb2Imp.ext')});

const imp = { id: adUnit.code, ext, secure: s2sConfig.secure };
const imp = { id: impressionId, ext, secure: s2sConfig.secure };

const ortb2 = {...utils.deepAccess(adUnit, 'ortb2Imp.ext.data')};
Object.keys(ortb2).forEach(prop => {
Expand Down Expand Up @@ -941,7 +952,7 @@ const OPEN_RTB_PROTOCOL = {
}

if (utils.isPlainObject(adm) && Array.isArray(adm.assets)) {
let origAssets = nativeAssetCache[bidRequest.adUnitCode];
let origAssets = nativeAssetCache[bid.impid];
bidObject.native = utils.cleanObj(adm.assets.reduce((native, asset) => {
let origAsset = origAssets[asset.id];
if (utils.isPlainObject(asset.img)) {
Expand Down Expand Up @@ -996,7 +1007,7 @@ const OPEN_RTB_PROTOCOL = {
bidObject.ttl = (bid.exp) ? bid.exp : configTtl;
bidObject.netRevenue = (bid.netRevenue) ? bid.netRevenue : DEFAULT_S2S_NETREVENUE;

bids.push({ adUnit: bid.impid, bid: bidObject });
bids.push({ adUnit: bidRequest.adUnitCode, bid: bidObject });
});
});
}
Expand Down