From aa566a7e28797119391a1f61773f175cc886444d Mon Sep 17 00:00:00 2001 From: Kirill Davidenko Date: Tue, 19 Dec 2017 17:19:28 +0200 Subject: [PATCH 01/10] VI prebid.js adapter (points dev platform) --- modules/viBidAdapter.js | 71 +++++++++++++++++++++++++++++++++++++++++ modules/viBidAdapter.md | 18 +++++++++++ 2 files changed, 89 insertions(+) create mode 100644 modules/viBidAdapter.js create mode 100644 modules/viBidAdapter.md diff --git a/modules/viBidAdapter.js b/modules/viBidAdapter.js new file mode 100644 index 00000000000..ae6dabcb6ed --- /dev/null +++ b/modules/viBidAdapter.js @@ -0,0 +1,71 @@ +import * as utils from 'src/utils'; +import { registerBidder } from 'src/adapters/bidderFactory'; +import { BANNER } from 'src/mediaTypes'; + +const BIDDER_CODE = 'vi'; +const SUPPORTED_MEDIA_TYPES = [BANNER]; + +function isBidRequestValid(bid) { + return !!(bid.params.pubid); +} + +function buildRequests(bidReqs) { + let imps = []; + utils._each(bidReqs, function (bid) { + imps.push({ + id: bid.bidId, + sizes: bid.sizes, + bidFloor: parseFloat(bid.params.bidFloor) > 0 ? bid.params.bidFloor : 0 + }); + }); + + const bidRequest = { + id: bidReqs[0].requestId, + imps: imps, + publisherId: utils.getBidIdParameter('pubId', bidReqs[0].params), + siteId: utils.getBidIdParameter('siteId', bidReqs[0].params), + cat: utils.getBidIdParameter('cat', bidReqs[0].params), + language: utils.getBidIdParameter('lang', bidReqs[0].params), + domain: utils.getTopWindowLocation().hostname, + page: utils.getTopWindowUrl(), + referrer: utils.getTopWindowReferrer() + }; + return { + method: 'POST', + url: `//smartbuy-dev-bidder.vidint.net/prebid/bid`, + data: JSON.stringify(bidRequest), + options: {contentType: 'application/json', withCredentials: false} + }; +} + +function interpretResponse(bids) { + let responses = []; + utils._each(bids.body, function(bid) { + responses.push({ + requestId: bid.id, + cpm: parseFloat(bid.price), + width: parseInt(bid.width), + height: parseInt(bid.height), + creativeId: bid.creativeId, + dealId: bid.dealId || null, + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: decodeURIComponent(`${bid.ad}`), + ttl: 60000 + }); + }); + return responses; +} + +const spec = { + code: BIDDER_CODE, + supportedMediaTypes: SUPPORTED_MEDIA_TYPES, + isBidRequestValid, + buildRequests, + interpretResponse +} + +registerBidder(spec); + +module.exports = spec; diff --git a/modules/viBidAdapter.md b/modules/viBidAdapter.md new file mode 100644 index 00000000000..bce727c4d1e --- /dev/null +++ b/modules/viBidAdapter.md @@ -0,0 +1,18 @@ +# Overview + +``` +Module Name: VI Bid Adapter +Module Type: Bidder Adapter +Maintainer: kd@vi.ai +``` + +# Description + +Video Intelligence AG adapter integration to the Prebid library. +Connects to VI demand source. + +# Test Parameters + +``` +TBD +``` From 3a4d3947b34aeec5998a2ba5201824b146df128c Mon Sep 17 00:00:00 2001 From: Kirill Davidenko Date: Tue, 19 Dec 2017 17:43:58 +0200 Subject: [PATCH 02/10] fix typo --- modules/viBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/viBidAdapter.js b/modules/viBidAdapter.js index ae6dabcb6ed..9d50f383a4a 100644 --- a/modules/viBidAdapter.js +++ b/modules/viBidAdapter.js @@ -6,7 +6,7 @@ const BIDDER_CODE = 'vi'; const SUPPORTED_MEDIA_TYPES = [BANNER]; function isBidRequestValid(bid) { - return !!(bid.params.pubid); + return !!(bid.params.pubId); } function buildRequests(bidReqs) { From eba2584eed798c127decc3519edfd86e1ba26187 Mon Sep 17 00:00:00 2001 From: Yurii Chernenko Date: Tue, 19 Dec 2017 18:25:45 +0200 Subject: [PATCH 03/10] Changed maintainer email --- modules/viBidAdapter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/viBidAdapter.md b/modules/viBidAdapter.md index bce727c4d1e..7f47bc1519f 100644 --- a/modules/viBidAdapter.md +++ b/modules/viBidAdapter.md @@ -3,7 +3,7 @@ ``` Module Name: VI Bid Adapter Module Type: Bidder Adapter -Maintainer: kd@vi.ai +Maintainer: support@vi.ai ``` # Description From 6e1df2cd3f6f4f0bec5bd1c9fdff30e6a1854617 Mon Sep 17 00:00:00 2001 From: Yurii Chernenko Date: Wed, 20 Dec 2017 17:27:02 +0200 Subject: [PATCH 04/10] Added test parameters --- modules/viBidAdapter.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/viBidAdapter.md b/modules/viBidAdapter.md index 7f47bc1519f..b68069a1a7b 100644 --- a/modules/viBidAdapter.md +++ b/modules/viBidAdapter.md @@ -14,5 +14,27 @@ Connects to VI demand source. # Test Parameters ``` -TBD +var adUnits = [{ + code: 'div-0', + sizes: [[320, 480], [480, 320]], + bids: [{ + bidder: 'vi', + params: { + pubId: 'sb_test', + lang: 'en-US', + cat: 'IAB1' + } + }] +}, { + code: 'div-1', + sizes: [[320, 480]], + bids: [{ + bidder: 'vi', + params: { + pubId: 'sb_test', + lang: 'en-US', + cat: 'IAB25-3' + } + }] +}]; ``` From e11a69266cd994eb2853e340025b7427f34d1c3c Mon Sep 17 00:00:00 2001 From: Yurii Chernenko Date: Fri, 5 Jan 2018 13:23:45 +0200 Subject: [PATCH 05/10] Changed bidder hostname to pb.vi-serve.com --- modules/viBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/viBidAdapter.js b/modules/viBidAdapter.js index 9d50f383a4a..99051365b6d 100644 --- a/modules/viBidAdapter.js +++ b/modules/viBidAdapter.js @@ -32,7 +32,7 @@ function buildRequests(bidReqs) { }; return { method: 'POST', - url: `//smartbuy-dev-bidder.vidint.net/prebid/bid`, + url: `//pb.vi-serve.com/prebid/bid`, data: JSON.stringify(bidRequest), options: {contentType: 'application/json', withCredentials: false} }; From c258dee68be3a631084f03d9aa20b6cedcf4e4e9 Mon Sep 17 00:00:00 2001 From: Kirill Davidenko Date: Fri, 5 Jan 2018 14:48:33 +0200 Subject: [PATCH 06/10] updated doc --- modules/viBidAdapter.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/viBidAdapter.md b/modules/viBidAdapter.md index b68069a1a7b..2744e1fbd4e 100644 --- a/modules/viBidAdapter.md +++ b/modules/viBidAdapter.md @@ -10,31 +10,32 @@ Maintainer: support@vi.ai Video Intelligence AG adapter integration to the Prebid library. Connects to VI demand source. +There should preferably be only one Ad Unit with VI bid adapter on the single page. # Test Parameters ``` var adUnits = [{ code: 'div-0', - sizes: [[320, 480], [480, 320]], - bids: [{ - bidder: 'vi', - params: { - pubId: 'sb_test', - lang: 'en-US', - cat: 'IAB1' - } - }] -}, { - code: 'div-1', sizes: [[320, 480]], bids: [{ bidder: 'vi', params: { pubId: 'sb_test', lang: 'en-US', - cat: 'IAB25-3' + cat: 'IAB1', + bidFloor: 0.05 //optional } }] }]; ``` + +# Parameters + +| Name | Scope | Description | Example | +| :------------ | :------- | :---------------------------------------------- | :--------------------------------- | +| `pubId` | required | Publisher ID, provided by VI | 'sb_test' | +| `lang` | required | Ad language, in ISO 639-1 language code format | 'en-US', 'es-ES', 'de' | +| `cat` | required | Ad IAB category (top-level or subcategory), single one supported | 'IAB1', 'IAB9-1' | +| `bidFloor` | optional | Lowest value of expected bid price | 0.001 | + From 429ac86d4eeca6a96d70a0b2cab4494b668b140e Mon Sep 17 00:00:00 2001 From: perwic <7835515+perwic@users.noreply.github.com> Date: Tue, 9 Jan 2018 10:31:34 +0100 Subject: [PATCH 07/10] Update viBidAdapter.md --- modules/viBidAdapter.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/viBidAdapter.md b/modules/viBidAdapter.md index 2744e1fbd4e..23288024fcc 100644 --- a/modules/viBidAdapter.md +++ b/modules/viBidAdapter.md @@ -1,16 +1,16 @@ # Overview ``` -Module Name: VI Bid Adapter -Module Type: Bidder Adapter +Module Name: vi bid adapter +Module Type: Bidder adapter Maintainer: support@vi.ai ``` # Description -Video Intelligence AG adapter integration to the Prebid library. -Connects to VI demand source. -There should preferably be only one Ad Unit with VI bid adapter on the single page. +The video intelligence (vi) adapter integration to the Prebid library. +Connects to vi’s demand sources. +There should be only one ad unit with vi bid adapter on each single page. # Test Parameters @@ -34,7 +34,7 @@ var adUnits = [{ | Name | Scope | Description | Example | | :------------ | :------- | :---------------------------------------------- | :--------------------------------- | -| `pubId` | required | Publisher ID, provided by VI | 'sb_test' | +| `pubId` | required | Publisher ID, provided by vi | 'sb_test' | | `lang` | required | Ad language, in ISO 639-1 language code format | 'en-US', 'es-ES', 'de' | | `cat` | required | Ad IAB category (top-level or subcategory), single one supported | 'IAB1', 'IAB9-1' | | `bidFloor` | optional | Lowest value of expected bid price | 0.001 | From 80b99512eefa72d29a7dd8de3baeb8fa07ddbb66 Mon Sep 17 00:00:00 2001 From: Kirill Davidenko Date: Tue, 9 Jan 2018 15:32:02 +0200 Subject: [PATCH 08/10] VI bid adapter - tests --- modules/viBidAdapter.js | 4 +- test/spec/modules/viBidAdapter_spec.js | 111 +++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 test/spec/modules/viBidAdapter_spec.js diff --git a/modules/viBidAdapter.js b/modules/viBidAdapter.js index 99051365b6d..aea3d74d9a3 100644 --- a/modules/viBidAdapter.js +++ b/modules/viBidAdapter.js @@ -58,7 +58,7 @@ function interpretResponse(bids) { return responses; } -const spec = { +export const spec = { code: BIDDER_CODE, supportedMediaTypes: SUPPORTED_MEDIA_TYPES, isBidRequestValid, @@ -67,5 +67,3 @@ const spec = { } registerBidder(spec); - -module.exports = spec; diff --git a/test/spec/modules/viBidAdapter_spec.js b/test/spec/modules/viBidAdapter_spec.js new file mode 100644 index 00000000000..00c065361cc --- /dev/null +++ b/test/spec/modules/viBidAdapter_spec.js @@ -0,0 +1,111 @@ +import { expect } from 'chai'; +import { spec } from 'modules/viBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; +import { REPO_AND_VERSION } from 'src/constants'; + +const ENDPOINT = `//pb.vi-serve.com/prebid/bid`; + +describe('viBidAdapter', function() { + const adapter = newBidder(spec); + + describe('isBidRequestValid', () => { + let bid = { + 'bidder': 'vi', + 'params': { + 'pubId': 'sb_test', + 'lang': 'en-US', + 'cat': 'IAB1', + 'bidFloor': 0.05 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [320, 480] + ], + 'bidId': '29b891ad542377', + 'bidderRequestId': '1dc9a08206a57b', + 'requestId': '24176695-e3f0-44db-815b-ed97cf5ad49b', + 'placementCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': '474da635-9cf0-4188-a3d9-58961be8f905' + }; + + it('should return true when required params found', () => { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when pubId not passed', () => { + bid.params.pubId = undefined; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', () => { + let bidRequests = [{ + 'bidder': 'vi', + 'params': { + 'pubId': 'sb_test', + 'lang': 'en-US', + 'cat': 'IAB1', + 'bidFloor': 0.05 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [320, 480] + ], + 'bidId': '29b891ad542377', + 'bidderRequestId': '1dc9a08206a57b', + 'requestId': '24176695-e3f0-44db-815b-ed97cf5ad49b', + 'placementCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': '474da635-9cf0-4188-a3d9-58961be8f905' + }]; + + const request = spec.buildRequests(bidRequests); + + it('POST bid request to vi', () => { + expect(request.method).to.equal('POST'); + }); + + it('check endpoint URL', () => { + expect(request.url).to.equal(ENDPOINT) + }); + }); + + describe('interpretResponse', () => { + let response = { + body: [{ + 'id': '29b891ad542377', + 'price': 0.1, + 'width': 320, + 'height': 480, + 'ad': '', + 'creativeId': 'dZsPGv' + }] + }; + + it('should get the correct bid response', () => { + let expectedResponse = [{ + 'requestId': '29b891ad542377', + 'cpm': 0.1, + 'width': 320, + 'height': 480, + 'creativeId': 'dZsPGv', + 'dealId': null, + 'currency': 'USD', + 'netRevenue': true, + 'mediaType': 'banner', + 'ad': decodeURIComponent(``), + 'ttl': 60000 + }]; + + let result = spec.interpretResponse(response); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + }); + + it('handles empty bid response', () => { + let response = { + body: [] + }; + let result = spec.interpretResponse(response); + expect(result.length).to.equal(0); + }); + }); +}); From 977fb3cc7690418d57f6dcb6e71a0efa6db6eb0e Mon Sep 17 00:00:00 2001 From: Kirill Davidenko Date: Thu, 18 Jan 2018 11:00:04 +0200 Subject: [PATCH 09/10] Removed unused import from spec, specified radix in parseInt --- modules/viBidAdapter.js | 4 ++-- test/spec/modules/viBidAdapter_spec.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/viBidAdapter.js b/modules/viBidAdapter.js index aea3d74d9a3..629a2a5ceca 100644 --- a/modules/viBidAdapter.js +++ b/modules/viBidAdapter.js @@ -44,8 +44,8 @@ function interpretResponse(bids) { responses.push({ requestId: bid.id, cpm: parseFloat(bid.price), - width: parseInt(bid.width), - height: parseInt(bid.height), + width: parseInt(bid.width, 10), + height: parseInt(bid.height, 10), creativeId: bid.creativeId, dealId: bid.dealId || null, currency: 'USD', diff --git a/test/spec/modules/viBidAdapter_spec.js b/test/spec/modules/viBidAdapter_spec.js index 00c065361cc..ab172a9c53e 100644 --- a/test/spec/modules/viBidAdapter_spec.js +++ b/test/spec/modules/viBidAdapter_spec.js @@ -1,12 +1,11 @@ import { expect } from 'chai'; import { spec } from 'modules/viBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -import { REPO_AND_VERSION } from 'src/constants'; const ENDPOINT = `//pb.vi-serve.com/prebid/bid`; describe('viBidAdapter', function() { - const adapter = newBidder(spec); + newBidder(spec); describe('isBidRequestValid', () => { let bid = { From c6c9ac564b851c350716a883f723514d9f0abf01 Mon Sep 17 00:00:00 2001 From: Kirill Davidenko Date: Fri, 19 Jan 2018 15:13:20 +0200 Subject: [PATCH 10/10] handling of various sizes formats --- modules/viBidAdapter.js | 2 +- test/spec/modules/viBidAdapter_spec.js | 29 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/viBidAdapter.js b/modules/viBidAdapter.js index 629a2a5ceca..bcfc4e246ac 100644 --- a/modules/viBidAdapter.js +++ b/modules/viBidAdapter.js @@ -14,7 +14,7 @@ function buildRequests(bidReqs) { utils._each(bidReqs, function (bid) { imps.push({ id: bid.bidId, - sizes: bid.sizes, + sizes: utils.parseSizesInput(bid.sizes).map(size => size.split('x')), bidFloor: parseFloat(bid.params.bidFloor) > 0 ? bid.params.bidFloor : 0 }); }); diff --git a/test/spec/modules/viBidAdapter_spec.js b/test/spec/modules/viBidAdapter_spec.js index ab172a9c53e..e8b0fbcc4b2 100644 --- a/test/spec/modules/viBidAdapter_spec.js +++ b/test/spec/modules/viBidAdapter_spec.js @@ -68,6 +68,35 @@ describe('viBidAdapter', function() { }); }); + describe('buildRequests can handle size in 1-dim array', () => { + let bidRequests = [{ + 'bidder': 'vi', + 'params': { + 'pubId': 'sb_test', + 'lang': 'en-US', + 'cat': 'IAB1', + 'bidFloor': 0.05 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [320, 480], + 'bidId': '29b891ad542377', + 'bidderRequestId': '1dc9a08206a57b', + 'requestId': '24176695-e3f0-44db-815b-ed97cf5ad49b', + 'placementCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': '474da635-9cf0-4188-a3d9-58961be8f905' + }]; + + const request = spec.buildRequests(bidRequests); + + it('POST bid request to vi', () => { + expect(request.method).to.equal('POST'); + }); + + it('check endpoint URL', () => { + expect(request.url).to.equal(ENDPOINT) + }); + }); + describe('interpretResponse', () => { let response = { body: [{