-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Lm_Kiviads Bid Adapter : initial adapter release #10415
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
430250f
new adapter - KiviAds
KiviAds 92cef83
add gpp, change tests, use bidderRequest instead of config.getConfig()
KiviAds 390beb6
Merge branch 'prebid:master' into master
KiviAds 2ffd46d
Update kiviadsBidAdapter_spec.js
patmmccann 28d7889
add new bid adapter
3f66183
update from main repo
aa4f3ae
Update lm_kiviadsBidAdapter: change placement -> pid according to ser…
KiviAds 1c5576e
fix aliases
KiviAds 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,206 @@ | ||
import {config} from '../src/config.js'; | ||
import {BANNER, VIDEO} from '../src/mediaTypes.js'; | ||
import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
import {getAdUnitSizes, parseSizesInput, isFn, deepAccess, getBidIdParameter, logError, isArray} from '../src/utils.js'; | ||
|
||
const CUR = 'USD'; | ||
const BIDDER_CODE = 'lm_kiviads'; | ||
const ENDPOINT = 'https://pbjs.kiviads.live'; | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {BidRequest} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
function isBidRequestValid(req) { | ||
if (req && typeof req.params !== 'object') { | ||
logError('Params is not defined or is incorrect in the bidder settings'); | ||
return false; | ||
} | ||
|
||
if (!getBidIdParameter('env', req.params) || !getBidIdParameter('pid', req.params)) { | ||
logError('Env or pid is not present in bidder params'); | ||
return false; | ||
} | ||
|
||
if (deepAccess(req, 'mediaTypes.video') && !isArray(deepAccess(req, 'mediaTypes.video.playerSize'))) { | ||
logError('mediaTypes.video.playerSize is required for video'); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {validBidRequest?pbjs_debug=trues[]} - an array of bids | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
function buildRequests(validBidRequests, bidderRequest) { | ||
const {refererInfo = {}, gdprConsent = {}, uspConsent} = bidderRequest; | ||
const requests = validBidRequests.map(req => { | ||
const request = {}; | ||
request.bidId = req.bidId; | ||
request.banner = deepAccess(req, 'mediaTypes.banner'); | ||
request.auctionId = req.ortb2?.source?.tid; | ||
request.transactionId = req.ortb2Imp?.ext?.tid; | ||
request.sizes = parseSizesInput(getAdUnitSizes(req)); | ||
request.schain = req.schain; | ||
request.location = { | ||
page: refererInfo.page, | ||
location: refererInfo.location, | ||
domain: refererInfo.domain, | ||
whost: window.location.host, | ||
ref: refererInfo.ref, | ||
isAmp: refererInfo.isAmp | ||
}; | ||
request.device = { | ||
ua: navigator.userAgent, | ||
lang: navigator.language | ||
}; | ||
request.env = { | ||
env: req.params.env, | ||
pid: req.params.pid | ||
}; | ||
request.ortb2 = req.ortb2; | ||
request.ortb2Imp = req.ortb2Imp; | ||
request.tz = new Date().getTimezoneOffset(); | ||
request.ext = req.params.ext; | ||
request.bc = req.bidRequestsCount; | ||
request.floor = getBidFloor(req); | ||
|
||
if (req.userIdAsEids && req.userIdAsEids.length !== 0) { | ||
request.userEids = req.userIdAsEids; | ||
} else { | ||
request.userEids = []; | ||
} | ||
if (gdprConsent.gdprApplies) { | ||
request.gdprApplies = Number(gdprConsent.gdprApplies); | ||
request.consentString = gdprConsent.consentString; | ||
} else { | ||
request.gdprApplies = 0; | ||
request.consentString = ''; | ||
} | ||
if (uspConsent) { | ||
request.usPrivacy = uspConsent; | ||
} else { | ||
request.usPrivacy = ''; | ||
} | ||
if (config.getConfig('coppa')) { | ||
request.coppa = 1; | ||
} else { | ||
request.coppa = 0; | ||
} | ||
|
||
const video = deepAccess(req, 'mediaTypes.video'); | ||
if (video) { | ||
request.sizes = parseSizesInput(deepAccess(req, 'mediaTypes.video.playerSize')); | ||
request.video = video; | ||
} | ||
|
||
return request; | ||
}); | ||
|
||
return { | ||
method: 'POST', | ||
url: ENDPOINT + '/bid', | ||
data: JSON.stringify(requests), | ||
withCredentials: true, | ||
bidderRequest, | ||
options: { | ||
contentType: 'application/json', | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
function interpretResponse(serverResponse, {bidderRequest}) { | ||
const response = []; | ||
if (!isArray(deepAccess(serverResponse, 'body.data'))) { | ||
return response; | ||
} | ||
|
||
serverResponse.body.data.forEach(serverBid => { | ||
const bid = { | ||
requestId: bidderRequest.bidId, | ||
dealId: bidderRequest.dealId || null, | ||
...serverBid | ||
}; | ||
response.push(bid); | ||
}); | ||
|
||
return response; | ||
} | ||
|
||
/** | ||
* Register the user sync pixels which should be dropped after the auction. | ||
* | ||
* @param {SyncOptions} syncOptions Which user syncs are allowed? | ||
* @param {ServerResponse[]} serverResponses List of server's responses. | ||
* @return {UserSync[]} The user syncs which should be dropped. | ||
*/ | ||
function getUserSyncs(syncOptions, serverResponses, gdprConsent = {}, uspConsent = '') { | ||
const syncs = []; | ||
const pixels = deepAccess(serverResponses, '0.body.data.0.ext.pixels'); | ||
|
||
if ((syncOptions.iframeEnabled || syncOptions.pixelEnabled) && isArray(pixels) && pixels.length !== 0) { | ||
const gdprFlag = `&gdpr=${gdprConsent.gdprApplies ? 1 : 0}`; | ||
const gdprString = `&gdpr_consent=${encodeURIComponent((gdprConsent.consentString || ''))}`; | ||
const usPrivacy = `us_privacy=${encodeURIComponent(uspConsent)}`; | ||
|
||
pixels.forEach(pixel => { | ||
const [type, url] = pixel; | ||
const sync = {type, url: `${url}&${usPrivacy}${gdprFlag}${gdprString}`}; | ||
if (type === 'iframe' && syncOptions.iframeEnabled) { | ||
syncs.push(sync) | ||
} else if (type === 'image' && syncOptions.pixelEnabled) { | ||
syncs.push(sync) | ||
} | ||
}); | ||
} | ||
|
||
return syncs; | ||
} | ||
|
||
/** | ||
* Get valid floor value from getFloor fuction. | ||
* | ||
* @param {Object} bid Current bid request. | ||
* @return {null|Number} Returns floor value when bid.getFloor is function and returns valid floor object with USD currency, otherwise returns null. | ||
*/ | ||
export function getBidFloor(bid) { | ||
if (!isFn(bid.getFloor)) { | ||
return null; | ||
} | ||
|
||
let floor = bid.getFloor({ | ||
currency: CUR, | ||
mediaType: '*', | ||
size: '*' | ||
}); | ||
|
||
if (typeof floor === 'object' && !isNaN(floor.floor) && floor.currency === CUR) { | ||
return floor.floor; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['kivi', 'kiviads'], | ||
supportedMediaTypes: [BANNER, VIDEO], | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
getUserSyncs | ||
} | ||
|
||
registerBidder(spec); |
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,54 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: lm_kiviads Bidder Adapter | ||
Module Type: lm_kiviads Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to kiviads.com demand sources | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-banner', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'lm_kiviads', | ||
params: { | ||
env: 'lm_kiviads', | ||
pid: '40', | ||
ext: {} | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'test-video', | ||
sizes: [ [ 640, 480 ] ], | ||
mediaTypes: { | ||
video: { | ||
playerSize: [640, 480], | ||
context: 'instream', | ||
skipppable: true | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'lm_kiviads', | ||
params: { | ||
env: 'lm_kiviads', | ||
pid: '40', | ||
ext: {} | ||
} | ||
}] | ||
} | ||
]; | ||
``` |
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.
aliases should be unique for the first 6 characters. There is already another another adapter with a bidder code named:
kiviads
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.
@lksharma, thanks for the information. The mistake has been fixed