Skip to content

Commit

Permalink
Merge pull request #1 from prebid/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
pro-nsk authored Nov 15, 2021
2 parents 2e2fdd8 + 51f9244 commit 10ae6ca
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 83 deletions.
24 changes: 15 additions & 9 deletions modules/invibesBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ function isBidRequestValid(bid) {
function buildRequest(bidRequests, bidderRequest) {
bidderRequest = bidderRequest || {};
const _placementIds = [];
const _adUnitCodes = [];
let _loginId, _customEndpoint, _userId;
let _ivAuctionStart = bidderRequest.auctionStart || Date.now();

bidRequests.forEach(function (bidRequest) {
bidRequest.startTime = new Date().getTime();
_placementIds.push(bidRequest.params.placementId);
_adUnitCodes.push(bidRequest.adUnitCode);
_loginId = _loginId || bidRequest.params.loginId;
_customEndpoint = _customEndpoint || bidRequest.params.customEndpoint;
_customUserSync = _customUserSync || bidRequest.params.customUserSync;
Expand All @@ -99,6 +101,7 @@ function buildRequest(bidRequests, bidderRequest) {
let userIdModel = getUserIds(_userId);
let bidParamsJson = {
placementIds: _placementIds,
adUnitCodes: _adUnitCodes,
loginId: _loginId,
auctionStartTime: _ivAuctionStart,
bidVersion: CONSTANTS.PREBID_VERSION
Expand Down Expand Up @@ -181,41 +184,44 @@ function handleResponse(responseObj, bidRequests) {
const bidResponses = [];
for (let i = 0; i < bidRequests.length; i++) {
let bidRequest = bidRequests[i];
let usedPlacementId = responseObj.UseAdUnitCode === true
? bidRequest.params.placementId + '_' + bidRequest.adUnitCode
: bidRequest.params.placementId;

if (invibes.placementBids.indexOf(bidRequest.params.placementId) > -1) {
logInfo('Invibes Adapter - Placement was previously bid on ' + bidRequest.params.placementId);
if (invibes.placementBids.indexOf(usedPlacementId) > -1) {
logInfo('Invibes Adapter - Placement was previously bid on ' + usedPlacementId);
continue;
}

let requestPlacement = null;
if (responseObj.AdPlacements != null) {
for (let j = 0; j < responseObj.AdPlacements.length; j++) {
let bidModel = responseObj.AdPlacements[j].BidModel;
if (bidModel != null && bidModel.PlacementId == bidRequest.params.placementId) {
if (bidModel != null && bidModel.PlacementId == usedPlacementId) {
requestPlacement = responseObj.AdPlacements[j];
break;
}
}
} else {
let bidModel = responseObj.BidModel;
if (bidModel != null && bidModel.PlacementId == bidRequest.params.placementId) {
if (bidModel != null && bidModel.PlacementId == usedPlacementId) {
requestPlacement = responseObj;
}
}

let bid = createBid(bidRequest, requestPlacement, responseObj.MultipositionEnabled);
let bid = createBid(bidRequest, requestPlacement, responseObj.MultipositionEnabled, usedPlacementId);
if (bid !== null) {
invibes.placementBids.push(bidRequest.params.placementId);
invibes.placementBids.push(usedPlacementId);
bidResponses.push(bid);
}
}

return bidResponses;
}

function createBid(bidRequest, requestPlacement, multipositionEnabled) {
function createBid(bidRequest, requestPlacement, multipositionEnabled, usedPlacementId) {
if (requestPlacement === null || requestPlacement.BidModel === null) {
logInfo('Invibes Adapter - Placement not configured for bidding ' + bidRequest.params.placementId);
logInfo('Invibes Adapter - Placement not configured for bidding ' + usedPlacementId);
return null;
}

Expand Down Expand Up @@ -684,7 +690,7 @@ let keywords = (function () {
return kw;
}());

// =====================
// ======================

export function resetInvibes() {
invibes.optIn = undefined;
Expand Down
6 changes: 3 additions & 3 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,10 @@ function _handleEids(payload, validBidRequests) {

function _checkMediaType(bid, newBid) {
// Create a regex here to check the strings
if (bid.ext && bid.ext['BidType'] != undefined) {
newBid.mediaType = MEDIATYPE[bid.ext.BidType];
if (bid.ext && bid.ext['bidtype'] != undefined) {
newBid.mediaType = MEDIATYPE[bid.ext.bidtype];
} else {
logInfo(LOG_WARN_PREFIX + 'bid.ext.BidType does not exist, checking alternatively for mediaType')
logInfo(LOG_WARN_PREFIX + 'bid.ext.bidtype does not exist, checking alternatively for mediaType')
var adm = bid.adm;
var admStr = '';
var videoRegex = new RegExp(/VAST\s+version/);
Expand Down
18 changes: 17 additions & 1 deletion modules/smartxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,20 @@ export const spec = {
domain: domain,
publisher: {
id: publisherId
},
content: {
ext: {
prebid: {
name: 'pbjs',
version: '$prebid.version$'
}
}
}
},
device: device,
at: at,
cur: cur
cur: cur,
ext: {}
};

const userExt = {};
Expand Down Expand Up @@ -194,6 +203,8 @@ export const spec = {
};
}

// requestPayload.user.ext.ver = pbjs.version;

// Targeting
if (getBidIdParameter('data', bid.params.user)) {
var targetingarr = [];
Expand Down Expand Up @@ -336,6 +347,7 @@ function createOutstreamConfig(bid) {
let confTitle = getBidIdParameter('title', bid.renderer.config.outstream_options);
let confSkipOffset = getBidIdParameter('skipOffset', bid.renderer.config.outstream_options);
let confDesiredBitrate = getBidIdParameter('desiredBitrate', bid.renderer.config.outstream_options);
let confVisibilityThreshold = getBidIdParameter('visibilityThreshold', bid.renderer.config.outstream_options);
let elementId = getBidIdParameter('slot', bid.renderer.config.outstream_options) || bid.adUnitCode;

logMessage('[SMARTX][renderer] Handle SmartX outstream renderer');
Expand Down Expand Up @@ -384,6 +396,10 @@ function createOutstreamConfig(bid) {
smartPlayObj.desiredBitrate = confDesiredBitrate;
}

if (confVisibilityThreshold) {
smartPlayObj.visibilityThreshold = confVisibilityThreshold;
}

smartPlayObj.adResponse = bid.vastContent;

const divID = '[id="' + elementId + '"]';
Expand Down
9 changes: 8 additions & 1 deletion modules/undertoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,16 @@ export const spec = {
'commons': commons
};
const referer = bidderRequest.refererInfo.referer;
const canonicalUrl = getCanonicalUrl();
if (referer) {
commons.referrer = referer;
}
if (canonicalUrl) {
commons.canonicalUrl = canonicalUrl;
}
const hostname = parseUrl(referer).hostname;
let domain = extractDomainFromHost(hostname);
const pageUrl = getCanonicalUrl() || referer;
const pageUrl = canonicalUrl || referer;

const pubid = validBidRequests[0].params.publisherId;
let reqUrl = `${URL}?pid=${pubid}&domain=${domain}`;
Expand Down
126 changes: 115 additions & 11 deletions modules/yieldoneBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepAccess, isEmpty, parseSizesInput, isStr, logWarn } from '../src/utils.js';
import {deepAccess, isEmpty, isStr, logWarn, parseSizesInput} from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
Expand All @@ -11,6 +11,8 @@ const VIDEO_PLAYER_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/d
const CMER_PLAYER_URL = 'https://an.cmertv.com/hb/renderer/cmertv-video-yone-prebid.min.js';
const VIEWABLE_PERCENTAGE_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/prebid-adformat-config.js';

const DEFAULT_VIDEO_SIZE = {w: 640, h: 360};

export const spec = {
code: BIDDER_CODE,
aliases: ['y1'],
Expand Down Expand Up @@ -40,16 +42,18 @@ export const spec = {
t: 'i'
};

const videoMediaType = deepAccess(bidRequest, 'mediaTypes.video');
if ((isEmpty(bidRequest.mediaType) && isEmpty(bidRequest.mediaTypes)) ||
(bidRequest.mediaType === BANNER || (bidRequest.mediaTypes && bidRequest.mediaTypes[BANNER]))) {
const sizes = deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes;
payload.sz = parseSizesInput(sizes).join(',');
} else if (bidRequest.mediaType === VIDEO || videoMediaType) {
const sizes = deepAccess(bidRequest, 'mediaTypes.video.playerSize') || bidRequest.sizes;
const size = parseSizesInput(sizes)[0];
payload.w = size.split('x')[0];
payload.h = size.split('x')[1];
const mediaType = getMediaType(bidRequest);
switch (mediaType) {
case BANNER:
payload.sz = getBannerSizes(bidRequest);
break;
case VIDEO:
const videoSize = getVideoSize(bidRequest);
payload.w = videoSize.w;
payload.h = videoSize.h;
break;
default:
break;
}

// LiveRampID
Expand Down Expand Up @@ -167,6 +171,106 @@ export const spec = {
},
}

/**
* NOTE: server side does not yet support multiple formats.
* @param {Object} bidRequest -
* @param {boolean} [enabledOldFormat = true] - default: `true`.
* @return {string|null} - `"banner"` or `"video"` or `null`.
*/
function getMediaType(bidRequest, enabledOldFormat = true) {
let hasBannerType = Boolean(deepAccess(bidRequest, 'mediaTypes.banner'));
let hasVideoType = Boolean(deepAccess(bidRequest, 'mediaTypes.video'));

if (enabledOldFormat) {
hasBannerType = hasBannerType || bidRequest.mediaType === BANNER ||
(isEmpty(bidRequest.mediaTypes) && isEmpty(bidRequest.mediaType));
hasVideoType = hasVideoType || bidRequest.mediaType === VIDEO;
}

if (hasBannerType && hasVideoType) {
const playerParams = deepAccess(bidRequest, 'params.playerParams')
if (playerParams) {
return VIDEO;
} else {
return BANNER;
}
} else if (hasBannerType) {
return BANNER;
} else if (hasVideoType) {
return VIDEO;
}

return null;
}

/**
* NOTE:
* If `mediaTypes.banner` exists, then `mediaTypes.banner.sizes` must also exist.
* The reason for this is that Prebid.js will perform the verification and
* if `mediaTypes.banner.sizes` is inappropriate, it will delete the entire `mediaTypes.banner`.
* @param {Object} bidRequest -
* @param {Object} bidRequest.banner -
* @param {Array<string>} bidRequest.banner.sizes -
* @param {boolean} [enabledOldFormat = true] - default: `true`.
* @return {string} - strings like `"300x250"` or `"300x250,728x90"`.
*/
function getBannerSizes(bidRequest, enabledOldFormat = true) {
let sizes = deepAccess(bidRequest, 'mediaTypes.banner.sizes');

if (enabledOldFormat) {
sizes = sizes || bidRequest.sizes;
}

return parseSizesInput(sizes).join(',');
}

/**
* @param {Object} bidRequest -
* @param {boolean} [enabledOldFormat = true] - default: `true`.
* @param {boolean} [enabledFlux = true] - default: `true`.
* @return {{w: number, h: number}} -
*/
function getVideoSize(bidRequest, enabledOldFormat = true, enabledFlux = true) {
/**
* @param {Array<number, number> | Array<Array<number, number>>} sizes -
* @return {{w: number, h: number} | null} -
*/
const _getPlayerSize = (sizes) => {
let result = null;

const size = parseSizesInput(sizes)[0];
if (isEmpty(size)) {
return result;
}

const splited = size.split('x');
const sizeObj = {w: parseInt(splited[0], 10), h: parseInt(splited[1], 10)};
const _isValidPlayerSize = !(isEmpty(sizeObj)) && (isFinite(sizeObj.w) && isFinite(sizeObj.h));
if (!_isValidPlayerSize) {
return result;
}

result = sizeObj;
return result;
}

let playerSize = _getPlayerSize(deepAccess(bidRequest, 'mediaTypes.video.playerSize'));

if (enabledOldFormat) {
playerSize = playerSize || _getPlayerSize(bidRequest.sizes);
}

if (enabledFlux) {
// NOTE: `video.playerSize` in Flux is always [1,1].
if (playerSize && (playerSize.w === 1 && playerSize.h === 1)) {
// NOTE: `params.playerSize` is a specific object to support `FLUX`.
playerSize = _getPlayerSize(deepAccess(bidRequest, 'params.playerSize'));
}
}

return playerSize || DEFAULT_VIDEO_SIZE;
}

function newRenderer(response) {
const renderer = Renderer.install({
id: response.uid,
Expand Down
33 changes: 29 additions & 4 deletions test/spec/modules/invibesBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('invibesBidAdapter:', function () {
params: {
placementId: PLACEMENT_ID
},
adUnitCode: 'test-div',
adUnitCode: 'test-div1',
auctionId: 'a1',
sizes: [
[300, 250],
Expand All @@ -30,7 +30,7 @@ describe('invibesBidAdapter:', function () {
params: {
placementId: 'abcde'
},
adUnitCode: 'test-div',
adUnitCode: 'test-div2',
auctionId: 'a2',
sizes: [
[300, 250],
Expand All @@ -48,7 +48,7 @@ describe('invibesBidAdapter:', function () {
params: {
placementId: PLACEMENT_ID
},
adUnitCode: 'test-div',
adUnitCode: 'test-div1',
auctionId: 'a1',
sizes: [
[300, 250],
Expand All @@ -67,7 +67,7 @@ describe('invibesBidAdapter:', function () {
params: {
placementId: 'abcde'
},
adUnitCode: 'test-div',
adUnitCode: 'test-div2',
auctionId: 'a2',
sizes: [
[300, 250],
Expand Down Expand Up @@ -223,6 +223,12 @@ describe('invibesBidAdapter:', function () {
expect(JSON.parse(request.data.bidParamsJson).placementIds).to.contain(bidRequests[1].params.placementId);
});

it('sends all adUnitCodes', function () {
const request = spec.buildRequests(bidRequests);
expect(JSON.parse(request.data.bidParamsJson).adUnitCodes).to.contain(bidRequests[0].adUnitCode);
expect(JSON.parse(request.data.bidParamsJson).adUnitCodes).to.contain(bidRequests[1].adUnitCode);
});

it('sends all Placement Ids and userId', function () {
const request = spec.buildRequests(bidRequestsWithUserId);
expect(JSON.parse(request.data.bidParamsJson).userId).to.exist;
Expand Down Expand Up @@ -823,6 +829,20 @@ describe('invibesBidAdapter:', function () {
}
};

let responseWithAdUnit = {
Ads: [{
BidPrice: 0.5,
VideoExposedId: 123
}],
BidModel: {
BidVersion: 1,
PlacementId: '12345_test-div1',
AuctionStartTime: Date.now(),
CreativeHtml: '<!-- Creative -->'
},
UseAdUnitCode: true
};

var buildResponse = function(placementId, cid, blcids, creativeId) {
return {
MultipositionEnabled: true,
Expand Down Expand Up @@ -911,6 +931,11 @@ describe('invibesBidAdapter:', function () {
let secondResult = spec.interpretResponse({body: response}, {bidRequests});
expect(secondResult).to.be.empty;
});

it('bids using the adUnitCode', function () {
let result = spec.interpretResponse({body: responseWithAdUnit}, {bidRequests});
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]));
});
});

context('when the response has meta', function () {
Expand Down
Loading

0 comments on commit 10ae6ca

Please sign in to comment.