-
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
Seedtag Bid Adapter : add support for inBanner and inStream #9230
Merged
Rothalack
merged 9 commits into
prebid:master
from
seedtag:seedtag/inBanner-inStream-support
Nov 28, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eaae059
use inBanner and inStream for video
ybootin 911d906
remove duplicate video params, now use only params from adunit level
ybootin 9c57b6b
lint
ybootin 0cc1bf6
improve unit test
ybootin 763502e
fix adapter for instream support, and fix unit test
ybootin a9266fc
use inStream placement for instream context
ybootin 40b1677
use ALLOWED_DISPLAY_PLACEMENTS
ybootin be8220c
fix lint error
ybootin edb855d
empty commit to relaunch CI
ybootin 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 |
---|---|---|
@@ -1,47 +1,52 @@ | ||
import { isArray, _map, triggerPixel } from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js' | ||
import { VIDEO, BANNER } from '../src/mediaTypes.js' | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { VIDEO, BANNER } from '../src/mediaTypes.js'; | ||
import { config } from '../src/config.js'; | ||
|
||
const BIDDER_CODE = 'seedtag'; | ||
const SEEDTAG_ALIAS = 'st'; | ||
const SEEDTAG_SSP_ENDPOINT = 'https://s.seedtag.com/c/hb/bid'; | ||
const SEEDTAG_SSP_ONTIMEOUT_ENDPOINT = 'https://s.seedtag.com/se/hb/timeout'; | ||
const ALLOWED_PLACEMENTS = { | ||
inImage: true, | ||
inScreen: true, | ||
inArticle: true, | ||
banner: true, | ||
video: true | ||
} | ||
const ALLOWED_DISPLAY_PLACEMENTS = [ | ||
'inScreen', | ||
'inImage', | ||
'inArticle', | ||
'inBanner', | ||
]; | ||
|
||
// Global Vendor List Id | ||
// https://iabeurope.eu/vendor-list-tcf-v2-0/ | ||
const GVLID = 157; | ||
|
||
const mediaTypesMap = { | ||
[BANNER]: 'display', | ||
[VIDEO]: 'video' | ||
[VIDEO]: 'video', | ||
}; | ||
|
||
const deviceConnection = { | ||
FIXED: 'fixed', | ||
MOBILE: 'mobile', | ||
UNKNOWN: 'unknown' | ||
UNKNOWN: 'unknown', | ||
}; | ||
|
||
const getConnectionType = () => { | ||
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection || {} | ||
const connection = | ||
navigator.connection || | ||
navigator.mozConnection || | ||
navigator.webkitConnection || | ||
{}; | ||
switch (connection.type || connection.effectiveType) { | ||
case 'wifi': | ||
case 'ethernet': | ||
return deviceConnection.FIXED | ||
return deviceConnection.FIXED; | ||
case 'cellular': | ||
case 'wimax': | ||
return deviceConnection.MOBILE | ||
return deviceConnection.MOBILE; | ||
default: | ||
const isMobile = /iPad|iPhone|iPod/.test(navigator.userAgent) || /android/i.test(navigator.userAgent) | ||
return isMobile ? deviceConnection.UNKNOWN : deviceConnection.FIXED | ||
const isMobile = | ||
/iPad|iPhone|iPod/.test(navigator.userAgent) || | ||
/android/i.test(navigator.userAgent); | ||
return isMobile ? deviceConnection.UNKNOWN : deviceConnection.FIXED; | ||
} | ||
}; | ||
|
||
|
@@ -52,24 +57,32 @@ function mapMediaType(seedtagMediaType) { | |
} | ||
|
||
function hasVideoMediaType(bid) { | ||
return (!!bid.mediaTypes && !!bid.mediaTypes.video) || (!!bid.params && !!bid.params.video) | ||
return !!bid.mediaTypes && !!bid.mediaTypes.video; | ||
} | ||
|
||
function hasMandatoryParams(params) { | ||
function hasMandatoryDisplayParams(bid) { | ||
const p = bid.params; | ||
return ( | ||
!!params.publisherId && | ||
!!params.adUnitId && | ||
!!params.placement && | ||
!!ALLOWED_PLACEMENTS[params.placement] | ||
!!p.publisherId && | ||
!!p.adUnitId && | ||
ALLOWED_DISPLAY_PLACEMENTS.indexOf(p.placement) > -1 | ||
); | ||
} | ||
|
||
function hasMandatoryVideoParams(bid) { | ||
const videoParams = getVideoParams(bid) | ||
const videoParams = getVideoParams(bid); | ||
|
||
return hasVideoMediaType(bid) && !!videoParams.playerSize && | ||
return ( | ||
!!bid.params.publisherId && | ||
!!bid.params.adUnitId && | ||
hasVideoMediaType(bid) && | ||
!!videoParams.playerSize && | ||
isArray(videoParams.playerSize) && | ||
videoParams.playerSize.length > 0; | ||
videoParams.playerSize.length > 0 && | ||
// only instream is supported for video | ||
videoParams.context === 'instream' && | ||
bid.params.placement === 'inStream' | ||
Comment on lines
+76
to
+84
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. when publisher use |
||
); | ||
} | ||
|
||
function buildBidRequest(validBidRequest) { | ||
|
@@ -89,15 +102,11 @@ function buildBidRequest(validBidRequest) { | |
adUnitId: params.adUnitId, | ||
adUnitCode: validBidRequest.adUnitCode, | ||
placement: params.placement, | ||
requestCount: validBidRequest.bidderRequestsCount || 1 // FIXME : in unit test the parameter bidderRequestsCount is undefined | ||
requestCount: validBidRequest.bidderRequestsCount || 1, // FIXME : in unit test the parameter bidderRequestsCount is undefined | ||
}; | ||
|
||
if (params.adPosition) { | ||
bidRequest.adPosition = params.adPosition; | ||
} | ||
|
||
if (hasVideoMediaType(validBidRequest)) { | ||
bidRequest.videoParams = getVideoParams(validBidRequest) | ||
bidRequest.videoParams = getVideoParams(validBidRequest); | ||
} | ||
|
||
return bidRequest; | ||
|
@@ -113,13 +122,7 @@ function getVideoParams(validBidRequest) { | |
videoParams.h = videoParams.playerSize[0][1]; | ||
} | ||
|
||
const bidderVideoParams = (validBidRequest.params && validBidRequest.params.video) || {} | ||
// override video params from seedtag bidder params | ||
Object.keys(bidderVideoParams).forEach(key => { | ||
videoParams[key] = validBidRequest.params.video[key] | ||
}) | ||
|
||
return videoParams | ||
return videoParams; | ||
} | ||
|
||
function buildBidResponse(seedtagBid) { | ||
|
@@ -136,8 +139,11 @@ function buildBidResponse(seedtagBid) { | |
ttl: seedtagBid.ttl, | ||
nurl: seedtagBid.nurl, | ||
meta: { | ||
advertiserDomains: seedtagBid && seedtagBid.adomain && seedtagBid.adomain.length > 0 ? seedtagBid.adomain : [] | ||
} | ||
advertiserDomains: | ||
seedtagBid && seedtagBid.adomain && seedtagBid.adomain.length > 0 | ||
? seedtagBid.adomain | ||
: [], | ||
}, | ||
}; | ||
|
||
if (mediaType === VIDEO) { | ||
|
@@ -181,16 +187,21 @@ function ttfb() { | |
export function getTimeoutUrl(data) { | ||
let queryParams = ''; | ||
if ( | ||
isArray(data) && data[0] && | ||
isArray(data[0].params) && data[0].params[0] | ||
isArray(data) && | ||
data[0] && | ||
isArray(data[0].params) && | ||
data[0].params[0] | ||
) { | ||
const params = data[0].params[0]; | ||
const timeout = data[0].timeout | ||
const timeout = data[0].timeout; | ||
|
||
queryParams = | ||
'?publisherToken=' + params.publisherId + | ||
'&adUnitId=' + params.adUnitId + | ||
'&timeout=' + timeout; | ||
'?publisherToken=' + | ||
params.publisherId + | ||
'&adUnitId=' + | ||
params.adUnitId + | ||
'&timeout=' + | ||
timeout; | ||
} | ||
return SEEDTAG_SSP_ONTIMEOUT_ENDPOINT + queryParams; | ||
} | ||
|
@@ -208,8 +219,8 @@ export const spec = { | |
*/ | ||
isBidRequestValid(bid) { | ||
return hasVideoMediaType(bid) | ||
? hasMandatoryParams(bid.params) && hasMandatoryVideoParams(bid) | ||
: hasMandatoryParams(bid.params); | ||
? hasMandatoryVideoParams(bid) | ||
: hasMandatoryDisplayParams(bid); | ||
}, | ||
|
||
/** | ||
|
@@ -237,24 +248,24 @@ export const spec = { | |
payload['cd'] = bidderRequest.gdprConsent.consentString; | ||
} | ||
if (bidderRequest.uspConsent) { | ||
payload['uspConsent'] = bidderRequest.uspConsent | ||
payload['uspConsent'] = bidderRequest.uspConsent; | ||
} | ||
|
||
if (validBidRequests[0].schain) { | ||
payload.schain = validBidRequests[0].schain; | ||
} | ||
|
||
let coppa = config.getConfig('coppa') | ||
let coppa = config.getConfig('coppa'); | ||
if (coppa) { | ||
payload.coppa = coppa | ||
payload.coppa = coppa; | ||
} | ||
|
||
const payloadString = JSON.stringify(payload) | ||
const payloadString = JSON.stringify(payload); | ||
return { | ||
method: 'POST', | ||
url: SEEDTAG_SSP_ENDPOINT, | ||
data: payloadString | ||
} | ||
data: payloadString, | ||
}; | ||
}, | ||
|
||
/** | ||
|
@@ -308,6 +319,6 @@ export const spec = { | |
if (bid && bid.nurl) { | ||
triggerPixel(bid.nurl); | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
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
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.
Update available placement for
display
creative (when usebanner
mediaType)