From d1cf0a6967bd26cf7eac393d2d1485c58315df03 Mon Sep 17 00:00:00 2001 From: Udi Talias Date: Thu, 19 Mar 2020 14:46:52 +0200 Subject: [PATCH 1/5] feat(module): multi size request --- modules/vidazooBidAdapter.js | 94 ++++++++++++--------- package-lock.json | 2 +- test/spec/modules/vidazooBidAdapter_spec.js | 61 ++++++------- 3 files changed, 77 insertions(+), 80 deletions(-) diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index b3ab8a4d275..dd7af53207f 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -1,6 +1,7 @@ import * as utils from '../src/utils.js'; -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {BANNER} from '../src/mediaTypes.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { BANNER } from '../src/mediaTypes.js'; + export const URL = 'https://prebid.cootlogix.com'; const BIDDER_CODE = 'vidazoo'; const CURRENCY = 'USD'; @@ -19,25 +20,29 @@ function isBidRequestValid(bid) { return !!(params.cId && params.pId); } -function buildRequest(bid, topWindowUrl, size, bidderRequest) { - const {params, bidId} = bid; - const {bidFloor, cId, pId, ext} = params; - // Prebid's util function returns AppNexus style sizes (i.e. 300x250) - const [width, height] = size.split('x'); - - const dto = { - method: 'GET', - url: `${URL}/prebid/${cId}`, - data: { - url: encodeURIComponent(topWindowUrl), - cb: Date.now(), - bidFloor: bidFloor, - bidId: bidId, - publisherId: pId, - consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString, - width, - height +function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { + const { params, bidId } = bid; + const { bidFloor, cId, pId, ext } = params; + let data = { + url: encodeURIComponent(topWindowUrl), + cb: Date.now(), + bidFloor: bidFloor, + bidId: bidId, + publisherId: pId, + sizes: sizes, + }; + if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent.consentString) { + data.gdprConsent = bidderRequest.gdprConsent.consentString; } + if (bidderRequest.gdprConsent.gdprApplies !== undefined) { + data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; + } + } + const dto = { + method: 'POST', + url: `${URL}/prebid/multi/${cId}`, + data: data }; utils._each(ext, (value, key) => { @@ -52,10 +57,8 @@ function buildRequests(validBidRequests, bidderRequest) { const requests = []; validBidRequests.forEach(validBidRequest => { const sizes = utils.parseSizesInput(validBidRequest.sizes); - sizes.forEach(size => { - const request = buildRequest(validBidRequest, topWindowUrl, size, bidderRequest); - requests.push(request); - }); + const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest); + requests.push(request); }); return requests; } @@ -64,30 +67,37 @@ function interpretResponse(serverResponse, request) { if (!serverResponse || !serverResponse.body) { return []; } - const {creativeId, ad, price, exp} = serverResponse.body; - if (!ad || !price) { - return []; - } - const {bidId, width, height} = request.data; + const { bidId } = request.data; + const { results } = serverResponse.body; + + let output = []; + try { - return [{ - requestId: bidId, - cpm: price, - width: width, - height: height, - creativeId: creativeId, - currency: CURRENCY, - netRevenue: true, - ttl: exp || TTL_SECONDS, - ad: ad - }]; + results.forEach(result => { + const { creativeId, ad, price, exp, width, height, currency } = result; + if (!ad || !price) { + return; + } + output.push({ + requestId: bidId, + cpm: price, + width: width, + height: height, + creativeId: creativeId, + currency: currency || CURRENCY, + netRevenue: true, + ttl: exp || TTL_SECONDS, + ad: ad + }) + }); + return output; } catch (e) { return []; } } function getUserSyncs(syncOptions, responses) { - const {iframeEnabled, pixelEnabled} = syncOptions; + const { iframeEnabled, pixelEnabled } = syncOptions; if (iframeEnabled) { return [{ @@ -100,7 +110,7 @@ function getUserSyncs(syncOptions, responses) { const lookup = {}; const syncs = []; responses.forEach(response => { - const {body} = response; + const { body } = response; const cookies = body ? body.cookies || [] : []; cookies.forEach(cookie => { switch (cookie.type) { diff --git a/package-lock.json b/package-lock.json index 2a9d671e441..a4d4a3ac194 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "3.12.0", + "version": "3.13.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/spec/modules/vidazooBidAdapter_spec.js b/test/spec/modules/vidazooBidAdapter_spec.js index 755295c7bd6..52c7388c30b 100644 --- a/test/spec/modules/vidazooBidAdapter_spec.js +++ b/test/spec/modules/vidazooBidAdapter_spec.js @@ -1,5 +1,5 @@ -import {expect} from 'chai'; -import {spec as adapter, URL} from 'modules/vidazooBidAdapter.js'; +import { expect } from 'chai'; +import { spec as adapter, URL } from 'modules/vidazooBidAdapter.js'; import * as utils from 'src/utils.js'; const BID = { @@ -31,16 +31,20 @@ const BIDDER_REQUEST = { const SERVER_RESPONSE = { body: { - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' + results: [{ + 'ad': '', + 'price': 0.8, + 'creativeId': '12610997325162499419', + 'exp': 30, + width: 300, + height: 250, + 'cookies': [{ + 'src': 'https://sync.com', + 'type': 'iframe' + }, { + 'src': 'https://sync.com', + 'type': 'img' + }] }] } }; @@ -119,30 +123,13 @@ describe('VidazooBidAdapter', function () { it('should build request for each size', function () { const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(2); + expect(requests).to.have.length(1); expect(requests[0]).to.deep.equal({ - method: 'GET', - url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`, + method: 'POST', + url: `${URL}/prebid/multi/59db6b3b4ffaa70004f45cdc`, data: { - consent: 'consent_string', - width: '300', - height: '250', - url: 'https%3A%2F%2Fwww.greatsite.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - publisherId: '59ac17c192832d0011283fe3', - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - } - }); - expect(requests[1]).to.deep.equal({ - method: 'GET', - url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`, - data: { - consent: 'consent_string', - width: '300', - height: '600', + gdprConsent: 'consent_string', + sizes: ['300x250', '300x600'], url: 'https%3A%2F%2Fwww.greatsite.com', cb: 1000, bidFloor: 0.1, @@ -166,12 +153,12 @@ describe('VidazooBidAdapter', function () { }); it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); + const responses = adapter.interpretResponse({ price: 1, ad: '' }); expect(responses).to.be.empty; }); it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); + const responses = adapter.interpretResponse({ price: null, ad: 'great ad' }); expect(responses).to.be.empty; }); @@ -193,7 +180,7 @@ describe('VidazooBidAdapter', function () { it('should take default TTL', function () { const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.exp; + delete serverResponse.body.results[0].exp; const responses = adapter.interpretResponse(serverResponse, REQUEST); expect(responses).to.have.length(1); expect(responses[0].ttl).to.equal(300); From 1f9521d090fe556e16f4c9dd98932bccdf1f1423 Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 24 Mar 2020 12:10:24 +0200 Subject: [PATCH 2/5] fix getUserSyncs added tests --- modules/vidazooBidAdapter.js | 32 +++++++++---------- test/spec/modules/vidazooBidAdapter_spec.js | 35 ++++++++++++++++----- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index dd7af53207f..d974c0e1eb7 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -1,6 +1,6 @@ import * as utils from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER } from '../src/mediaTypes.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {BANNER} from '../src/mediaTypes.js'; export const URL = 'https://prebid.cootlogix.com'; const BIDDER_CODE = 'vidazoo'; @@ -21,8 +21,8 @@ function isBidRequestValid(bid) { } function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { - const { params, bidId } = bid; - const { bidFloor, cId, pId, ext } = params; + const {params, bidId} = bid; + const {bidFloor, cId, pId, ext} = params; let data = { url: encodeURIComponent(topWindowUrl), cb: Date.now(), @@ -67,14 +67,14 @@ function interpretResponse(serverResponse, request) { if (!serverResponse || !serverResponse.body) { return []; } - const { bidId } = request.data; - const { results } = serverResponse.body; + const {bidId} = request.data; + const {results} = serverResponse.body; let output = []; try { results.forEach(result => { - const { creativeId, ad, price, exp, width, height, currency } = result; + const {creativeId, ad, price, exp, width, height, currency} = result; if (!ad || !price) { return; } @@ -97,7 +97,7 @@ function interpretResponse(serverResponse, request) { } function getUserSyncs(syncOptions, responses) { - const { iframeEnabled, pixelEnabled } = syncOptions; + const {iframeEnabled, pixelEnabled} = syncOptions; if (iframeEnabled) { return [{ @@ -110,21 +110,19 @@ function getUserSyncs(syncOptions, responses) { const lookup = {}; const syncs = []; responses.forEach(response => { - const { body } = response; - const cookies = body ? body.cookies || [] : []; - cookies.forEach(cookie => { - switch (cookie.type) { - case INTERNAL_SYNC_TYPE.IFRAME: - break; - case INTERNAL_SYNC_TYPE.IMAGE: + const {body} = response; + const results = body ? body.results || [] : []; + results.forEach(result => { + (result.cookies || []).forEach(cookie => { + if (cookie.type === INTERNAL_SYNC_TYPE.IMAGE) { if (pixelEnabled && !lookup[cookie.src]) { syncs.push({ type: EXTERNAL_SYNC_TYPE.IMAGE, url: cookie.src }); } - break; - } + } + }); }); }); return syncs; diff --git a/test/spec/modules/vidazooBidAdapter_spec.js b/test/spec/modules/vidazooBidAdapter_spec.js index 52c7388c30b..a52669b773b 100644 --- a/test/spec/modules/vidazooBidAdapter_spec.js +++ b/test/spec/modules/vidazooBidAdapter_spec.js @@ -1,5 +1,5 @@ -import { expect } from 'chai'; -import { spec as adapter, URL } from 'modules/vidazooBidAdapter.js'; +import {expect} from 'chai'; +import {spec as adapter, URL} from 'modules/vidazooBidAdapter.js'; import * as utils from 'src/utils.js'; const BID = { @@ -22,7 +22,8 @@ const BID = { const BIDDER_REQUEST = { 'gdprConsent': { - 'consentString': 'consent_string' + 'consentString': 'consent_string', + 'gdprApplies': true }, 'refererInfo': { 'referer': 'https://www.greatsite.com' @@ -36,8 +37,8 @@ const SERVER_RESPONSE = { 'price': 0.8, 'creativeId': '12610997325162499419', 'exp': 30, - width: 300, - height: 250, + 'width': 300, + 'height': 250, 'cookies': [{ 'src': 'https://sync.com', 'type': 'iframe' @@ -129,6 +130,7 @@ describe('VidazooBidAdapter', function () { url: `${URL}/prebid/multi/59db6b3b4ffaa70004f45cdc`, data: { gdprConsent: 'consent_string', + gdpr: 1, sizes: ['300x250', '300x600'], url: 'https%3A%2F%2Fwww.greatsite.com', cb: 1000, @@ -145,6 +147,25 @@ describe('VidazooBidAdapter', function () { sandbox.restore(); }); }); + describe('getUserSyncs', function () { + it('should have valid user sync with iframeEnabled', function () { + const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); + + expect(result).to.deep.equal([{ + type: 'iframe', + url: 'https://static.cootlogix.com/basev/sync/user_sync.html' + }]); + }); + + it('should have valid user sync with pixelEnabled', function () { + const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); + + expect(result).to.deep.equal([{ + 'url': 'https://sync.com', + 'type': 'image' + }]); + }) + }); describe('interpret response', function () { it('should return empty array when there is no response', function () { @@ -153,12 +174,12 @@ describe('VidazooBidAdapter', function () { }); it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({ price: 1, ad: '' }); + const responses = adapter.interpretResponse({price: 1, ad: ''}); expect(responses).to.be.empty; }); it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({ price: null, ad: 'great ad' }); + const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); expect(responses).to.be.empty; }); From 8c23b90eb45e98a5f201be7b2016807b7f2f79ce Mon Sep 17 00:00:00 2001 From: Udi Talias Date: Tue, 24 Mar 2020 18:53:35 +0200 Subject: [PATCH 3/5] update(module): package-lock.json from master --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index a4d4a3ac194..2a9d671e441 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "3.13.0-pre", + "version": "3.12.0", "lockfileVersion": 1, "requires": true, "dependencies": { From f278843111fc46c07301d936c57ba150c89e218f Mon Sep 17 00:00:00 2001 From: Udi Talias Date: Sun, 12 Apr 2020 16:45:10 +0300 Subject: [PATCH 4/5] feat(module): add usp consent support --- modules/vidazooBidAdapter.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index d974c0e1eb7..0880b115c70 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -39,6 +39,9 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; } } + if (bidderRequest.uspConsent) { + data.usPrivacy = bidderRequest.uspConsent + } const dto = { method: 'POST', url: `${URL}/prebid/multi/${cId}`, From d9d723603bd43d8a6173cd5cbfb511d2e88eb8fe Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 12 May 2020 14:52:50 +0300 Subject: [PATCH 5/5] added uspConsent test --- test/spec/modules/vidazooBidAdapter_spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/spec/modules/vidazooBidAdapter_spec.js b/test/spec/modules/vidazooBidAdapter_spec.js index a52669b773b..0c9867cbe9c 100644 --- a/test/spec/modules/vidazooBidAdapter_spec.js +++ b/test/spec/modules/vidazooBidAdapter_spec.js @@ -25,6 +25,7 @@ const BIDDER_REQUEST = { 'consentString': 'consent_string', 'gdprApplies': true }, + 'uspConsent': 'consent_string', 'refererInfo': { 'referer': 'https://www.greatsite.com' } @@ -131,6 +132,7 @@ describe('VidazooBidAdapter', function () { data: { gdprConsent: 'consent_string', gdpr: 1, + usPrivacy: 'consent_string', sizes: ['300x250', '300x600'], url: 'https%3A%2F%2Fwww.greatsite.com', cb: 1000,