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

rubicon Bid Adapter : add support for twin ad units #12328

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 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 @@ -212,6 +214,14 @@ export const converter = ortbConverter({

setBidFloors(bidRequest, imp);

// ensure unique imp IDs for twin adunits
let adUnitCode = imp.id;
let i = 2;
while (Object.keys(impIdMap).indexOf(imp.id) > -1) {
imp.id = adUnitCode + i++;
}
impIdMap[imp.id] = adUnitCode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think a loop is needed here

if (impIdMap[imp.id]) {
   imp.id = imp.id + impIdMap[imp.id];
   impIdMap[imp.id] += 1
} else {
   impIdMap[imp.id] = 2;
}

The above can probably even be a bit simplified probably

But the gist is

  • Make a object

{
[name of adunit]: [how many times its been used]
}

Then no looping is needed and if the adunit exists in the map, just append the value to the id and increment.

Let me know if that works / makes sense!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All good, I've made the change :-)


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

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

filteredHttpRequest.push({
method: 'POST',
Expand Down Expand Up @@ -1152,6 +1163,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