From 9169108ac98b03eac160395df28e6cc6e648d829 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:10:18 -0700 Subject: [PATCH 01/10] Added deals support in viantOrtbBidAdapter --- modules/viantOrtbBidAdapter.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index d056dfeb2eb..32b6cf1eeab 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -6,6 +6,7 @@ import {deepAccess, getBidIdParameter, logError} from '../src/utils.js'; const BIDDER_CODE = 'viant'; const ENDPOINT = 'https://bidders-us-east-1.adelphic.net/d/rtb/v25/prebid/bidder' +const ADAPTER_VERSION = '2.0.0'; const DEFAULT_BID_TTL = 300; const DEFAULT_CURRENCY = 'USD'; @@ -85,6 +86,33 @@ function createRequest(bidRequests, bidderRequest, mediaType) { if (!data.regs.ext) data.regs.ext = {}; data.regs.ext.us_privacy = bidderRequest.uspConsent; } + + let imp = data.imp || []; + let dealsMap = new Map(); + let privateAuctions = new Map(); + bidderRequest.bids.forEach(bid => { + if (bid.params.pmp !== undefined) { + dealsMap.set(bid.bidId, bid.params.pmp); + privateAuctions.set(bid.bidId, bid.params.private_auction || 0); + } + }); + + imp.forEach((element) => { + if (dealsMap.size > 0) { + let deals = dealsMap.get(element.id); + if (deals) { + element.pmp = element.pmp || {}; + element.pmp = deals; + element.pmp.private_auction = privateAuctions.get(element.id); + } + } + }); + + data.ext = data.ext || {}; + data.ext.viant = { + adapterVersion: ADAPTER_VERSION + }; + return { method: 'POST', url: ENDPOINT, From a2717cdf3e5dbff0633a29c5f0fc381e992b5370 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:16:39 -0700 Subject: [PATCH 02/10] refactoring --- modules/viantOrtbBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index 32b6cf1eeab..74775d9f44e 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -103,9 +103,9 @@ function createRequest(bidRequests, bidderRequest, mediaType) { if (deals) { element.pmp = element.pmp || {}; element.pmp = deals; - element.pmp.private_auction = privateAuctions.get(element.id); } } + element.pmp.private_auction = privateAuctions.get(element.id); }); data.ext = data.ext || {}; From a1307e3afd88c9a25b58291119561388e0c1319e Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:20:12 -0700 Subject: [PATCH 03/10] refactor --- modules/viantOrtbBidAdapter.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index 74775d9f44e..9aa4742d556 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -86,7 +86,6 @@ function createRequest(bidRequests, bidderRequest, mediaType) { if (!data.regs.ext) data.regs.ext = {}; data.regs.ext.us_privacy = bidderRequest.uspConsent; } - let imp = data.imp || []; let dealsMap = new Map(); let privateAuctions = new Map(); @@ -96,7 +95,6 @@ function createRequest(bidRequests, bidderRequest, mediaType) { privateAuctions.set(bid.bidId, bid.params.private_auction || 0); } }); - imp.forEach((element) => { if (dealsMap.size > 0) { let deals = dealsMap.get(element.id); @@ -107,12 +105,10 @@ function createRequest(bidRequests, bidderRequest, mediaType) { } element.pmp.private_auction = privateAuctions.get(element.id); }); - data.ext = data.ext || {}; data.ext.viant = { adapterVersion: ADAPTER_VERSION }; - return { method: 'POST', url: ENDPOINT, From 16cb24ea70e12f3c93f1d5ca0cfefadaf6b4679b Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:29:29 -0700 Subject: [PATCH 04/10] refactor --- modules/viantOrtbBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index 9aa4742d556..ca1991c37ce 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -103,7 +103,7 @@ function createRequest(bidRequests, bidderRequest, mediaType) { element.pmp = deals; } } - element.pmp.private_auction = privateAuctions.get(element.id); + element.pmp.private_auction = privateAuctions.get(element.id) || 0; }); data.ext = data.ext || {}; data.ext.viant = { From e16697eeaeb53eff7da9a9beaf2ca7dc780a6a05 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:35:15 -0700 Subject: [PATCH 05/10] refactor --- modules/viantOrtbBidAdapter.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index ca1991c37ce..9f20be063a5 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -96,14 +96,12 @@ function createRequest(bidRequests, bidderRequest, mediaType) { } }); imp.forEach((element) => { - if (dealsMap.size > 0) { - let deals = dealsMap.get(element.id); - if (deals) { - element.pmp = element.pmp || {}; - element.pmp = deals; - } + let deals = dealsMap.get(element.id); + if (deals) { + element.pmp = deals; } - element.pmp.private_auction = privateAuctions.get(element.id) || 0; + element.pmp = element.pmp || {}; + element.pmp.private_auction = privateAuctions.get(element.id); }); data.ext = data.ext || {}; data.ext.viant = { From 7274077d8f509f733358ee57f02134c9134e6102 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:49:51 -0700 Subject: [PATCH 06/10] refactor --- modules/viantOrtbBidAdapter.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index 9f20be063a5..cdb5b06d272 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -89,12 +89,14 @@ function createRequest(bidRequests, bidderRequest, mediaType) { let imp = data.imp || []; let dealsMap = new Map(); let privateAuctions = new Map(); - bidderRequest.bids.forEach(bid => { - if (bid.params.pmp !== undefined) { - dealsMap.set(bid.bidId, bid.params.pmp); - privateAuctions.set(bid.bidId, bid.params.private_auction || 0); - } - }); + if (bidderRequest.bids) { + bidderRequest.bids.forEach(bid => { + if (bid.params && bid.params.pmp) { + dealsMap.set(bid.bidId, bid.params.pmp); + privateAuctions.set(bid.bidId, bid.params.private_auction || 0); + } + }); + } imp.forEach((element) => { let deals = dealsMap.get(element.id); if (deals) { From 66977c87593d9f3085a5db17ed2cb39a5ddbfaa9 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:23:28 -0700 Subject: [PATCH 07/10] added test case --- test/spec/modules/viantOrtbBidAdapter_spec.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/spec/modules/viantOrtbBidAdapter_spec.js b/test/spec/modules/viantOrtbBidAdapter_spec.js index 271c944e6e9..2221c1d4d18 100644 --- a/test/spec/modules/viantOrtbBidAdapter_spec.js +++ b/test/spec/modules/viantOrtbBidAdapter_spec.js @@ -180,6 +180,54 @@ describe('viantOrtbBidAdapter', function () { 'src': 'client', 'bidRequestsCount': 1 }]; + const basePMPDealsBidRequests = [{ + 'bidder': 'viant', + 'params': { + 'publisherId': '464', + 'placementId': '1', + 'pmp': { + 'deals': [ + { + 'id': '1234567', + 'at': 3, + 'bidfloor': 25, + 'bidfloorcur': 'USD', + 'ext': { + 'must_bid': 1, + 'private_auction': 1 + } + }, + { + 'id': '1234568', + 'at': 3, + 'bidfloor': 25, + 'bidfloorcur': 'USD', + 'ext': { + 'must_bid': 0 + } + } + ] + } + }, + 'mediaTypes': { + 'banner': { + 'sizes': [[728, 90]] + } + }, + 'gdprConsent': { + 'consentString': 'consentString', + 'gdprApplies': true, + }, + 'uspConsent': '1YYY', + 'sizes': [[728, 90]], + 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', + 'adUnitCode': 'div-gpt-ad-1460505748561-0', + 'bidId': '243310435309b5', + 'bidderRequestId': '18084284054531', + 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', + 'src': 'client', + 'bidRequestsCount': 1 + }]; const testWindow = buildWindowTree(['https://www.example.com/test', 'https://www.example.com/other/page', 'https://www.example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'); const baseBidderRequestReferer = detectReferer(testWindow)(); @@ -238,6 +286,11 @@ describe('viantOrtbBidAdapter', function () { }); }); + it('includes the deals in the bid request', function () { + const requestBody = testBuildRequests(basePMPDealsBidRequests, baseBidderRequest)[0].data; + expect(requestBody.imp[0].pmp).to.be.not.null; + }); + if (FEATURES.VIDEO) { describe('buildRequests-video', function () { function makeBid() { From f7419bcfecff9526507aedcd5473a9f516ab02f2 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:40:32 -0700 Subject: [PATCH 08/10] refactor --- test/spec/modules/viantOrtbBidAdapter_spec.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/viantOrtbBidAdapter_spec.js b/test/spec/modules/viantOrtbBidAdapter_spec.js index 2221c1d4d18..3121bd7a84f 100644 --- a/test/spec/modules/viantOrtbBidAdapter_spec.js +++ b/test/spec/modules/viantOrtbBidAdapter_spec.js @@ -289,7 +289,31 @@ describe('viantOrtbBidAdapter', function () { it('includes the deals in the bid request', function () { const requestBody = testBuildRequests(basePMPDealsBidRequests, baseBidderRequest)[0].data; expect(requestBody.imp[0].pmp).to.be.not.null; - }); + expect(requestBody.imp[0].pmp).to.deep.equal({ + 'private_auction': 0, + 'deals': [ + { + 'id': '1234567', + 'at': 3, + 'bidfloor': 25, + 'bidfloorcur': 'USD', + 'ext': { + 'must_bid': 1, + 'private_auction': 1 + } + }, + { + 'id': '1234568', + 'at': 3, + 'bidfloor': 25, + 'bidfloorcur': 'USD', + 'ext': { + 'must_bid': 0 + } + } + ] + }); +}); if (FEATURES.VIDEO) { describe('buildRequests-video', function () { From 484ccee112e370c3b2b4119199a1f5b09a322800 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:51:15 -0700 Subject: [PATCH 09/10] refactor test file --- test/spec/modules/viantOrtbBidAdapter_spec.js | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/test/spec/modules/viantOrtbBidAdapter_spec.js b/test/spec/modules/viantOrtbBidAdapter_spec.js index 3121bd7a84f..d0d89e85818 100644 --- a/test/spec/modules/viantOrtbBidAdapter_spec.js +++ b/test/spec/modules/viantOrtbBidAdapter_spec.js @@ -1,8 +1,9 @@ -import { spec, converter } from 'modules/viantOrtbBidAdapter.js'; +import {spec, converter} from 'modules/viantOrtbBidAdapter.js'; import {assert, expect} from 'chai'; -import { deepClone } from '../../../src/utils'; +import {deepClone} from '../../../src/utils'; import {buildWindowTree} from '../../helpers/refererDetectionHelper'; import {detectReferer} from '../../../src/refererDetection'; + describe('viantOrtbBidAdapter', function () { function testBuildRequests(bidRequests, bidderRequestBase) { let clonedBidderRequest = deepClone(bidderRequestBase); @@ -10,7 +11,8 @@ describe('viantOrtbBidAdapter', function () { let requests = spec.buildRequests(bidRequests, clonedBidderRequest); return requests } - describe('isBidRequestValid', function() { + + describe('isBidRequestValid', function () { function makeBid() { return { 'bidder': 'viant', @@ -46,9 +48,7 @@ describe('viantOrtbBidAdapter', function () { it('should return true if placementId is not passed ', function () { let bid = makeBid(); delete bid.params.placementId; - bid.ortb2Imp = { - - } + bid.ortb2Imp = {} expect(spec.isBidRequestValid(bid)).to.equal(true); }); @@ -98,6 +98,7 @@ describe('viantOrtbBidAdapter', function () { 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' } } + it('should return true when required params found', function () { expect(spec.isBidRequestValid(makeBid())).to.equal(true); }); @@ -141,6 +142,7 @@ describe('viantOrtbBidAdapter', function () { 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' } } + it('should return true when required params found', function () { expect(spec.isBidRequestValid(makeBid())).to.equal(true); }); @@ -284,36 +286,35 @@ describe('viantOrtbBidAdapter', function () { const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest)[0].data; expect(requestBody.imp[0].banner.pos).to.equal(1); }); - }); - - it('includes the deals in the bid request', function () { - const requestBody = testBuildRequests(basePMPDealsBidRequests, baseBidderRequest)[0].data; - expect(requestBody.imp[0].pmp).to.be.not.null; - expect(requestBody.imp[0].pmp).to.deep.equal({ - 'private_auction': 0, - 'deals': [ - { - 'id': '1234567', - 'at': 3, - 'bidfloor': 25, - 'bidfloorcur': 'USD', - 'ext': { - 'must_bid': 1, - 'private_auction': 1 - } - }, - { - 'id': '1234568', - 'at': 3, - 'bidfloor': 25, - 'bidfloorcur': 'USD', - 'ext': { - 'must_bid': 0 + it('includes the deals in the bid request', function () { + const requestBody = testBuildRequests(basePMPDealsBidRequests, baseBidderRequest)[0].data; + expect(requestBody.imp[0].pmp).to.be.not.null; + expect(requestBody.imp[0].pmp).to.deep.equal({ + 'private_auction': 0, + 'deals': [ + { + 'id': '1234567', + 'at': 3, + 'bidfloor': 25, + 'bidfloorcur': 'USD', + 'ext': { + 'must_bid': 1, + 'private_auction': 1 + } + }, + { + 'id': '1234568', + 'at': 3, + 'bidfloor': 25, + 'bidfloorcur': 'USD', + 'ext': { + 'must_bid': 0 + } } - } - ] + ] + }); }); -}); + }); if (FEATURES.VIDEO) { describe('buildRequests-video', function () { From 23f4fcdebce6246ba904636e3e18d8f7482622f3 Mon Sep 17 00:00:00 2001 From: skapoorViant <153030693+skapoorViant@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:22:07 -0700 Subject: [PATCH 10/10] added test case and addressed suggestions --- modules/viantOrtbBidAdapter.js | 8 ++------ test/spec/modules/viantOrtbBidAdapter_spec.js | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index cdb5b06d272..b4448715f7a 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -88,12 +88,10 @@ function createRequest(bidRequests, bidderRequest, mediaType) { } let imp = data.imp || []; let dealsMap = new Map(); - let privateAuctions = new Map(); if (bidderRequest.bids) { bidderRequest.bids.forEach(bid => { - if (bid.params && bid.params.pmp) { - dealsMap.set(bid.bidId, bid.params.pmp); - privateAuctions.set(bid.bidId, bid.params.private_auction || 0); + if (bid.ortb2Imp && bid.ortb2Imp.pmp) { + dealsMap.set(bid.bidId, bid.ortb2Imp.pmp); } }); } @@ -102,8 +100,6 @@ function createRequest(bidRequests, bidderRequest, mediaType) { if (deals) { element.pmp = deals; } - element.pmp = element.pmp || {}; - element.pmp.private_auction = privateAuctions.get(element.id); }); data.ext = data.ext || {}; data.ext.viant = { diff --git a/test/spec/modules/viantOrtbBidAdapter_spec.js b/test/spec/modules/viantOrtbBidAdapter_spec.js index d0d89e85818..a289faf3573 100644 --- a/test/spec/modules/viantOrtbBidAdapter_spec.js +++ b/test/spec/modules/viantOrtbBidAdapter_spec.js @@ -186,8 +186,11 @@ describe('viantOrtbBidAdapter', function () { 'bidder': 'viant', 'params': { 'publisherId': '464', - 'placementId': '1', + 'placementId': '1' + }, + 'ortb2Imp': { 'pmp': { + 'private_auction': 0, 'deals': [ { 'id': '1234567', @@ -209,7 +212,7 @@ describe('viantOrtbBidAdapter', function () { } } ] - } + }, }, 'mediaTypes': { 'banner': {