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

Kubient bid adapter. Added video support and honoring v5 requirements #7052

Closed
wants to merge 6 commits into from
Closed
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
143 changes: 143 additions & 0 deletions modules/kubientBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'kubient';
const END_POINT = 'https://kssp.kbntx.ch/kubprebidjs';
const VERSION = '1.1';
const VENDOR_ID = 794;
export const spec = {
code: BIDDER_CODE,
gvlid: VENDOR_ID,
supportedMediaTypes: [ BANNER, VIDEO ],
isBidRequestValid: function (bid) {
return !!(bid && bid.params);
},
buildRequests: function (validBidRequests, bidderRequest) {
if (!validBidRequests || !bidderRequest) {
return;
}
return validBidRequests.map(function (bid) {
let floor = 0.0;
if (typeof bid.getFloor === 'function') {
const mediaType = (Object.keys(bid.mediaTypes).length == 1) ? Object.keys(bid.mediaTypes)[0] : '*';
const sizes = bid.sizes || '*';
const floorInfo = bid.getFloor({currency: 'USD', mediaType: mediaType, size: sizes});
if (typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
}
}

let adSlot = {
bidId: bid.bidId,
zoneId: bid.params.zoneid || '',
floor: floor || 0.0
};

if (bid.mediaTypes.banner) {
adSlot.banner = bid.mediaTypes.banner;
}

if (bid.mediaTypes.video) {
adSlot.video = bid.mediaTypes.video;
}

if (bid.schain) {
adSlot.schain = bid.schain;
}

let data = {
v: VERSION,
requestId: bid.bidderRequestId,
adSlots: [adSlot],
tmax: bidderRequest.timeout,
gdpr: (bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) ? 1 : 0,
consentGiven: kubientGetConsentGiven(bidderRequest.gdprConsent),
uspConsent: bidderRequest.uspConsent
};

if (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) {
data.referer = bidderRequest.refererInfo.referer
}

if (bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) {
data.consent = bidderRequest.gdprConsent.consentString
}

return {
method: 'POST',
url: END_POINT,
data: JSON.stringify(data)
};
});
},
interpretResponse: function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body || !serverResponse.body.seatbid) {
return [];
}
let bidResponses = [];
serverResponse.body.seatbid.forEach(seatbid => {
let bids = seatbid.bid || [];
bids.forEach(bid => {
const bidResponse = {
requestId: bid.bidId,
cpm: bid.price,
currency: bid.cur,
width: bid.w,
height: bid.h,
creativeId: bid.creativeId,
netRevenue: bid.netRevenue,
ttl: bid.ttl,
ad: bid.adm,
meta: {}
};
if (bid.meta && bid.meta.adomain && utils.isArray(bid.meta.adomain)) {
bidResponse.meta.advertiserDomains = bid.meta.adomain;
}
bidResponses.push(bidResponse);
});
});
return bidResponses;
},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
let gdprParams = '';
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
gdprParams = `?consent_str=${gdprConsent.consentString}`;
if (typeof gdprConsent.gdprApplies === 'boolean') {
gdprParams = gdprParams + `&gdpr=${Number(gdprConsent.gdprApplies)}`;
}
gdprParams = gdprParams + `&consent_given=` + kubientGetConsentGiven(gdprConsent);
}
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://kdmp.kbntx.ch/init.html' + gdprParams
});
}
if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: 'https://kdmp.kbntx.ch/init.png' + gdprParams
});
}
return syncs;
}
};

function kubientGetConsentGiven(gdprConsent) {
let consentGiven = 0;
if (typeof gdprConsent !== 'undefined') {
let apiVersion = utils.deepAccess(gdprConsent, `apiVersion`);
switch (apiVersion) {
case 1:
consentGiven = utils.deepAccess(gdprConsent, `vendorData.vendorConsents.${VENDOR_ID}`) ? 1 : 0;
break;
case 2:
consentGiven = utils.deepAccess(gdprConsent, `vendorData.vendor.consents.${VENDOR_ID}`) ? 1 : 0;
break;
}
}
return consentGiven;
}
registerBidder(spec);
66 changes: 50 additions & 16 deletions modules/kubientBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,55 @@
# Description
Connects to Kubient KSSP demand source to fetch bids.
Connects to Kubient KSSP demand source to fetch bids. Banners and Video supported
# Test Parameters
# Banner Test Parameters
```
var adUnits = [{
code: 'banner-ad-div',
mediaTypes: {
banner: {
sizes: [[300, 250],[728, 90]],
}
},
bids: [{
"bidder": "kubient",
"params": {
"zoneid": "5fbb948f1e22b",
}
}]
}];
var adUnits = [
{
code: 'banner-ad-unit',
mediaTypes: {
banner: {
sizes: [[300, 100]]
}
},
bids: [{
bidder: 'kubient',
params: {
zoneid: "5fbb948f1e22b",
}
}]
}
];

# Video Test Parameters

var adUnits = [
{
code: 'video-ad-unit',
mediaTypes: {
video: {
playerSize: [300, 250], // required
context: 'instream', // required
mimes: ['video/mp4','video/x-flv'], // required
protocols: [ 2, 3 ], // required, set at least 1 value in array
placement: 1, // optional, defaults to 2 when context = outstream
api: [ 1, 2 ], // optional
skip: 0, // optional
minduration: 5, // optional
maxduration: 30, // optional
playbackmethod: [1,3], // optional
battr: [ 13, 14 ], // optional
linearity: 1, // optional
minbitrate: 10, // optional
maxbitrate: 10 // optional
}
},
bids: [{
bidder: 'kubient',
params: {
zoneid: "60ad1c0b35864",
}
}]
}
];
Loading