Skip to content

Commit

Permalink
Seedtag Bid Adapter: read video params from mediaTypes, and allow ove…
Browse files Browse the repository at this point in the history
…rride from bidder params, support passing adomain (#6888)

* read video params from mediaTypes, and allow override from from bidder

* implement meta.advertiserDomain

* fix unit tests

* allow outstream video
  • Loading branch information
ybootin authored Jun 2, 2021
1 parent 0f267d8 commit 5698959
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 25 deletions.
51 changes: 34 additions & 17 deletions modules/seedtagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function mapMediaType(seedtagMediaType) {
}

function hasVideoMediaType(bid) {
return !!bid.mediaTypes && !!bid.mediaTypes.video
return (!!bid.mediaTypes && !!bid.mediaTypes.video) || (!!bid.params && !!bid.params.video)
}

function hasMandatoryParams(params) {
Expand All @@ -58,13 +58,12 @@ function hasMandatoryParams(params) {
);
}

function hasMandatoryVideoParams(mediaTypes) {
const isVideoInStream =
!!mediaTypes.video && mediaTypes.video.context === 'instream';
const isPlayerSize =
!!utils.deepAccess(mediaTypes, 'video.playerSize') &&
utils.isArray(utils.deepAccess(mediaTypes, 'video.playerSize'));
return isVideoInStream && isPlayerSize;
function hasMandatoryVideoParams(bid) {
const videoParams = getVideoParams(bid)

return hasVideoMediaType(bid) && !!videoParams.playerSize &&
utils.isArray(videoParams.playerSize) &&
videoParams.playerSize.length > 0;
}

function buildBidRequests(validBidRequests) {
Expand All @@ -91,18 +90,33 @@ function buildBidRequests(validBidRequests) {
}

if (hasVideoMediaType(validBidRequest)) {
bidRequest.videoParams = params.video || {};
bidRequest.videoParams.w =
validBidRequest.mediaTypes.video.playerSize[0][0];
bidRequest.videoParams.h =
validBidRequest.mediaTypes.video.playerSize[0][1];
bidRequest.videoParams = getVideoParams(validBidRequest)
}

return bidRequest;
})
}

