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

Sovrn Bid Adaptter: add video to Sovrn adapter #7929

Merged
merged 4 commits into from
Jan 19, 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
111 changes: 93 additions & 18 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess } from '../src/utils.js';
import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess, isInteger, logWarn } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER } from '../src/mediaTypes.js'
import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js'
import { createEidsArray } from './userId/eids.js';
import {config} from '../src/config.js';

const ORTB_VIDEO_PARAMS = {
'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'),
'minduration': (value) => isInteger(value),
'maxduration': (value) => isInteger(value),
'protocols': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 10),
'w': (value) => isInteger(value),
'h': (value) => isInteger(value),
'startdelay': (value) => isInteger(value),
'placement': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 5),
'linearity': (value) => [1, 2].indexOf(value) !== -1,
'skip': (value) => [0, 1].indexOf(value) !== -1,
'skipmin': (value) => isInteger(value),
'skipafter': (value) => isInteger(value),
'sequence': (value) => isInteger(value),
'battr': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 17),
'maxextended': (value) => isInteger(value),
'minbitrate': (value) => isInteger(value),
'maxbitrate': (value) => isInteger(value),
'boxingallowed': (value) => [0, 1].indexOf(value) !== -1,
'playbackmethod': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6),
'playbackend': (value) => [1, 2, 3].indexOf(value) !== -1,
'delivery': (value) => [1, 2, 3].indexOf(value) !== -1,
'pos': (value) => Array.isArray(value) && value.every(v => v >= 0 && v <= 7),
'api': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6)
}

export const spec = {
code: 'sovrn',
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],
gvlid: 13,

/**
Expand All @@ -15,7 +41,12 @@ export const spec = {
* @return boolean for whether or not a bid is valid
*/
isBidRequestValid: function(bid) {
return !!(bid.params.tagid && !isNaN(parseFloat(bid.params.tagid)) && isFinite(bid.params.tagid))
return !!(
bid.params.tagid &&
!isNaN(parseFloat(bid.params.tagid)) &&
isFinite(bid.params.tagid) &&
deepAccess(bid, 'mediaTypes.video.context') !== ADPOD
)
},

/**
Expand Down Expand Up @@ -50,27 +81,34 @@ export const spec = {
}
iv = iv || getBidIdParameter('iv', bid.params)

let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes
bidSizes = ((isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes])
bidSizes = bidSizes.filter(size => isArray(size))
const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}))
const floorInfo = (bid.getFloor && typeof bid.getFloor === 'function') ? bid.getFloor({
currency: 'USD',
mediaType: 'banner',
mediaType: bid.mediaTypes && bid.mediaTypes.banner ? 'banner' : 'video',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This way you don't support bid with multi mediatype. I just want to be sure that this is what you expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is what we expect.

size: '*'
}) : {}
floorInfo.floor = floorInfo.floor || getBidIdParameter('bidfloor', bid.params)

const imp = {
adunitcode: bid.adUnitCode,
id: bid.bidId,
banner: {
tagid: String(getBidIdParameter('tagid', bid.params)),
bidfloor: floorInfo.floor
}

if (deepAccess(bid, 'mediaTypes.banner')) {
let bidSizes = deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes
bidSizes = (isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes]
bidSizes = bidSizes.filter(size => isArray(size))
const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}))

imp.banner = {
format: processedSizes,
w: 1,
h: 1,
},
tagid: String(getBidIdParameter('tagid', bid.params)),
bidfloor: floorInfo.floor
};
}
if (deepAccess(bid, 'mediaTypes.video')) {
imp.video = _buildVideoRequestObj(bid);
}

imp.ext = getBidIdParameter('ext', bid.ortb2Imp) || undefined
Expand Down Expand Up @@ -149,7 +187,7 @@ export const spec = {
seatbid[0].bid &&
seatbid[0].bid.length > 0) {
seatbid[0].bid.map(sovrnBid => {
sovrnBidResponses.push({
const bid = {
requestId: sovrnBid.impid,
cpm: parseFloat(sovrnBid.price),
width: parseInt(sovrnBid.w),
Expand All @@ -158,11 +196,18 @@ export const spec = {
dealId: sovrnBid.dealid || null,
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: decodeURIComponent(`${sovrnBid.adm}<img src="${sovrnBid.nurl}">`),
ttl: sovrnBid.ext ? (sovrnBid.ext.ttl || 90) : 90,
meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] }
});
}

if (!sovrnBid.nurl) {
bid.mediaType = VIDEO
bid.vastXml = decodeURIComponent(sovrnBid.adm)
} else {
bid.mediaType = BANNER
bid.ad = decodeURIComponent(`${sovrnBid.adm}<img src="${sovrnBid.nurl}">`)
}
sovrnBidResponses.push(bid);
});
}
return sovrnBidResponses
Expand Down Expand Up @@ -209,4 +254,34 @@ export const spec = {
},
}

registerBidder(spec);
function _buildVideoRequestObj(bid) {
const videoObj = {}
const videoAdUnitParams = deepAccess(bid, 'mediaTypes.video', {})
const videoBidderParams = deepAccess(bid, 'params.video', {})
const computedParams = {}

if (Array.isArray(videoAdUnitParams.playerSize)) {
const sizes = (Array.isArray(videoAdUnitParams.playerSize[0])) ? videoAdUnitParams.playerSize[0] : videoAdUnitParams.playerSize
computedParams.w = sizes[0]
computedParams.h = sizes[1]
}

const videoParams = {
...computedParams,
...videoAdUnitParams,
...videoBidderParams
};

Object.keys(ORTB_VIDEO_PARAMS).forEach(paramName => {
if (videoParams.hasOwnProperty(paramName)) {
if (ORTB_VIDEO_PARAMS[paramName](videoParams[paramName])) {
videoObj[paramName] = videoParams[paramName]
} else {
logWarn(`The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`);
}
}
})
return videoObj
}

registerBidder(spec)
82 changes: 80 additions & 2 deletions modules/sovrnBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Maintainer: [email protected]

Sovrn's adapter integration to the Prebid library. Posts plain-text JSON to the /rtb/bid endpoint.

# Test Parameters
# Banner Test Parameters

```
```js
var adUnits = [
{
code: 'test-leaderboard',
Expand Down Expand Up @@ -45,3 +45,81 @@ var adUnits = [
}
]
```

# Video Test Parameters
### Instream
```js
var videoAdUnit = {
code: 'video1',
sizes: [640, 480],
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480],
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
playbackmethod: [2],
skip: 1,
},
},
bids: [
{
bidder: 'sovrn',
// Prebid Server Bidder Params https://docs.prebid.org/dev-docs/pbs-bidders.html#sovrn
params: {
tagid: '315045',
bidfloor: '0.04',
},
},
],
}
```
### Outstream
```js
var adUnits = [
{
code: videoId,
mediaTypes: {
video: {
context: 'outstream',
playerSize: [640, 360],
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
playbackmethod: [2],
skip: 1,
},
},
bids: [
{
bidder: 'sovrn',
// Prebid Server Bidder Params https://docs.prebid.org/dev-docs/pbs-bidders.html#sovrn
params: {
tagid: '315045',
bidfloor: '0.04',
},
},
],
renderer: {
url: 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js',
render: function (bid) {
adResponse = {
ad: {
video: {
content: bid.vastXml,
player_height: bid.height,
player_width: bid.width,
},
},
}
// push to render queue because ANOutstreamVideo may not be loaded yet.
bid.renderer.push(() => {
ANOutstreamVideo.renderAd({
targetId: bid.adUnitCode,
adResponse: adResponse,
})
})
},
},
},
]
```
Loading