Skip to content
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
merged 9 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 67 additions & 56 deletions modules/seedtagBidAdapter.js
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',
];
Comment on lines +10 to +15
Copy link
Contributor Author

@ybootin ybootin Nov 17, 2022

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 use banner mediaType)


// 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;
}
};

Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when publisher use video mediatype, it must have context:instream and also have bidder params placement: inStream

);
}

function buildBidRequest(validBidRequest) {
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -208,8 +219,8 @@ export const spec = {
*/
isBidRequestValid(bid) {
return hasVideoMediaType(bid)
? hasMandatoryParams(bid.params) && hasMandatoryVideoParams(bid)
: hasMandatoryParams(bid.params);
? hasMandatoryVideoParams(bid)
: hasMandatoryDisplayParams(bid);
},

/**
Expand Down Expand Up @@ -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,
};
},

/**
Expand Down Expand Up @@ -308,6 +319,6 @@ export const spec = {
if (bid && bid.nurl) {
triggerPixel(bid.nurl);
}
}
}
},
};
registerBidder(spec);
60 changes: 60 additions & 0 deletions modules/seedtagBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,63 @@ const adUnits = [
}
]
```

## InBanner
```js
const adUnits = [
{
code: '/21804003197/prebid_test_300x250',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: 'seedtag',
params: {
publisherId: '0000-0000-01', // required
adUnitId: '0000', // required
placement: 'inBanner', // required
}
}
]
}
]
```

## inStream Video
```js
var adUnits = [{
code: 'video',
mediaTypes: {
video: {
context: 'instream', // required
playerSize: [640, 360], // required
// Video object as specified in OpenRTB 2.5
mimes: ['video/mp4'], // recommended
minduration: 5, // optional
maxduration: 60, // optional
boxingallowed: 1, // optional
skip: 1, // optional
startdelay: 1, // optional
linearity: 1, // optional
battr: [1, 2], // optional
maxbitrate: 10, // optional
playbackmethod: [1], // optional
delivery: [1], // optional
placement: 1, // optional
}
},
bids: [
{
bidder: 'seedtag',
params: {
publisherId: '0000-0000-01', // required
adUnitId: '0000', // required
placement: 'inStream', // required
}
}
]
}];
```
Loading