diff --git a/modules/districtmDMXBidAdapter.js b/modules/districtmDMXBidAdapter.js index 5942e0ea683..205017066a8 100644 --- a/modules/districtmDMXBidAdapter.js +++ b/modules/districtmDMXBidAdapter.js @@ -22,7 +22,7 @@ export const spec = { if (oBid.price < nBid.price) { const bid = matchRequest(nBid.impid, bidRequest); const {width, height} = defaultSize(bid); - nBid.cpm = nBid.price; + nBid.cpm = parseFloat(nBid.price).toFixed(2); nBid.bidId = nBid.impid; nBid.requestId = nBid.impid; nBid.width = nBid.w || width; @@ -32,7 +32,6 @@ export const spec = { nBid.creativeId = nBid.crid; nBid.currency = 'USD'; nBid.ttl = 60; - return nBid; } else { oBid.cpm = oBid.price; @@ -69,6 +68,14 @@ export const spec = { site: { publisher: { id: String(bidRequest[0].params.memberid) || null } } + } + try { + let params = config.getConfig('dmx'); + dmxRequest.user = params.user || {}; + let site = params.site || {}; + dmxRequest.site = {...dmxRequest.site, ...site} + } catch (e) { + } if (!dmxRequest.test) { delete dmxRequest.test; @@ -94,21 +101,25 @@ export const spec = { obj.secure = 1; obj.banner = { topframe: 1, - w: dmx.sizes[0][0] || 0, - h: dmx.sizes[0][1] || 0, - format: dmx.sizes.map(s => { + w: cleanSizes(dmx.sizes, 'w'), + h: cleanSizes(dmx.sizes, 'h'), + format: cleanSizes(dmx.sizes).map(s => { return {w: s[0], h: s[1]}; }).filter(obj => typeof obj.w === 'number' && typeof obj.h === 'number') }; return obj; }); - dmxRequest.imp = tosendtags; - return { - method: 'POST', - url: DMXURI, - data: JSON.stringify(dmxRequest), - bidderRequest + if (tosendtags.length <= 5) { + dmxRequest.imp = tosendtags; + return { + method: 'POST', + url: DMXURI, + data: JSON.stringify(dmxRequest), + bidderRequest + } + } else { + return upto5(tosendtags, dmxRequest, bidderRequest, DMXURI); } }, test() { @@ -124,6 +135,101 @@ export const spec = { } } +export function cleanSizes(sizes, value) { + const supportedSize = [ + { + size: [300, 250], + s: 100 + }, + { + size: [728, 90], + s: 95 + }, + { + size: [320, 50], + s: 90 + }, + { + size: [160, 600], + s: 88 + }, + { + size: [300, 600], + s: 85 + }, + { + size: [300, 50], + s: 80 + }, + { + size: [970, 250], + s: 75 + }, + { + size: [970, 90], + s: 60 + }, + ]; + let newArray = shuffle(sizes, supportedSize); + switch (value) { + case 'w': + return newArray[0][0] || 0; + case 'h': + return newArray[0][1] || 0; + case 'size': + return newArray; + default: + return newArray; + } +} + +export function shuffle(sizes, list) { + let removeSizes = sizes.filter(size => { + return list.map(l => `${l.size[0]}x${l.size[1]}`).indexOf(`${size[0]}x${size[1]}`) === -1 + }) + let reOrder = sizes.reduce((results, current) => { + if (results.length === 0) { + results.push(current); + return results; + } + results.push(current); + results = list.filter(l => results.map(r => `${r[0]}x${r[1]}`).indexOf(`${l.size[0]}x${l.size[1]}`) !== -1); + results = results.sort(function(a, b) { + return b.s - a.s; + }) + return results.map(r => r.size); + }, []) + return removeDuplicate([...reOrder, ...removeSizes]); +} + +export function removeDuplicate(arrayValue) { + return arrayValue.filter((elem, index) => { + return arrayValue.map(e => `${e[0]}x${e[1]}`).indexOf(`${elem[0]}x${elem[1]}`) === index + }) +} + +export function upto5(allimps, dmxRequest, bidderRequest, DMXURI) { + let start = 0; + let step = 5; + let req = []; + while (allimps.length !== 0) { + if (allimps.length >= 5) { + req.push(allimps.splice(start, step)) + } else { + req.push(allimps.splice(start, allimps.length)) + } + } + return req.map(r => { + dmxRequest.imp = r; + return { + method: 'POST', + url: DMXURI, + data: JSON.stringify(dmxRequest), + bidderRequest + } + }) +} + /** * Function matchRequest(id: string, BidRequest: object) * @param id diff --git a/modules/districtmDmxBidAdapter.md b/modules/districtmDmxBidAdapter.md index 2859bcfa19d..5bc1e5d5780 100644 --- a/modules/districtmDmxBidAdapter.md +++ b/modules/districtmDmxBidAdapter.md @@ -115,3 +115,25 @@ Our demand and adapter supports multiple sizes per placement, as such a single d ###### 4. Implementation Checking Once the bidder is live in your Prebid configuration you may confirm it is making requests to our end point by looking for requests to `https://dmx.districtm.io/b/v1`. + + +###### 5. Setting first party data + +```code +pbjs.setConfig({ + dmx: { + user: { + 'gender': 'M', + 'yob': 1992, + // keywords example + 'keywords': 'automotive,dodge,engine,car' + + }, + site: { + cat: ['IAB-12'], + pagecat: ['IAB-14'], + sectioncat: ['IAB-24'] + } + } +}); +``` diff --git a/test/spec/modules/districtmDmxBidAdapter_spec.js b/test/spec/modules/districtmDmxBidAdapter_spec.js index 64f76eb026d..ac8698f63a9 100644 --- a/test/spec/modules/districtmDmxBidAdapter_spec.js +++ b/test/spec/modules/districtmDmxBidAdapter_spec.js @@ -1,7 +1,41 @@ import {expect} from 'chai'; import * as _ from 'lodash'; -import {spec, matchRequest, checkDeepArray, defaultSize} from '../../../modules/districtmDMXBidAdapter'; +import {spec, matchRequest, checkDeepArray, defaultSize, upto5, cleanSizes, shuffle} from '../../../modules/districtmDMXBidAdapter'; +const supportedSize = [ + { + size: [300, 250], + s: 100 + }, + { + size: [728, 90], + s: 95 + }, + { + size: [300, 600], + s: 90 + }, + { + size: [160, 600], + s: 88 + }, + { + size: [320, 50], + s: 85 + }, + { + size: [300, 50], + s: 80 + }, + { + size: [970, 250], + s: 75 + }, + { + size: [970, 90], + s: 60 + }, +]; const bidRequest = [{ 'bidder': 'districtmDMX', 'params': { @@ -422,6 +456,12 @@ const emptyResponseSeatBid = { body: { seatbid: [] } }; describe('DistrictM Adaptor', function () { const districtm = spec; + describe('verification of upto5', function() { + it('upto5 function should always break 12 imps into 3 request same for 15', function() { + expect(upto5([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], bidRequest, bidderRequest, 'https://google').length).to.be.equal(3) + expect(upto5([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], bidRequest, bidderRequest, 'https://google').length).to.be.equal(3) + }) + }) describe('All needed functions are available', function () { it(`isBidRequestValid is present and type function`, function () { expect(districtm.isBidRequestValid).to.exist.and.to.be.a('function')