From 48d9b36263b6f37d1acc2e995b87d009ee658a4b Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Tue, 21 Nov 2017 11:12:08 -0800 Subject: [PATCH 1/4] wip --- test/spec/modules/appnexusAstBidAdapter_spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/spec/modules/appnexusAstBidAdapter_spec.js b/test/spec/modules/appnexusAstBidAdapter_spec.js index 3884b1c5863..b3e3e6a0480 100644 --- a/test/spec/modules/appnexusAstBidAdapter_spec.js +++ b/test/spec/modules/appnexusAstBidAdapter_spec.js @@ -76,6 +76,21 @@ describe('AppNexusAdapter', () => { }); }); + it('should populate the ad_types array on all requests', () => { + const bidRequest = Object.assign({}, bidRequests); + + // const bidRequest = Object.assign({}, + // bidRequests[0], + // { mediaTypes: {native: {}} } + // ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].ad_types).to.deep.equal(['banner']); + // expect(payload.tags[0].ad_types).to.deep.equal(['native']); + }); + it('sends bid request to ENDPOINT via POST', () => { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT); From 0ace278f7914a09f1db7580dfb67750e7ddad3d4 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Tue, 21 Nov 2017 14:18:44 -0800 Subject: [PATCH 2/4] Populate ad_types on all requests --- modules/appnexusAstBidAdapter.js | 13 +++++++++++-- .../spec/modules/appnexusAstBidAdapter_spec.js | 18 ++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/modules/appnexusAstBidAdapter.js b/modules/appnexusAstBidAdapter.js index f3173dc15bc..ad535d8bf57 100644 --- a/modules/appnexusAstBidAdapter.js +++ b/modules/appnexusAstBidAdapter.js @@ -1,7 +1,7 @@ import { Renderer } from 'src/Renderer'; import * as utils from 'src/utils'; import { registerBidder } from 'src/adapters/bidderFactory'; -import { NATIVE, VIDEO } from 'src/mediaTypes'; +import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; const BIDDER_CODE = 'appnexusAst'; const URL = '//ib.adnxs.com/ut/v3/prebid'; @@ -241,6 +241,7 @@ function bidToTag(bid) { const tag = {}; tag.sizes = transformSizes(bid.sizes); tag.primary_size = tag.sizes[0]; + tag.ad_types = []; tag.uuid = bid.bidId; if (bid.params.placementId) { tag.id = parseInt(bid.params.placementId, 10); @@ -280,7 +281,7 @@ function bidToTag(bid) { } if (bid.mediaType === 'native' || utils.deepAccess(bid, 'mediaTypes.native')) { - tag.ad_types = ['native']; + tag.ad_types.push('native'); if (bid.nativeParams) { const nativeRequest = buildNativeRequest(bid.nativeParams); @@ -292,6 +293,7 @@ function bidToTag(bid) { const context = utils.deepAccess(bid, 'mediaTypes.video.context'); if (bid.mediaType === 'video' || (videoMediaType && context !== 'outstream')) { + tag.ad_types.push('video'); tag.require_asset_url = true; } @@ -303,6 +305,13 @@ function bidToTag(bid) { .forEach(param => tag.video[param] = bid.params.video[param]); } + if ( + (utils.isEmpty(bid.mediaType) && utils.isEmpty(bid.mediaTypes)) || + (bid.mediaType === BANNER || (bid.mediaTypes && bid.mediaTypes[BANNER])) + ) { + tag.ad_types.push(BANNER); + } + return tag; } diff --git a/test/spec/modules/appnexusAstBidAdapter_spec.js b/test/spec/modules/appnexusAstBidAdapter_spec.js index b3e3e6a0480..dc1709c03cd 100644 --- a/test/spec/modules/appnexusAstBidAdapter_spec.js +++ b/test/spec/modules/appnexusAstBidAdapter_spec.js @@ -77,18 +77,16 @@ describe('AppNexusAdapter', () => { }); it('should populate the ad_types array on all requests', () => { - const bidRequest = Object.assign({}, bidRequests); + ['banner', 'video', 'native'].forEach(type => { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest.mediaTypes = {}; + bidRequest.mediaTypes[type] = {}; - // const bidRequest = Object.assign({}, - // bidRequests[0], - // { mediaTypes: {native: {}} } - // ); + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal(['banner']); - // expect(payload.tags[0].ad_types).to.deep.equal(['native']); + expect(payload.tags[0].ad_types).to.deep.equal([type]); + }); }); it('sends bid request to ENDPOINT via POST', () => { From 0f36fdc8232e6e090771343a7aefa08162caf202 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Tue, 21 Nov 2017 14:48:59 -0800 Subject: [PATCH 3/4] Use constants for media types --- modules/appnexusAstBidAdapter.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/modules/appnexusAstBidAdapter.js b/modules/appnexusAstBidAdapter.js index ad535d8bf57..c5ab47e8de5 100644 --- a/modules/appnexusAstBidAdapter.js +++ b/modules/appnexusAstBidAdapter.js @@ -5,7 +5,6 @@ import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; const BIDDER_CODE = 'appnexusAst'; const URL = '//ib.adnxs.com/ut/v3/prebid'; -const SUPPORTED_AD_TYPES = ['banner', 'video', 'native']; const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks']; const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt', 'language']; @@ -28,7 +27,7 @@ const SOURCE = 'pbjs'; export const spec = { code: BIDDER_CODE, - supportedMediaTypes: [VIDEO, NATIVE], + supportedMediaTypes: [BANNER, VIDEO, NATIVE], /** * Determines whether or not the given bid request is valid. @@ -100,7 +99,7 @@ export const spec = { serverResponse.tags.forEach(serverBid => { const rtbBid = getRtbBid(serverBid); if (rtbBid) { - if (rtbBid.cpm !== 0 && SUPPORTED_AD_TYPES.includes(rtbBid.ad_type)) { + if (rtbBid.cpm !== 0 && this.supportedMediaTypes.includes(rtbBid.ad_type)) { const bid = newBid(serverBid, rtbBid); bid.mediaType = parseMediaType(rtbBid); bids.push(bid); @@ -206,9 +205,9 @@ function newBid(serverBid, rtbBid) { bid.adResponse.ad = bid.adResponse.ads[0]; bid.adResponse.ad.video = bid.adResponse.ad.rtb.video; } - } else if (rtbBid.rtb['native']) { - const nativeAd = rtbBid.rtb['native']; - bid['native'] = { + } else if (rtbBid.rtb[NATIVE]) { + const nativeAd = rtbBid.rtb[NATIVE]; + bid[NATIVE] = { title: nativeAd.title, body: nativeAd.desc, cta: nativeAd.ctatext, @@ -280,20 +279,20 @@ function bidToTag(bid) { tag.keywords = getKeywords(bid.params.keywords); } - if (bid.mediaType === 'native' || utils.deepAccess(bid, 'mediaTypes.native')) { - tag.ad_types.push('native'); + if (bid.mediaType === NATIVE || utils.deepAccess(bid, 'mediaTypes.native')) { + tag.ad_types.push(NATIVE); if (bid.nativeParams) { const nativeRequest = buildNativeRequest(bid.nativeParams); - tag['native'] = {layouts: [nativeRequest]}; + tag[NATIVE] = {layouts: [nativeRequest]}; } } const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video'); const context = utils.deepAccess(bid, 'mediaTypes.video.context'); - if (bid.mediaType === 'video' || (videoMediaType && context !== 'outstream')) { - tag.ad_types.push('video'); + if (bid.mediaType === VIDEO || (videoMediaType && context !== 'outstream')) { + tag.ad_types.push(VIDEO); tag.require_asset_url = true; } @@ -408,12 +407,12 @@ function handleOutstreamRendererEvents(bid, id, eventName) { function parseMediaType(rtbBid) { const adType = rtbBid.ad_type; - if (adType === 'video') { - return 'video'; - } else if (adType === 'native') { - return 'native'; + if (adType === VIDEO) { + return VIDEO; + } else if (adType === NATIVE) { + return NATIVE; } else { - return 'banner'; + return BANNER; } } From b1da7cb318dc54c4746aa59959558e044c7fd4da Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Fri, 24 Nov 2017 12:16:04 -0800 Subject: [PATCH 4/4] Cover outstream requests --- modules/appnexusAstBidAdapter.js | 6 +++++- test/spec/modules/appnexusAstBidAdapter_spec.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/appnexusAstBidAdapter.js b/modules/appnexusAstBidAdapter.js index c5ab47e8de5..890c69df243 100644 --- a/modules/appnexusAstBidAdapter.js +++ b/modules/appnexusAstBidAdapter.js @@ -291,8 +291,12 @@ function bidToTag(bid) { const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video'); const context = utils.deepAccess(bid, 'mediaTypes.video.context'); - if (bid.mediaType === VIDEO || (videoMediaType && context !== 'outstream')) { + if (bid.mediaType === VIDEO || videoMediaType) { tag.ad_types.push(VIDEO); + } + + // instream gets vastUrl, outstream gets vastXml + if (bid.mediaType === VIDEO || (videoMediaType && context !== 'outstream')) { tag.require_asset_url = true; } diff --git a/test/spec/modules/appnexusAstBidAdapter_spec.js b/test/spec/modules/appnexusAstBidAdapter_spec.js index dc1709c03cd..af92aa40605 100644 --- a/test/spec/modules/appnexusAstBidAdapter_spec.js +++ b/test/spec/modules/appnexusAstBidAdapter_spec.js @@ -89,6 +89,17 @@ describe('AppNexusAdapter', () => { }); }); + it('should populate the ad_types array on outstream requests', () => { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest.mediaTypes = {}; + bidRequest.mediaTypes.video = {context: 'outstream'}; + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].ad_types).to.deep.equal(['video']); + }); + it('sends bid request to ENDPOINT via POST', () => { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT);