Skip to content

Commit

Permalink
rubicon Bid Adapter : add support for twin ad units (#12328)
Browse files Browse the repository at this point in the history
* Add support for twin ad units

* Remove impIdMap loop in favour of ternary operator
  • Loading branch information
ourcraig authored Oct 31, 2024
1 parent 190f540 commit b4efa80
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
7 changes: 7 additions & 0 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ config.getConfig('rubicon', config => {

const GVLID = 52;

let impIdMap = {};

var sizeMap = {
1: '468x60',
2: '728x90',
Expand Down Expand Up @@ -218,6 +220,9 @@ export const converter = ortbConverter({

setBidFloors(bidRequest, imp);

// ensure unique imp IDs for twin adunits
imp.id = impIdMap[imp.id] ? imp.id + impIdMap[imp.id]++ : (impIdMap[imp.id] = 2, imp.id);

return imp;
},
bidResponse(buildBidResponse, bid, context) {
Expand Down Expand Up @@ -308,6 +313,7 @@ export const spec = {

if (filteredRequests && filteredRequests.length) {
const data = converter.toORTB({bidRequests: filteredRequests, bidderRequest});
resetImpIdMap();

filteredHttpRequest.push({
method: 'POST',
Expand Down Expand Up @@ -1158,6 +1164,7 @@ function bidType(bid, log = false) {
}

export const resetRubiConf = () => rubiConf = {};
export const resetImpIdMap = () => impIdMap = {};
export function masSizeOrdering(sizes) {
const MAS_SIZE_PRIORITY = [15, 2, 9];

Expand Down
64 changes: 42 additions & 22 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
resetUserSync,
classifiedAsVideo,
resetRubiConf,
resetImpIdMap,
converter
} from 'modules/rubiconBidAdapter.js';
import {config} from 'src/config.js';
Expand Down Expand Up @@ -485,6 +486,7 @@ describe('the rubicon adapter', function () {
utils.logError.restore();
config.resetConfig();
resetRubiConf();
resetImpIdMap();
delete $$PREBID_GLOBAL$$.installedModules;
});

Expand Down Expand Up @@ -3060,6 +3062,21 @@ describe('the rubicon adapter', function () {
expect(other).to.be.empty;
});
});

describe('with duplicate adUnitCodes', () => {
it('should increment PBS request imp[].id starting at 2', () => {
const nativeBidderRequest = addNativeToBidRequest(bidderRequest, {twin: true});
const request = converter.toORTB({bidderRequest: nativeBidderRequest, bidRequests: nativeBidderRequest.bids});
for (let i = 0; i < nativeBidderRequest.bids.length; i++) {
var adUnitCode = nativeBidderRequest.bids[i].adUnitCode;
if (i === 0) {
expect(request.imp[i].id).to.equal(adUnitCode);
} else {
expect(request.imp[i].id).to.equal(adUnitCode + (i + 1));
}
}
});
});
});
}
});
Expand Down Expand Up @@ -3997,7 +4014,7 @@ describe('the rubicon adapter', function () {
let bids = spec.interpretResponse({body: response}, {data: request});
expect(bids[0].width).to.equal(0);
expect(bids[0].height).to.equal(0);
})
});
});
}

Expand Down Expand Up @@ -4545,7 +4562,7 @@ describe('the rubicon adapter', function () {
});
});

function addNativeToBidRequest(bidderRequest) {
function addNativeToBidRequest(bidderRequest, options = {twin: false}) {
const nativeOrtbRequest = {
assets: [{
id: 0,
Expand Down Expand Up @@ -4574,27 +4591,30 @@ function addNativeToBidRequest(bidderRequest) {
bidderRequest.refererInfo = {
page: 'localhost'
}
bidderRequest.bids[0] = {
bidder: 'rubicon',
params: {
accountId: '14062',
siteId: '70608',
zoneId: '335918',
},
adUnitCode: '/19968336/header-bid-tag-0',
code: 'div-1',
bidId: '2ffb201a808da7',
bidderRequestId: '178e34bad3658f',
auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a',
transactionId: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b',
mediaTypes: {
native: {
ortb: {
...nativeOrtbRequest
const numBids = !options.twin ? 1 : 2;
for (let i = 0; i < numBids; i++) {
bidderRequest.bids[i] = {
bidder: 'rubicon',
params: {
accountId: '14062',
siteId: '70608',
zoneId: '335918',
},
adUnitCode: '/19968336/header-bid-tag-0',
code: 'div-1',
bidId: '2ffb201a808da7',
bidderRequestId: '178e34bad3658f',
auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a',
transactionId: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b',
mediaTypes: {
native: {
ortb: {
...nativeOrtbRequest
}
}
}
},
nativeOrtbRequest
},
nativeOrtbRequest
}
}
return bidderRequest;
}
Expand Down

0 comments on commit b4efa80

Please sign in to comment.