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

Appnexus bid adapter: support mediaTypes pos field #8275

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,13 @@ function bidToTag(bid) {
}
if (bid.params.position) {
tag.position = { 'above': 1, 'below': 2 }[bid.params.position] || 0;
} else {
let mediaTypePos = deepAccess(bid, `mediaTypes.banner.pos`) || deepAccess(bid, `mediaTypes.video.pos`);
// only support unknown, atf, and btf values for position at this time
if (mediaTypePos === 0 || mediaTypePos === 1 || mediaTypePos === 3) {
// ortb spec treats btf === 3, but our system interprets btf === 2; so converting the ortb value here for consistency
tag.position = (mediaTypePos === 3) ? 2 : mediaTypePos;
}
}
if (bid.params.trafficSourceCode) {
tag.traffic_source_code = bid.params.trafficSourceCode;
Expand Down
51 changes: 50 additions & 1 deletion test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,55 @@ describe('AppNexusAdapter', function () {
expect(payload.tags[0].private_sizes).to.deep.equal([{width: 300, height: 250}]);
});

it('should add position in request', function() {
// set from bid.params
let bidRequest = deepClone(bidRequests[0]);
bidRequest.params.position = 'above';

const request = spec.buildRequests([bidRequest]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].position).to.exist;
expect(payload.tags[0].position).to.deep.equal(1);

// set from mediaTypes.banner.pos = 1
bidRequest = deepClone(bidRequests[0]);
bidRequest.mediaTypes = {
banner: { pos: 1 }
};

const request2 = spec.buildRequests([bidRequest]);
const payload2 = JSON.parse(request2.data);

expect(payload2.tags[0].position).to.exist;
expect(payload2.tags[0].position).to.deep.equal(1);

// set from mediaTypes.video.pos = 3
bidRequest = deepClone(bidRequests[0]);
bidRequest.mediaTypes = {
video: { pos: 3 }
};

const request3 = spec.buildRequests([bidRequest]);
const payload3 = JSON.parse(request3.data);

expect(payload3.tags[0].position).to.exist;
expect(payload3.tags[0].position).to.deep.equal(2);

// bid.params trumps mediatypes
bidRequest = deepClone(bidRequests[0]);
bidRequest.params.position = 'above';
bidRequest.mediaTypes = {
banner: { pos: 3 }
};

const request4 = spec.buildRequests([bidRequest]);
const payload4 = JSON.parse(request4.data);

expect(payload4.tags[0].position).to.exist;
expect(payload4.tags[0].position).to.deep.equal(1);
});

it('should add publisher_id in request', function() {
let bidRequest = Object.assign({},
bidRequests[0],
Expand All @@ -116,7 +165,7 @@ describe('AppNexusAdapter', function () {
expect(payload.tags[0].publisher_id).to.deep.equal(1231234);
expect(payload.publisher_id).to.exist;
expect(payload.publisher_id).to.deep.equal(1231234);
})
});

it('should add source and verison to the tag', function () {
const request = spec.buildRequests(bidRequests);
Expand Down