-
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
videoNow bid adapter #4088
Merged
Merged
videoNow bid adapter #4088
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
68717af
-- first commit
sdbaron e49d26a
-- cors and bidder's name fixed
sdbaron 1654ea5
-- almost ready
sdbaron 8137975
-- added docs
sdbaron ed28e3c
-- added nurl tracking
sdbaron d3d8462
-- bid params
sdbaron 56b0d23
-- tests added
sdbaron c31fbb1
-- test fixed
sdbaron 7d1d694
Merge branch 'videoNowAdapter'
sdbaron 615c3f3
-- replace placeholder in the onBidWon pixel's url
sdbaron 4142f07
-- commit for restart tests
sdbaron 36ce34a
-- change response data format for display ad
sdbaron 7310341
-- tests updated
sdbaron 4c659f6
-- 100% tests coverage
sdbaron a786ef5
-- a few clean the test's code
sdbaron 11f54ac
-- custom urls from localStorage
sdbaron 77691e5
-- tests updated
sdbaron 833cc86
-- a few clean the test's code
sdbaron 0f8c673
-- new init model
sdbaron dea7e2d
-- spec for new init model
sdbaron fbbd777
-- fix for new init model
sdbaron 62811b7
-- code cleaned
sdbaron a4d0bfd
-- 100% tests coverage
sdbaron 53a3b95
-- 100% tests coverage
sdbaron 1fe97ef
Merge remote-tracking branch 'upstream/master'
sdbaron 779fa64
Merge branch 'newResponseFormat'
sdbaron f7b2e2c
Merge remote-tracking branch 'upstream/master'
sdbaron 5801534
-- fixed test
sdbaron 3c1f76f
-- commit for restart tests
sdbaron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
import * as utils from '../src/utils'; | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
import { BANNER } from '../src/mediaTypes' | ||
|
||
const RTB_URL = 'https://bidder.videonow.ru/prebid' | ||
|
||
const BIDDER_CODE = 'videonow' | ||
const TTL_SECONDS = 60 * 5; | ||
|
||
function isBidRequestValid(bid) { | ||
const { params } = bid || {} | ||
return !!(params.pId); | ||
} | ||
|
||
function buildRequest(bid, bidderRequest) { | ||
const { refererInfo } = bidderRequest | ||
const { ext, bidId, params, code, sizes } = bid; | ||
const { pId, bidFloor, cur, placementId, url: rtbUrl } = params || {} | ||
|
||
let url = rtbUrl || RTB_URL | ||
url = `${url}${~url.indexOf('?') ? '&' : '?'}profile_id=${pId}` | ||
|
||
const dto = { | ||
method: 'POST', | ||
url, | ||
data: { | ||
id: bidId, | ||
cpm: bidFloor, | ||
code, | ||
sizes, | ||
cur: cur || 'RUB', | ||
placementId, | ||
ref: refererInfo && refererInfo.referer | ||
} | ||
} | ||
|
||
ext && Object.keys(ext).forEach(key => { | ||
dto[`ext_${key}`] = ext.key | ||
}) | ||
|
||
return dto; | ||
} | ||
|
||
function buildRequests(validBidRequests, bidderRequest) { | ||
utils.logInfo(`${BIDDER_CODE}. buildRequests`) | ||
const requests = []; | ||
validBidRequests.forEach(validBidRequest => { | ||
const request = buildRequest(validBidRequest, bidderRequest); | ||
request && requests.push(request); | ||
}); | ||
return requests; | ||
} | ||
|
||
function interpretResponse(serverResponse, bidRequest) { | ||
if (!serverResponse || !serverResponse.body) { | ||
return []; | ||
} | ||
const { id: bidId } = (bidRequest && bidRequest.data) || {} | ||
if (!bidId) return [] | ||
|
||
const { seatbid, cur, ext } = serverResponse.body; | ||
if (!seatbid || !seatbid.length) return [] | ||
|
||
const { placementId } = ext || {} | ||
if (!placementId) return [] | ||
|
||
const bids = [] | ||
seatbid.forEach(sb => { | ||
const { bid } = sb | ||
if (bid && bid.length) { | ||
bid.forEach(b => { | ||
const res = createResponseBid(b, bidId, cur, placementId) | ||
res && bids.push(res) | ||
}) | ||
} | ||
}) | ||
|
||
return bids | ||
} | ||
|
||
function createResponseBid(bidInfo, bidId, cur, placementId) { | ||
const { id, nurl, code, price, crid, adm, ttl, netRevenue, w, h } = bidInfo | ||
|
||
if (!id || !price) { | ||
return null; | ||
} | ||
|
||
if (!adm) { | ||
utils.logError(`${BIDDER_CODE}. adm not exists in the response`) | ||
return null | ||
} | ||
|
||
try { | ||
return { | ||
requestId: bidId, | ||
cpm: price, | ||
width: w, | ||
height: h, | ||
creativeId: crid, | ||
currency: cur || 'RUB', | ||
netRevenue: netRevenue !== undefined ? netRevenue : true, | ||
ttl: ttl || TTL_SECONDS, | ||
ad: code, | ||
nurl, | ||
renderer: { | ||
url: nurl, | ||
render: function() { | ||
const d = window.document | ||
const el = placementId && d.getElementById(placementId) | ||
if (!el) { | ||
console.error(`bidAdapter ${BIDDER_CODE}: ${placementId} not found`) | ||
} | ||
|
||
el.innerHTML = adm | ||
reInitScripts(el) | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
return null | ||
} | ||
} | ||
|
||
function getUserSyncs(syncOptions, serverResponses) { | ||
const syncs = [] | ||
|
||
if (!serverResponses || !serverResponses.length) return syncs | ||
|
||
serverResponses.forEach(response => { | ||
const {ext} = (response && response.body) || {} | ||
const {pixels, iframes} = ext || {} | ||
|
||
if (syncOptions.iframeEnabled && iframes && iframes.length) { | ||
iframes.forEach(i => syncs.push({ | ||
type: 'iframe', | ||
url: i | ||
}) | ||
) | ||
} | ||
|
||
if (syncOptions.pixelEnabled && pixels && pixels.length) { | ||
pixels.forEach(p => syncs.push({ | ||
type: 'image', | ||
url: p | ||
}) | ||
) | ||
} | ||
}) | ||
|
||
utils.logInfo(`${BIDDER_CODE} getUserSyncs() syncs=${syncs.length}`) | ||
return syncs | ||
} | ||
|
||
function onBidWon(bid) { | ||
const { nurl } = bid | ||
if (nurl) { | ||
const img = document.createElement('img') | ||
img.src = nurl | ||
img.style.cssText = 'display:none !important;' | ||
document.body.appendChild(img) | ||
} | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
getUserSyncs, | ||
onTimeout: function(timeoutData) {}, | ||
onBidWon | ||
} | ||
|
||
registerBidder(spec); | ||
|
||
function reInitScripts(container, shouldReInitInlineScripts = true, delay = 10) { | ||
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. Can you please explain what does this function do and why do we need it in the adapter? |
||
const oldScripts = container.querySelectorAll('script') | ||
const innerScriptsInsertActions = [] | ||
|
||
oldScripts && oldScripts.length && Array.from(oldScripts).forEach(oldScr => { | ||
const { parentNode } = oldScr | ||
const scriptElement = document.createElement('script') | ||
oldScr.attributes && Array.from(oldScr.attributes).forEach(attr => { | ||
scriptElement.setAttribute(attr.name, attr.value) | ||
}) | ||
|
||
if (oldScr.src) { | ||
innerScriptsInsertActions.push(() => { | ||
((function(parent, scriptElm, src) { | ||
scriptElm.src = src | ||
parent.appendChild(scriptElm) | ||
})(parentNode, scriptElement, oldScr.src)) | ||
}) | ||
} | ||
|
||
if (oldScr.innerHTML && shouldReInitInlineScripts) { | ||
innerScriptsInsertActions.push(() => { | ||
((function(parent, scriptElm, scriptText) { | ||
scriptElm.innerHTML = scriptText | ||
parent.appendChild(scriptElm) | ||
})(parentNode, scriptElement, oldScr.innerHTML)) | ||
}) | ||
} | ||
parentNode.removeChild(oldScr) | ||
}) | ||
|
||
innerScriptsInsertActions.length && setTimeout(() => { | ||
innerScriptsInsertActions.forEach(si => si()) | ||
}, delay) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Videonow Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: info@videonow.ru | ||
``` | ||
|
||
# Description | ||
|
||
Connect to Videonow for bids. | ||
|
||
The Videonow bidder adapter requires setup and approval from the videoNow team. | ||
Please reach out to your account team or info@videonow.ru for more information. | ||
|
||
# Test Parameters | ||
```javascript | ||
var adUnits = [ | ||
// Banner adUnit | ||
{ | ||
code: 'banner-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[640, 480], [300, 250], [336, 280]] | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'videonow', | ||
params: { | ||
pId: 1, | ||
placementId: '36891' | ||
} | ||
}] | ||
}] | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we use
utils.logError()
here?