Skip to content

Commit

Permalink
Appnexus: Add omid support (#5821)
Browse files Browse the repository at this point in the history
* basic implementation complete

* add unit tests

* remove redundant field tags[].video.frameworks
  • Loading branch information
Fawke authored Oct 7, 2020
1 parent 8982e09 commit 16fabf4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
32 changes: 32 additions & 0 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const spec = {
const memberIdBid = find(bidRequests, hasMemberId);
const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0;
const schain = bidRequests[0].schain;
const omidSupport = find(bidRequests, hasOmidSupport);

const payload = {
tags: [...tags],
Expand All @@ -168,6 +169,13 @@ export const spec = {
schain: schain
};

if (omidSupport) {
payload['iab_support'] = {
omidpn: 'Appnexus',
omidpv: '$prebid.version$'
}
}

if (member > 0) {
payload.member_id = member;
}
Expand Down Expand Up @@ -766,16 +774,27 @@ function bidToTag(bid) {
type = (utils.isArray(type)) ? type[0] : type;
tag.video[param] = VIDEO_MAPPING[param][type];
break;
// Deprecating tags[].video.frameworks in favor of tags[].video_frameworks
case 'frameworks':
break;
default:
tag.video[param] = bid.params.video[param];
}
});

if (bid.params.video.frameworks && utils.isArray(bid.params.video.frameworks)) {
tag['video_frameworks'] = bid.params.video.frameworks;
}
}

if (bid.renderer) {
tag.video = Object.assign({}, tag.video, { custom_renderer_present: true });
}

if (bid.params.frameworks && utils.isArray(bid.params.frameworks)) {
tag['banner_frameworks'] = bid.params.frameworks;
}

let adUnit = find(auctionManager.getAdUnits(), au => bid.transactionId === au.transactionId);
if (adUnit && adUnit.mediaTypes && adUnit.mediaTypes.banner) {
tag.ad_types.push(BANNER);
Expand Down Expand Up @@ -844,6 +863,19 @@ function hasAdPod(bid) {
);
}

function hasOmidSupport(bid) {
let hasOmid = false;
const bidderParams = bid.params;
const videoParams = bid.params.video;
if (bidderParams.frameworks && utils.isArray(bidderParams.frameworks)) {
hasOmid = includes(bid.params.frameworks, 6);
}
if (!hasOmid && videoParams && videoParams.frameworks && utils.isArray(videoParams.frameworks)) {
hasOmid = includes(bid.params.video.frameworks, 6);
}
return hasOmid;
}

/**
* Expand an adpod placement into a set of request objects according to the
* total adpod duration and the range of duration seconds. Sets minduration/
Expand Down
46 changes: 46 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,52 @@ describe('AppNexusAdapter', function () {
user_id: 'sample-criteo-userid',
});
});

it('should populate iab_support object at the root level if omid support is detected', function () {
// with bid.params.frameworks
let bidRequest_A = Object.assign({}, bidRequests[0], {
params: {
frameworks: [1, 2, 5, 6],
video: {
frameworks: [1, 2, 5, 6]
}
}
});
let request = spec.buildRequests([bidRequest_A]);
let payload = JSON.parse(request.data);
expect(payload.iab_support).to.be.an('object');
expect(payload.iab_support).to.deep.equal({
omidpn: 'Appnexus',
omidpv: '$prebid.version$'
});
expect(payload.tags[0].banner_frameworks).to.be.an('array');
expect(payload.tags[0].banner_frameworks).to.deep.equal([1, 2, 5, 6]);
expect(payload.tags[0].video_frameworks).to.be.an('array');
expect(payload.tags[0].video_frameworks).to.deep.equal([1, 2, 5, 6]);
expect(payload.tags[0].video.frameworks).to.not.exist;

// without bid.params.frameworks
const bidRequest_B = Object.assign({}, bidRequests[0]);
request = spec.buildRequests([bidRequest_B]);
payload = JSON.parse(request.data);
expect(payload.iab_support).to.not.exist;
expect(payload.tags[0].banner_frameworks).to.not.exist;
expect(payload.tags[0].video_frameworks).to.not.exist;

// with video.frameworks but it is not an array
const bidRequest_C = Object.assign({}, bidRequests[0], {
params: {
video: {
frameworks: "'1', '2', '3', '6'"
}
}
});
request = spec.buildRequests([bidRequest_C]);
payload = JSON.parse(request.data);
expect(payload.iab_support).to.not.exist;
expect(payload.tags[0].banner_frameworks).to.not.exist;
expect(payload.tags[0].video_frameworks).to.not.exist;
});
})

describe('interpretResponse', function () {
Expand Down

0 comments on commit 16fabf4

Please sign in to comment.