Skip to content

Commit

Permalink
Relaido Adapter : size of the banner is checked and the banner can be…
Browse files Browse the repository at this point in the history
… bid on. (prebid#6776)

* add relaido adapter

* remove event listener

* fixed UserSyncs and e.data

* fix conflicts

* take size each mediaType

Co-authored-by: ishigami_shingo <[email protected]>
Co-authored-by: cmertv-sishigami <[email protected]>
Co-authored-by: t_bun <[email protected]>
  • Loading branch information
4 people authored and stsepelin committed May 28, 2021
1 parent 76e7650 commit ff90cb4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 38 deletions.
70 changes: 33 additions & 37 deletions modules/relaidoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'relaido';
const BIDDER_DOMAIN = 'api.relaido.jp';
const ADAPTER_VERSION = '1.0.2';
const ADAPTER_VERSION = '1.0.3';
const DEFAULT_TTL = 300;
const UUID_KEY = 'relaido_uuid';

Expand All @@ -17,21 +17,17 @@ function isBidRequestValid(bid) {
utils.logWarn('placementId param is reqeuired.');
return false;
}
if (hasVideoMediaType(bid)) {
if (!isVideoValid(bid)) {
utils.logWarn('Invalid mediaType video.');
return false;
}
} else if (hasBannerMediaType(bid)) {
if (!isBannerValid(bid)) {
utils.logWarn('Invalid mediaType banner.');
return false;
}
if (hasVideoMediaType(bid) && isVideoValid(bid)) {
return true;
} else {
utils.logWarn('Invalid mediaTypes input banner or video.');
return false;
utils.logWarn('Invalid mediaType video.');
}
return true;
if (hasBannerMediaType(bid) && isBannerValid(bid)) {
return true;
} else {
utils.logWarn('Invalid mediaType banner.');
}
return false;
}

function buildRequests(validBidRequests, bidderRequest) {
Expand All @@ -43,7 +39,21 @@ function buildRequests(validBidRequests, bidderRequest) {
const bidDomain = bidRequest.params.domain || BIDDER_DOMAIN;
const bidUrl = `https://${bidDomain}/bid/v1/prebid/${placementId}`;
const uuid = getUuid();
const mediaType = getMediaType(bidRequest);
let mediaType = '';
let width = 0;
let height = 0;

if (hasVideoMediaType(bidRequest) && isVideoValid(bidRequest)) {
const playerSize = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'));
width = playerSize[0][0];
height = playerSize[0][1];
mediaType = VIDEO;
} else if (hasBannerMediaType(bidRequest) && isBannerValid(bidRequest)) {
const sizes = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes'));
width = sizes[0][0];
height = sizes[0][1];
mediaType = BANNER;
}

let payload = {
version: ADAPTER_VERSION,
Expand All @@ -57,18 +67,10 @@ function buildRequests(validBidRequests, bidderRequest) {
transaction_id: bidRequest.transactionId,
media_type: mediaType,
uuid: uuid,
width: width,
height: height
};

if (hasVideoMediaType(bidRequest)) {
const playerSize = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'));
payload.width = playerSize[0][0];
payload.height = playerSize[0][1];
} else if (hasBannerMediaType(bidRequest)) {
const sizes = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes'));
payload.width = sizes[0][0];
payload.height = sizes[0][1];
}

// It may not be encoded, so add it at the end of the payload
payload.ref = bidderRequest.refererInfo.referer;

Expand All @@ -83,10 +85,9 @@ function buildRequests(validBidRequests, bidderRequest) {
player: bidRequest.params.player,
width: payload.width,
height: payload.height,
mediaType: mediaType,
mediaType: payload.media_type
});
}

return bidRequests;
}

Expand Down Expand Up @@ -162,6 +163,7 @@ function onTimeout(data) {
auction_id: utils.deepAccess(data, '0.auctionId'),
bid_id: utils.deepAccess(data, '0.bidId'),
ad_unit_code: utils.deepAccess(data, '0.adUnitCode'),
version: ADAPTER_VERSION,
ref: window.location.href,
}).replace(/\&$/, '');
const bidDomain = utils.deepAccess(data, '0.params.0.domain') || BIDDER_DOMAIN;
Expand Down Expand Up @@ -248,15 +250,6 @@ export function isMobile() {
return false;
}

function getMediaType(bid) {
if (hasVideoMediaType(bid)) {
return VIDEO;
} else if (hasBannerMediaType(bid)) {
return BANNER;
}
return '';
}

function hasBannerMediaType(bid) {
return !!utils.deepAccess(bid, 'mediaTypes.banner');
}
Expand All @@ -272,7 +265,10 @@ function getValidSizes(sizes) {
if (utils.isArray(sizes[i]) && sizes[i].length == 2) {
const width = sizes[i][0];
const height = sizes[i][1];
if ((width >= 300 && height >= 250) || (width == 1 && height == 1)) {
if (width == 1 && height == 1) {
return [[1, 1]];
}
if ((width >= 300 && height >= 250)) {
result.push([width, height]);
}
}
Expand Down
35 changes: 34 additions & 1 deletion test/spec/modules/relaidoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,18 @@ describe('RelaidoAdapter', function () {
});

it('should build bid requests by banner', function () {
setUAMobile();
bidRequest.mediaTypes = {
video: {
context: 'outstream',
playerSize: [
[320, 180]
]
},
banner: {
sizes: [
[640, 360]
[640, 360],
[1, 1]
]
}
};
Expand All @@ -221,6 +229,31 @@ describe('RelaidoAdapter', function () {
expect(request.mediaType).to.equal('banner');
});

it('should take 1x1 size', function () {
setUAMobile();
bidRequest.mediaTypes = {
video: {
context: 'outstream',
playerSize: [
[320, 180]
]
},
banner: {
sizes: [
[640, 360],
[1, 1]
]
}
};
const bidRequests = spec.buildRequests([bidRequest], bidderRequest);
expect(bidRequests).to.have.lengthOf(1);
const request = bidRequests[0];

// eslint-disable-next-line no-console
console.log(bidRequests);
expect(request.width).to.equal(1);
});

it('The referrer should be the last', function () {
const bidRequests = spec.buildRequests([bidRequest], bidderRequest);
expect(bidRequests).to.have.lengthOf(1);
Expand Down

0 comments on commit ff90cb4

Please sign in to comment.