Skip to content

Commit

Permalink
OpenX Bid Adapter : fix to determine bid mediaType based on ad markup (
Browse files Browse the repository at this point in the history
…#12695)

* hotfix: Determine bid mtype based on ad markup

* hotfix: Determine mediaType only when no context.mediaType

* hotfix: Determine mediaType only when no context.mediaType and no bid.mtype

* hotfix: Fix unit test for mediaType

* hotfix: Check if adm contains any of vast keywords

* hotfix: Add unit test

* hotfix: Add unit test

* hotfix: Remove dur from vast keywords
  • Loading branch information
gmiedlar-ox authored Jan 28, 2025
1 parent 0c60b11 commit 698ede8
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 10 deletions.
13 changes: 13 additions & 0 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as utils from '../src/utils.js';
import {mergeDeep} from '../src/utils.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
import {ORTB_MTYPES} from '../libraries/ortbConverter/processors/mediaType.js';

const bidderConfig = 'hb_pb_ortb';
const bidderVersion = '2.0';
Expand Down Expand Up @@ -79,6 +80,18 @@ const converter = ortbConverter({
return req;
},
bidResponse(buildBidResponse, bid, context) {
if (!context.mediaType && !bid.mtype) {
let mediaType = BANNER; // default media type
const vastKeywords = ['VAST ', 'vast ', 'videoad', 'VAST_VERSION', 'dc_vast', 'video '];
if (bid.adm && bid.adm.startsWith('{') && bid.adm.includes('"assets"')) {
mediaType = NATIVE;
} else if (bid.vastXml || bid.vastUrl || (bid.adm && vastKeywords.some(v => bid.adm.includes(v)))) {
mediaType = VIDEO;
}
bid.mediaType = mediaType;
bid.mtype = Object.keys(ORTB_MTYPES).find(key => ORTB_MTYPES[key] === mediaType);
}

const bidResponse = buildBidResponse(bid, context);
if (bid.ext) {
bidResponse.meta.networkId = bid.ext.dsp_id;
Expand Down
232 changes: 222 additions & 10 deletions test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from 'chai';
import {spec, REQUEST_URL, SYNC_URL, DEFAULT_PH} from 'modules/openxBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from 'src/mediaTypes.js';
import {BANNER, NATIVE, VIDEO} from 'src/mediaTypes.js';
import {config} from 'src/config.js';
import * as utils from 'src/utils.js';
// load modules that register ORTB processors
Expand Down Expand Up @@ -1381,7 +1381,6 @@ describe('OpenxRtbAdapter', function () {
crid: 'test-creative-id',
dealid: 'test-deal-id',
adm: 'test-ad-markup',
mtype: 1,
adomain: ['brand.com'],
ext: {
dsp_id: '123',
Expand Down Expand Up @@ -1456,7 +1455,7 @@ describe('OpenxRtbAdapter', function () {
});
});

context('when the response is a banner', function() {
context('when banner request and the response is a banner', function() {
beforeEach(function () {
bidRequestConfigs = [{
bidder: 'openx',
Expand Down Expand Up @@ -1496,14 +1495,12 @@ describe('OpenxRtbAdapter', function () {
});

it('should return the proper mediaType', function () {
it('should return a creativeId', function () {
expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]);
});
expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]);
});
});

if (FEATURES.VIDEO) {
context('when the response is a video', function() {
context('when video request and the response is a video', function() {
beforeEach(function () {
bidRequestConfigs = [{
bidder: 'openx',
Expand Down Expand Up @@ -1533,7 +1530,7 @@ describe('OpenxRtbAdapter', function () {
h: 480,
crid: 'test-creative-id',
dealid: 'test-deal-id',
adm: 'test-ad-markup',
adm: '<VAST version="4.0"><Ad></Ad></VAST>',
}]
}],
cur: 'AUS'
Expand All @@ -1553,10 +1550,107 @@ describe('OpenxRtbAdapter', function () {
expect(bid.vastUrl).to.equal(winUrl);
});
});

context('when multi-format request (banner + video) and the response is a video', function() {
beforeEach(function () {
bidRequestConfigs = [{
bidder: 'openx',
params: {
unit: '12345678',
delDomain: 'test-del-domain'
},
adUnitCode: 'adunit-code',
mediaTypes: {
banner: {
size: [[300, 600]]
},
video: {
playerSize: [[640, 360], [854, 480]],
},
},
bidId: 'test-bid-id',
bidderRequestId: 'test-bidder-request-id',
auctionId: 'test-auction-id'
}];

bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0];

bidResponse = {
seatbid: [{
bid: [{
impid: 'test-bid-id',
price: 5,
adm: '<VAST version="4.0"><Ad></Ad></VAST>',
}]
}],
cur: 'USD'
};
});

it('should return video mediaType', function () {
bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0];
expect(bid.mediaType).to.equal(VIDEO);
});
});

context('when multiple bid requests (banner + video) and the response is a banner', function() {
beforeEach(function () {
bidRequestConfigs = [{
bidder: 'openx',
params: {
unit: '12345678',
delDomain: 'test-del-domain'
},
adUnitCode: 'adunit-code',
mediaTypes: {
video: {
playerSize: [[640, 360], [854, 480]],
},
},
bidId: 'test-bid-id-1',
bidderRequestId: 'test-bidder-request-id-1',
auctionId: 'test-auction-id-1'
},
{
bidder: 'openx',
params: {
unit: '12345678',
delDomain: 'test-del-domain'
},
adUnitCode: 'adunit-code',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
bidId: 'test-bid-id-2',
bidderRequestId: 'test-bidder-request-id-2',
auctionId: 'test-auction-id-2'
}];

bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0];

bidResponse = {
seatbid: [{
bid: [{
impid: 'test-bid-id-2',
price: 2,
adm: '<iframe src="https://test.url"></iframe>',
}]
}],
cur: 'USD'
};
});

it('should return banner mediaType', function () {
bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0];
expect(bid.mediaType).to.equal(BANNER);
});
});
}

if (FEATURES.NATIVE) {
context('when the response is a native', function() {
context('when native request and the response is a native', function() {
beforeEach(function () {
const nativeOrtbRequest = {
ver: '1.2',
Expand Down Expand Up @@ -1593,7 +1687,6 @@ describe('OpenxRtbAdapter', function () {
bid: [{
impid: 'test-bid-id',
price: 2,
mtype: 4,
adm: '{"ver": "1.2", "assets": [{"id": 1, "required": 1,"title": {"text": "OpenX (Title)"}}], "link": {"url": "https://www.openx.com/"}, "eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}',
}]
}],
Expand Down Expand Up @@ -1625,6 +1718,125 @@ describe('OpenxRtbAdapter', function () {
});
});
});

context('when multi-format request (banner + native) and the response is a banner', function() {
beforeEach(function () {
const nativeOrtbRequest = {
ver: '1.2',
assets: [{
id: 1,
required: 1,
title: {
len: 80
}
}]
};
bidRequestConfigs = [{
bidder: 'openx',
params: {
unit: '12345678',
delDomain: 'test-del-domain'
},
adUnitCode: 'adunit-code',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
},
native: {
...nativeOrtbRequest
},
},
nativeOrtbRequest,
bidId: 'test-bid-id',
bidderRequestId: 'test-bidder-request-id',
auctionId: 'test-auction-id'
}];

bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0];

bidResponse = {
seatbid: [{
bid: [{
impid: 'test-bid-id',
price: 2,
adm: '<iframe src="https://test.url"></iframe>',
}]
}],
cur: 'AUS'
};
});

it('should return banner mediaType', function () {
bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0];
expect(bid.mediaType).to.equal(BANNER);
});
});

context('when multiple bid requests (banner + native) and the response is a native', function() {
beforeEach(function () {
const nativeOrtbRequest = {
ver: '1.2',
assets: [{
id: 1,
required: 1,
title: {
len: 80
}
}]
};
bidRequestConfigs = [{
bidder: 'openx',
params: {
unit: '12345678',
delDomain: 'test-del-domain'
},
adUnitCode: 'adunit-code',
mediaTypes: {
native: {
...nativeOrtbRequest
},
},
nativeOrtbRequest,
bidId: 'test-bid-id-1',
bidderRequestId: 'test-bidder-request-id-1',
auctionId: 'test-auction-id-1'
},
{
bidder: 'openx',
params: {
unit: '12345678',
delDomain: 'test-del-domain'
},
adUnitCode: 'adunit-code',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
bidId: 'test-bid-id-2',
bidderRequestId: 'test-bidder-request-id-2',
auctionId: 'test-auction-id-2'
}];

bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0];

bidResponse = {
seatbid: [{
bid: [{
impid: 'test-bid-id-1',
price: 2,
adm: '{"ver": "1.2", "assets": [{"id": 1, "required": 1,"title": {"text": "OpenX (Title)"}}], "link": {"url": "https://www.openx.com/"}, "eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}',
}]
}],
cur: 'USD'
};
});

it('should return native mediaType', function () {
bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0];
expect(bid.mediaType).to.equal(NATIVE);
});
});
}

context('when the response contains FLEDGE interest groups config', function() {
Expand Down

0 comments on commit 698ede8

Please sign in to comment.