Skip to content

Commit

Permalink
Sonobi Bid Adapter : send video playbackmethod and placement in the b…
Browse files Browse the repository at this point in the history
…id request (#10474)

* Send video playbackmethod and placement in the bid request to Sonobi

* added a separate field for plcmt
  • Loading branch information
JonGoSonobi authored Sep 13, 2023
1 parent d4203d2 commit 725ed60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
32 changes: 21 additions & 11 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,15 @@ export const spec = {
*/
buildRequests: (validBidRequests, bidderRequest) => {
const bids = validBidRequests.map(bid => {
let mediaType;

if (deepAccess(bid, 'mediaTypes.video')) {
mediaType = 'video';
} else if (deepAccess(bid, 'mediaTypes.banner')) {
mediaType = 'display';
}

let slotIdentifier = _validateSlot(bid);
if (/^[\/]?[\d]+[[\/].+[\/]?]?$/.test(slotIdentifier)) {
slotIdentifier = slotIdentifier.charAt(0) === '/' ? slotIdentifier : '/' + slotIdentifier;
return {
[`${slotIdentifier}|${bid.bidId}`]: `${_validateSize(bid)}|${_validateFloor(bid)}${_validateGPID(bid)}${_validateMediaType(mediaType)}`
[`${slotIdentifier}|${bid.bidId}`]: `${_validateSize(bid)}|${_validateFloor(bid)}${_validateGPID(bid)}${_validateMediaType(bid)}`
}
} else if (/^[0-9a-fA-F]{20}$/.test(slotIdentifier) && slotIdentifier.length === 20) {
return {
[bid.bidId]: `${slotIdentifier}|${_validateSize(bid)}|${_validateFloor(bid)}${_validateGPID(bid)}${_validateMediaType(mediaType)}`
[bid.bidId]: `${slotIdentifier}|${_validateSize(bid)}|${_validateFloor(bid)}${_validateGPID(bid)}${_validateMediaType(bid)}`
}
} else {
logError(`The ad unit code or Sonobi Placement id for slot ${bid.bidId} is invalid`);
Expand Down Expand Up @@ -336,10 +328,28 @@ function _validateGPID(bid) {
return ''
}

function _validateMediaType(mediaType) {
function _validateMediaType(bidRequest) {
let mediaType;
if (deepAccess(bidRequest, 'mediaTypes.video')) {
mediaType = 'video';
} else if (deepAccess(bidRequest, 'mediaTypes.banner')) {
mediaType = 'display';
}

let mediaTypeValidation = '';
if (mediaType === 'video') {
mediaTypeValidation = 'c=v,';
if (deepAccess(bidRequest, 'mediaTypes.video.playbackmethod')) {
mediaTypeValidation = `${mediaTypeValidation}pm=${deepAccess(bidRequest, 'mediaTypes.video.playbackmethod').join(':')},`;
}
if (deepAccess(bidRequest, 'mediaTypes.video.placement')) {
let placement = deepAccess(bidRequest, 'mediaTypes.video.placement');
mediaTypeValidation = `${mediaTypeValidation}p=${placement},`;
}
if (deepAccess(bidRequest, 'mediaTypes.video.plcmt')) {
let plcmt = deepAccess(bidRequest, 'mediaTypes.video.plcmt');
mediaTypeValidation = `${mediaTypeValidation}pl=${plcmt},`;
}
} else if (mediaType === 'display') {
mediaTypeValidation = 'c=d,';
}
Expand Down
7 changes: 5 additions & 2 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ describe('SonobiBidAdapter', function () {
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'outstream'
context: 'outstream',
playbackmethod: [1, 2, 3],
plcmt: 3,
placement: 2
}
}
},
Expand Down Expand Up @@ -339,7 +342,7 @@ describe('SonobiBidAdapter', function () {
}];

let keyMakerData = {
'30b31c1838de1f': '1a2b3c4d5e6f1a2b3c4d|640x480|f=1.25,gpid=/123123/gpt_publisher/adunit-code-1,c=v,',
'30b31c1838de1f': '1a2b3c4d5e6f1a2b3c4d|640x480|f=1.25,gpid=/123123/gpt_publisher/adunit-code-1,c=v,pm=1:2:3,p=2,pl=3,',
'30b31c1838de1d': '1a2b3c4d5e6f1a2b3c4e|300x250,300x600|f=0.42,gpid=/123123/gpt_publisher/adunit-code-3,c=d,',
'/7780971/sparks_prebid_LB|30b31c1838de1e': '300x250,300x600|gpid=/7780971/sparks_prebid_LB,c=d,',
};
Expand Down

0 comments on commit 725ed60

Please sign in to comment.