diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index 5d137c994fe0..60ad15c1d9b9 100644 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -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/library/fn/array/find.js'; -import { verify } from 'criteo-direct-rsa-validate/build/verify.js'; -import { getStorageManager } from '../src/storageManager.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; @@ -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; @@ -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, @@ -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) { diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index 042f1a4d61db..6ab0159e9017 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -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: {