-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Synacormedia: Added video support to adapter. #3695
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,26 @@ | |
|
||
import { getAdUnitSizes, logWarn } from '../src/utils'; | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
import { BANNER } from '../src/mediaTypes'; | ||
import { BANNER, VIDEO } from '../src/mediaTypes'; | ||
import includes from 'core-js/library/fn/array/includes'; | ||
|
||
const BID_HOST = '//prebid.technoratimedia.com'; | ||
const USER_SYNC_HOST = '//ad-cdn.technoratimedia.com'; | ||
const VIDEO_PARAMS = [ 'minduration', 'maxduration' ]; | ||
|
||
export const spec = { | ||
code: 'synacormedia', | ||
supportedMediaTypes: [ BANNER ], | ||
supportedMediaTypes: [ BANNER, VIDEO ], | ||
sizeMap: {}, | ||
|
||
isVideoBid: function(bid) { | ||
return bid.mediaTypes !== undefined && | ||
bid.mediaTypes.hasOwnProperty('video'); | ||
}, | ||
isBidRequestValid: function(bid) { | ||
return !!(bid && bid.params && bid.params.placementId && bid.params.seatId); | ||
}, | ||
|
||
buildRequests: function(validBidReqs, bidderRequest) { | ||
if (!validBidReqs || !validBidReqs.length || !bidderRequest) { | ||
return; | ||
|
@@ -49,20 +57,33 @@ export const spec = { | |
logWarn(`Synacormedia: there is an invalid POS: ${bid.params.pos}`); | ||
pos = 0; | ||
} | ||
let videoOrBannerKey = this.isVideoBid(bid) ? 'video' : 'banner'; | ||
getAdUnitSizes(bid).forEach((size, i) => { | ||
let request = { | ||
id: bid.bidId + '~' + size[0] + 'x' + size[1], | ||
tagid: placementId, | ||
banner: { | ||
w: size[0], | ||
h: size[1], | ||
pos | ||
} | ||
if (!size || size.length != 2) { | ||
return; | ||
} | ||
let size0 = size[0]; | ||
let size1 = size[1]; | ||
let imp = { | ||
id: videoOrBannerKey.substring(0, 1) + bid.bidId + '-' + size0 + 'x' + size1, | ||
tagid: placementId | ||
}; | ||
if (bidFloor !== null && !isNaN(bidFloor)) { | ||
request.bidfloor = bidFloor; | ||
imp.bidfloor = bidFloor; | ||
} | ||
|
||
let videoOrBannerValue = { | ||
w: size0, | ||
h: size1, | ||
pos | ||
}; | ||
if (videoOrBannerKey === 'video' && bid.params.video) { | ||
Object.keys(bid.params.video) | ||
.filter(param => includes(VIDEO_PARAMS, param) && !isNaN(parseInt(bid.params.video[param], 10))) | ||
.forEach(param => videoOrBannerValue[param] = parseInt(bid.params.video[param], 10)); | ||
} | ||
openRtbBidRequest.imp.push(request); | ||
imp[videoOrBannerKey] = videoOrBannerValue; | ||
openRtbBidRequest.imp.push(imp); | ||
}); | ||
}); | ||
|
||
|
@@ -79,41 +100,43 @@ export const spec = { | |
} | ||
}, | ||
interpretResponse: function(serverResponse) { | ||
var updateMacros = (bid, r) => { | ||
return r ? r.replace(/\${AUCTION_PRICE}/g, parseFloat(bid.price)) : r; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
}; | ||
|
||
if (!serverResponse.body || typeof serverResponse.body != 'object') { | ||
logWarn('Synacormedia: server returned empty/non-json response: ' + JSON.stringify(serverResponse.body)); | ||
return; | ||
} | ||
|
||
const {id, seatbid: seatbids} = serverResponse.body; | ||
let bids = []; | ||
if (id && seatbids) { | ||
seatbids.forEach(seatbid => { | ||
seatbid.bid.forEach(bid => { | ||
let price = parseFloat(bid.price); | ||
let creative = bid.adm.replace(/\${([^}]*)}/g, (match, key) => { | ||
switch (key) { | ||
case 'AUCTION_SEAT_ID': return seatbid.seat; | ||
case 'AUCTION_ID': return id; | ||
case 'AUCTION_BID_ID': return bid.id; | ||
case 'AUCTION_IMP_ID': return bid.impid; | ||
case 'AUCTION_PRICE': return price; | ||
case 'AUCTION_CURRENCY': return 'USD'; | ||
} | ||
return match; | ||
}); | ||
let [, impid, width, height] = bid.impid.match(/^(.*)~(.*)x(.*)$/); | ||
bids.push({ | ||
let creative = updateMacros(bid, bid.adm); | ||
let nurl = updateMacros(bid, bid.nurl); | ||
let [, impType, impid, width, height] = bid.impid.match(/^([vb])(.*)-(.*)x(.*)$/); | ||
let isVideo = impType == 'v'; | ||
let bidObj = { | ||
requestId: impid, | ||
adId: bid.id.replace(/~/g, '-'), | ||
cpm: price, | ||
cpm: parseFloat(bid.price), | ||
width: parseInt(width, 10), | ||
height: parseInt(height, 10), | ||
creativeId: seatbid.seat + '~' + bid.crid, | ||
creativeId: seatbid.seat + '_' + bid.crid, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A template string could be used here: |
||
currency: 'USD', | ||
netRevenue: true, | ||
mediaType: BANNER, | ||
mediaType: (isVideo ? VIDEO : BANNER), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a recommendation, but you could simplify by removing the parens here: |
||
ad: creative, | ||
ttl: 60 | ||
}); | ||
}; | ||
if (isVideo) { | ||
let [, uuid] = nurl.match(/ID=([^&]*)&?/); | ||
bidObj.videoCacheKey = encodeURIComponent(uuid); | ||
bidObj.vastUrl = nurl; | ||
} | ||
bids.push(bidObj); | ||
}); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use template strings if possible in Prebid, so line 68 is changed to something like:
id: `
${videoOrBannerKey.substring(0,1)}${bid.bidId}-${size0}x${size1}
`