Skip to content

Commit

Permalink
Use default native size if received size is undefined (#5192)
Browse files Browse the repository at this point in the history
Co-authored-by: mi.chen <[email protected]>
  • Loading branch information
bmwcmw and mi.chen authored May 14, 2020
1 parent 2fe9d78 commit 0d40c28
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 16 deletions.
36 changes: 20 additions & 16 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { loadExternalScript } from '../src/adloader.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import {loadExternalScript} from '../src/adloader.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import find from 'core-js-pure/features/array/find.js';
import { verify } from 'criteo-direct-rsa-validate/build/verify.js';
import { getStorageManager } from '../src/storageManager.js';

const GVLID = 91;
export const ADAPTER_VERSION = 29;
export const ADAPTER_VERSION = 31;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const PROFILE_ID_INLINE = 207;
Expand Down Expand Up @@ -274,7 +274,6 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
impid: bidRequest.adUnitCode,
transactionid: bidRequest.transactionId,
auctionId: bidRequest.auctionId,
sizes: getBannerSizes(bidRequest),
};
if (bidRequest.params.zoneId) {
slot.zoneid = bidRequest.params.zoneId;
Expand All @@ -293,10 +292,13 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
if (!checkNativeSendId(bidRequest)) {
utils.logWarn(LOG_PREFIX + 'all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)');
}
slot.sizes = parseSizes(retrieveBannerSizes(bidRequest), parseNativeSize);
} else {
slot.sizes = parseSizes(retrieveBannerSizes(bidRequest), parseSize);
}
if (hasVideoMediaType(bidRequest)) {
const video = {
playersizes: getVideoSizes(bidRequest),
playersizes: parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'), parseSize),
mimes: bidRequest.mediaTypes.video.mimes,
protocols: bidRequest.mediaTypes.video.protocols,
maxduration: bidRequest.mediaTypes.video.maxduration,
Expand Down Expand Up @@ -339,24 +341,26 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
return request;
}

function getVideoSizes(bidRequest) {
return parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'));
function retrieveBannerSizes(bidRequest) {
return utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes;
}

function getBannerSizes(bidRequest) {
return parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes);
function parseSizes(sizes, parser) {
if (Array.isArray(sizes[0])) { // is there several sizes ? (ie. [[728,90],[200,300]])
return sizes.map(size => parser(size));
}
return [parser(sizes)]; // or a single one ? (ie. [728,90])
}

function parseSize(size) {
return size[0] + 'x' + size[1];
}

function parseSizes(sizes) {
if (Array.isArray(sizes[0])) { // is there several sizes ? (ie. [[728,90],[200,300]])
return sizes.map(size => parseSize(size));
function parseNativeSize(size) {
if (size[0] === undefined && size[1] === undefined) {
return '2x2';
}

return [parseSize(sizes)]; // or a single one ? (ie. [728,90])
return size[0] + 'x' + size[1];
}

function hasVideoMediaType(bidRequest) {
Expand Down
56 changes: 56 additions & 0 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,62 @@ describe('The Criteo bidding adapter', function () {
expect(ortbRequest.gdprConsent.version).to.equal(1);
});

it('should keep undefined sizes for non native banner', function () {
const bidRequests = [
{
sizes: [[undefined, undefined]],
params: {},
},
];
const request = spec.buildRequests(bidRequests, bidderRequest);
const ortbRequest = request.data;
expect(ortbRequest.slots[0].sizes).to.have.lengthOf(1);
expect(ortbRequest.slots[0].sizes[0]).to.equal('undefinedxundefined');
});

it('should keep undefined size for non native banner', function () {
const bidRequests = [
{
sizes: [undefined, undefined],
params: {},
},
];
const request = spec.buildRequests(bidRequests, bidderRequest);
const ortbRequest = request.data;
expect(ortbRequest.slots[0].sizes).to.have.lengthOf(1);
expect(ortbRequest.slots[0].sizes[0]).to.equal('undefinedxundefined');
});

it('should properly detect and get sizes of native sizeless banner', function () {
const bidRequests = [
{
sizes: [[undefined, undefined]],
params: {
nativeCallback: function() {}
},
},
];
const request = spec.buildRequests(bidRequests, bidderRequest);
const ortbRequest = request.data;
expect(ortbRequest.slots[0].sizes).to.have.lengthOf(1);
expect(ortbRequest.slots[0].sizes[0]).to.equal('2x2');
});

it('should properly detect and get size of native sizeless banner', function () {
const bidRequests = [
{
sizes: [undefined, undefined],
params: {
nativeCallback: function() {}
},
},
];
const request = spec.buildRequests(bidRequests, bidderRequest);
const ortbRequest = request.data;
expect(ortbRequest.slots[0].sizes).to.have.lengthOf(1);
expect(ortbRequest.slots[0].sizes[0]).to.equal('2x2');
});

it('should properly build a networkId request', function () {
const bidderRequest = {
refererInfo: {
Expand Down

0 comments on commit 0d40c28

Please sign in to comment.