Skip to content

Commit

Permalink
Improve Digital adapter: set dealID based on buying type (prebid#3182)
Browse files Browse the repository at this point in the history
* Adding GDPR support

* Always drop user syncs when available

* Set dealID based on buying type
  • Loading branch information
jbartek25 authored and Pedro López Jiménez committed Mar 18, 2019
1 parent 6d75bf8 commit d27233d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
21 changes: 17 additions & 4 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { config } from 'src/config';
const BIDDER_CODE = 'improvedigital';

export const spec = {
version: '4.3.0',
version: '4.4.0',
code: BIDDER_CODE,
aliases: ['id'],

Expand Down Expand Up @@ -78,11 +78,24 @@ export const spec = {
bid.cpm = parseFloat(bidObject.price);
bid.creativeId = bidObject.crid;
bid.currency = bidObject.currency ? bidObject.currency.toUpperCase() : 'USD';
if (utils.isNumber(bidObject.lid)) {

// Deal ID. Composite ads can have multiple line items and the ID of the first
// dealID line item will be used.
if (utils.isNumber(bidObject.lid) && bidObject.buying_type === 'deal_id') {
bid.dealId = bidObject.lid;
} else if (typeof bidObject.lid === 'object' && bidObject.lid['1']) {
bid.dealId = bidObject.lid['1'];
} else if (Array.isArray(bidObject.lid) &&
Array.isArray(bidObject.buying_type) &&
bidObject.lid.length === bidObject.buying_type.length) {
let isDeal = false;
bidObject.buying_type.forEach((bt, i) => {
if (isDeal) return;
if (bt === 'deal_id') {
isDeal = true;
bid.dealId = bidObject.lid[i];
}
});
}

bid.height = bidObject.h;
bid.netRevenue = bidObject.isNet ? bidObject.isNet : false;
bid.requestId = bidObject.id;
Expand Down
31 changes: 26 additions & 5 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,40 @@ describe('Improve Digital Adapter Tests', function () {
let response = JSON.parse(JSON.stringify(serverResponse));
let bids;

response.body.bid[0].lid = 'xyz';
delete response.body.bid[0].lid;
response.body.bid[0].buying_type = 'deal_id';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = 268515;
delete response.body.bid[0].buying_type;
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.equal(268515);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = {
1: 268515
};
response.body.bid[0].lid = 268515;
response.body.bid[0].buying_type = 'classic';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = 268515;
response.body.bid[0].buying_type = 'deal_id';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.equal(268515);

response.body.bid[0].lid = [ 268515, 12456, 34567 ];
response.body.bid[0].buying_type = 'deal_id';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = [ 268515, 12456, 34567 ];
response.body.bid[0].buying_type = [ 'deal_id', 'classic' ];
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = [ 268515, 12456, 34567 ];
response.body.bid[0].buying_type = [ 'classic', 'deal_id', 'deal_id' ];
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.equal(12456);
});

it('should set currency', function () {
Expand Down

0 comments on commit d27233d

Please sign in to comment.