diff --git a/modules/medianetBidAdapter.js b/modules/medianetBidAdapter.js index cc00f7c1ea4..8236fb0888c 100644 --- a/modules/medianetBidAdapter.js +++ b/modules/medianetBidAdapter.js @@ -2,6 +2,7 @@ import { registerBidder } from '../src/adapters/bidderFactory'; import * as utils from '../src/utils'; import { config } from '../src/config'; import * as url from '../src/url'; +import { BANNER, NATIVE } from '../src/mediaTypes'; const BIDDER_CODE = 'medianet'; const BID_URL = '//prebid.media.net/rtb/prebid'; @@ -138,9 +139,18 @@ function slotParams(bidRequest) { dfp_id: bidRequest.adUnitCode, display_count: bidRequest.bidRequestsCount }, - banner: transformSizes(bidRequest.sizes), all: bidRequest.params }; + if (bidRequest.sizes.length > 0) { + params.banner = transformSizes(bidRequest.sizes); + } + if (bidRequest.nativeParams) { + try { + params.native = JSON.stringify(bidRequest.nativeParams); + } catch (e) { + utils.logError((`${BIDDER_CODE} : Incorrect JSON : bidRequest.nativeParams`)); + } + } if (bidRequest.params.crid) { params.tagid = bidRequest.params.crid.toString(); @@ -151,7 +161,7 @@ function slotParams(bidRequest) { params.bidfloor = bidFloor; } const coordinates = getCoordinates(bidRequest.adUnitCode); - if (coordinates) { + if (coordinates && params.banner && params.banner.length !== 0) { let normCoordinates = normalizeCoordinates(coordinates); params.ext.coordinates = normCoordinates; params.ext.viewability = getSlotVisibility(coordinates.top_left, getMinSize(params.banner)); @@ -268,6 +278,8 @@ export const spec = { code: BIDDER_CODE, + supportedMediaTypes: [BANNER, NATIVE], + /** * Determines whether or not the given bid request is valid. * diff --git a/modules/medianetBidAdapter.md b/modules/medianetBidAdapter.md index 2edb120033e..a29ee056a88 100644 --- a/modules/medianetBidAdapter.md +++ b/modules/medianetBidAdapter.md @@ -30,7 +30,7 @@ var adUnits = [{ }]; ``` -# Ad Unit and Setup: For Testing +# Ad Unit and Setup: For Testing (Banner) ```html @@ -56,4 +56,46 @@ var adUnits = [{ pbjs.que = pbjs.que || []; -``` \ No newline at end of file +``` + + +# Ad Unit and Setup: For Testing (Native) + +```html + + + diff --git a/test/spec/modules/medianetBidAdapter_spec.js b/test/spec/modules/medianetBidAdapter_spec.js index 331b36b3217..336a86a7793 100644 --- a/test/spec/modules/medianetBidAdapter_spec.js +++ b/test/spec/modules/medianetBidAdapter_spec.js @@ -73,6 +73,101 @@ let VALID_BID_REQUEST = [{ 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', 'bidRequestsCount': 1 }], + VALID_NATIVE_BID_REQUEST = [{ + 'bidder': 'medianet', + 'params': { + 'cid': 'customer_id', + 'site': { + 'page': 'http://media.net/prebidtest', + 'domain': 'media.net', + 'ref': 'http://media.net/prebidtest' + } + }, + 'adUnitCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', + 'sizes': [[300, 250]], + 'bidId': '28f8f8130a583e', + 'bidderRequestId': '1e9b1f07797c1c', + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1, + 'nativeParams': { + 'image': { + 'required': true, + 'sizes': [ + 150, + 50 + ], + 'wmin': 50 + }, + 'title': { + 'required': true, + 'len': 80 + }, + 'sponsoredBy': { + 'required': true + }, + 'clickUrl': { + 'required': true + }, + 'body': { + 'required': true + }, + 'icon': { + 'required': true, + 'sizes': [ + 50, + 50 + ] + } + } + }, { + 'bidder': 'medianet', + 'params': { + 'cid': 'customer_id', + 'site': { + 'page': 'http://media.net/prebidtest', + 'domain': 'media.net', + 'ref': 'http://media.net/prebidtest' + } + }, + 'adUnitCode': 'div-gpt-ad-1460505748561-123', + 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', + 'sizes': [[300, 251]], + 'bidId': '3f97ca71b1e5c2', + 'bidderRequestId': '1e9b1f07797c1c', + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1, + 'nativeParams': { + 'image': { + 'required': true, + 'sizes': [ + 150, + 50 + ], + 'wmin': 50 + }, + 'title': { + 'required': true, + 'len': 80 + }, + 'sponsoredBy': { + 'required': true + }, + 'clickUrl': { + 'required': true + }, + 'body': { + 'required': true + }, + 'icon': { + 'required': true, + 'sizes': [ + 50, + 50 + ] + } + } + }], VALID_AUCTIONDATA = { 'timeout': config.getConfig('bidderTimeout'), }, @@ -156,6 +251,87 @@ let VALID_BID_REQUEST = [{ }], 'tmax': config.getConfig('bidderTimeout') }, + VALID_PAYLOAD_NATIVE = { + 'site': { + 'page': 'http://media.net/prebidtest', + 'domain': 'media.net', + 'ref': 'http://media.net/prebidtest' + }, + 'ext': { + 'customer_id': 'customer_id', + 'prebid_version': $$PREBID_GLOBAL$$.version, + 'gdpr_applies': false, + 'screen': { + 'w': 1000, + 'h': 1000 + } + }, + 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'imp': [{ + 'id': '28f8f8130a583e', + 'ext': { + 'dfp_id': 'div-gpt-ad-1460505748561-0', + 'visibility': 1, + 'viewability': 1, + 'coordinates': { + 'top_left': { + x: 50, + y: 50 + }, + 'bottom_right': { + x: 100, + y: 100 + } + }, + 'display_count': 1 + }, + 'banner': [{ + 'w': 300, + 'h': 250 + }], + 'native': '{\"image\":{\"required\":true,\"sizes\":[150,50],\"wmin\":50},\"title\":{\"required\":true,\"len\":80},\"sponsoredBy\":{\"required\":true},\"clickUrl\":{\"required\":true},\"body\":{\"required\":true},\"icon\":{\"required\":true,\"sizes\":[50,50]}}', + 'all': { + 'cid': 'customer_id', + 'site': { + 'page': 'http://media.net/prebidtest', + 'domain': 'media.net', + 'ref': 'http://media.net/prebidtest' + } + } + }, { + 'id': '3f97ca71b1e5c2', + 'ext': { + 'dfp_id': 'div-gpt-ad-1460505748561-123', + 'visibility': 1, + 'viewability': 1, + 'coordinates': { + 'top_left': { + x: 50, + y: 50 + }, + 'bottom_right': { + x: 100, + y: 100 + } + }, + 'display_count': 1 + }, + 'banner': [{ + 'w': 300, + 'h': 251 + }], + 'native': '{\"image\":{\"required\":true,\"sizes\":[150,50],\"wmin\":50},\"title\":{\"required\":true,\"len\":80},\"sponsoredBy\":{\"required\":true},\"clickUrl\":{\"required\":true},\"body\":{\"required\":true},\"icon\":{\"required\":true,\"sizes\":[50,50]}}', + 'all': { + 'cid': 'customer_id', + 'site': { + 'page': 'http://media.net/prebidtest', + 'domain': 'media.net', + 'ref': 'http://media.net/prebidtest' + } + } + }], + 'tmax': config.getConfig('bidderTimeout') + }, VALID_PAYLOAD = { 'site': { 'page': 'http://media.net/prebidtest', @@ -562,6 +738,11 @@ describe('Media.net bid adapter', function () { expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_FOR_GDPR); }); + it('should parse params for native request', function () { + let bidReq = spec.buildRequests(VALID_NATIVE_BID_REQUEST, VALID_AUCTIONDATA); + expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_NATIVE); + }); + describe('build requests: when page meta-data is available', () => { beforeEach(() => { spec.clearMnData();