Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default size filter & KVP support #4452

Merged
merged 42 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5711b57
adding DMX
Nov 17, 2016
ad33b56
Update districtm_spec.js
stevealliance Nov 30, 2016
fbd31ff
Update districtmDMX.js
stevealliance Nov 30, 2016
fe94313
updating repo fork in github
Oct 26, 2017
6054a04
Merge pull request #1 from prebid/master
stevealliance Jun 22, 2018
0384c75
adding all districtm needed file
Jun 22, 2018
d2f5de2
remove legacy file
Jun 22, 2018
d83db11
remove typo || 0 in the test method
Jun 22, 2018
a7d0a85
force default to return a valid width and height
Jun 27, 2018
d73cac7
update unit test code for failing test
Jun 27, 2018
d5b2617
changed class for an object
Jul 9, 2018
c80b0df
remove package-lock.json
Jul 9, 2018
afa5d3e
change file name for dmx adapter
Jul 11, 2018
4e93b06
remove package-lock.json
Jul 11, 2018
afdbd9e
update fork
Jul 31, 2018
5cc3181
renamed files
Jul 31, 2018
e3e864d
restaure package-lock.json
Jul 31, 2018
6af65f9
update to last package-lock state
Jul 31, 2018
4da8f60
Merge branch 'master' of https://github.com/prebid/Prebid.js
Aug 14, 2018
15954f2
Merge branch 'master' of https://github.com/prebid/Prebid.js
Aug 27, 2018
af73067
update gdpr user consent
Aug 27, 2018
c2e2f5f
fix sizes issue
Aug 27, 2018
0f83dab
Documentation updates
lsv1 Aug 29, 2018
787e1e0
Merge pull request #3 from lsv1/patch-1
stevealliance Aug 29, 2018
a63b92b
Merge branch 'master' of https://github.com/prebid/Prebid.js
Sep 4, 2018
3dfb282
update file name and update unit testing import file location
Sep 4, 2018
5786375
Merge branch 'master' of https://github.com/stevealliance/Prebid.js
Sep 4, 2018
60f693e
update remote to reflect forked repo
Jun 17, 2019
1f03347
Mdding all file to localserge branch 'master' of github.com:prebid/Pr…
Oct 23, 2019
a3d85d7
current machine state
Oct 23, 2019
a327932
lint correction
Oct 23, 2019
1706bd1
remove variable assigment duplicate
Oct 23, 2019
9492b32
adding change to dmx
steve-a-districtm Nov 6, 2019
e050ffc
adding logic upto5
steve-a-districtm Nov 6, 2019
073b474
adding support for removing and shuffle sizes
steve-a-districtm Nov 7, 2019
9d87cdd
adding array split test
steve-a-districtm Nov 8, 2019
effca85
re-assign none standard size to the request
steve-a-districtm Nov 8, 2019
3077a2d
resolve duplicate format inside format array
steve-a-districtm Nov 11, 2019
998da4b
update .md and adaptor file for KVP support
steve-a-districtm Nov 11, 2019
2d67433
remove array helper includes
steve-a-districtm Nov 11, 2019
2d49bfc
inforce two digit after decimal
steve-a-districtm Nov 13, 2019
06e9202
RUn error check nothing on my side but error form another adapter
steve-a-districtm Nov 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 117 additions & 11 deletions modules/districtmDMXBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +32,6 @@ export const spec = {
nBid.creativeId = nBid.crid;
nBid.currency = 'USD';
nBid.ttl = 60;

return nBid;
} else {
oBid.cpm = oBid.price;
Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions modules/districtmDmxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
}
});
```
42 changes: 41 additions & 1 deletion test/spec/modules/districtmDmxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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': {
Expand Down Expand Up @@ -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')
Expand Down