From bbd11e3a8910c74622b588df18025ce1baa1ecf1 Mon Sep 17 00:00:00 2001 From: Jozef Bartek <31618107+jbartek25@users.noreply.github.com> Date: Tue, 16 Oct 2018 20:39:50 +0200 Subject: [PATCH] Improve Digital adapter: set dealID based on buying type (#3182) * Adding GDPR support * Always drop user syncs when available * Set dealID based on buying type --- modules/improvedigitalBidAdapter.js | 21 ++++++++++--- .../modules/improvedigitalBidAdapter_spec.js | 31 ++++++++++++++++--- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index 2cc1d8b39b01..54eb3bb65740 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -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'], @@ -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; diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js index bab469b936ee..3d7f5a860164 100644 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ b/test/spec/modules/improvedigitalBidAdapter_spec.js @@ -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 () {