function buildBid(seedtagBid) {
/**
* return video param (global or overrided per bidder)
*/
function getVideoParams(validBidRequest) {
const videoParams = validBidRequest.mediaTypes.video || {};
if (videoParams.playerSize) {
videoParams.w = videoParams.playerSize[0][0];
videoParams.h = videoParams.playerSize[0][1];
}

const bidderVideoParams = (validBidRequest.params && validBidRequest.params.video) || {}
// override video params from seedtag bidder params
Object.keys(bidderVideoParams).forEach(key => {
videoParams[key] = validBidRequest.params.video[key]
})

return videoParams
}

function buildBidResponse(seedtagBid) {
const mediaType = mapMediaType(seedtagBid.mediaType);
const bid = {
requestId: seedtagBid.bidId,
Expand All @@ -114,7 +128,10 @@ function buildBid(seedtagBid) {
netRevenue: true,
mediaType: mediaType,
ttl: seedtagBid.ttl,
nurl: seedtagBid.nurl
nurl: seedtagBid.nurl,
meta: {
advertiserDomains: seedtagBid && seedtagBid.adomain && seedtagBid.adomain.length > 0 ? seedtagBid.adomain : []
}
};

if (mediaType === VIDEO) {
Expand Down Expand Up @@ -152,7 +169,7 @@ export const spec = {
*/
isBidRequestValid(bid) {
return hasVideoMediaType(bid)
? hasMandatoryParams(bid.params) && hasMandatoryVideoParams(bid.mediaTypes)
? hasMandatoryParams(bid.params) && hasMandatoryVideoParams(bid)
: hasMandatoryParams(bid.params);
},

Expand Down Expand Up @@ -197,7 +214,7 @@ export const spec = {
const serverBody = serverResponse.body;
if (serverBody && serverBody.bids && utils.isArray(serverBody.bids)) {
return utils._map(serverBody.bids, function(bid) {
return buildBid(bid);
return buildBidResponse(bid);
});
} else {
return [];
Expand Down
21 changes: 17 additions & 4 deletions modules/seedtagBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ var adUnits = [{
mediaTypes: {
video: {
context: 'instream', // required
playerSize: [600, 300] // required
playerSize: [600, 300], // required
mimes: ['video/mp4'], // recommended
minduration: 5, // optional
maxduration: 60, // optional
boxingallowed: 1, // optional
skip: 1, // optional
startdelay: 1, // optional
linearity: 1, // optional
battr: [1, 2], // optional
maxbitrate: 10, // optional
playbackmethod: [1], // optional
delivery: [1], // optional
placement: 1, // optional
}
},
bids: [
Expand All @@ -57,9 +69,10 @@ var adUnits = [{
adUnitId: '0000', // required
placement: 'video', // required
adPosition: 0, // optional
// Video object as specified in OpenRTB 2.5
video: {
mimes: ['video/mp4'], // recommended
video: { // optional
context: 'instream', // optional
playerSize: [600, 300], // optional
mimes: ['video/mp4'], // optional
minduration: 5, // optional
maxduration: 60, // optional
boxingallowed: 1, // optional
Expand Down
29 changes: 25 additions & 4 deletions test/spec/modules/seedtagBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Seedtag Adapter', function() {
})
})
describe('when video slot has all mandatory params', function() {
it('should return true, when video mediatype object are correct.', function() {
it('should return true, when video context is instream', function () {
const slotConfig = getSlotConfigs(
{
video: {
Expand All @@ -72,6 +72,24 @@ describe('Seedtag Adapter', function() {
const isBidRequestValid = spec.isBidRequestValid(slotConfig)
expect(isBidRequestValid).to.equal(true)
})

it('should return true, when video context is outstream', function () {
const slotConfig = getSlotConfigs(
{
video: {
context: 'outstream',
playerSize: [[600, 200]]
}
},
{
publisherId: PUBLISHER_ID,
adUnitId: ADUNIT_ID,
placement: 'video'
}
)
const isBidRequestValid = spec.isBidRequestValid(slotConfig)
expect(isBidRequestValid).to.equal(true)
})
})
})
describe('returns false', function() {
Expand Down Expand Up @@ -137,7 +155,7 @@ describe('Seedtag Adapter', function() {
)
expect(isBidRequestValid).to.equal(false)
})
it('is not instream ', function() {
it('is outstream ', function () {
const isBidRequestValid = spec.isBidRequestValid(
createVideoSlotConfig({
video: {
Expand All @@ -146,7 +164,7 @@ describe('Seedtag Adapter', function() {
}
})
)
expect(isBidRequestValid).to.equal(false)
expect(isBidRequestValid).to.equal(true)
})
describe('order does not matter', function() {
it('when video is not the first slot', function() {
Expand Down Expand Up @@ -326,7 +344,8 @@ describe('Seedtag Adapter', function() {
height: 90,
mediaType: 'display',
ttl: 360,
nurl: 'testurl.com/nurl'
nurl: 'testurl.com/nurl',
adomain: ['advertiserdomain.com']
}
],
cookieSync: { url: '' }
Expand All @@ -342,6 +361,7 @@ describe('Seedtag Adapter', function() {
expect(bids[0].netRevenue).to.equal(true)
expect(bids[0].ad).to.equal('content')
expect(bids[0].nurl).to.equal('testurl.com/nurl')
expect(bids[0].meta.advertiserDomains).to.deep.equal(['advertiserdomain.com'])
})
})
describe('the bid is a video', function() {
Expand Down Expand Up @@ -374,6 +394,7 @@ describe('Seedtag Adapter', function() {
expect(bids[0].currency).to.equal('USD')
expect(bids[0].netRevenue).to.equal(true)
expect(bids[0].vastXml).to.equal('content')
expect(bids[0].meta.advertiserDomains).to.deep.equal([])
})
})
})
Expand Down

0 comments on commit 5698959

Please sign in to comment.