From 3ebf710018bb095647ea025c7f9e03b7c0b2a5d2 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Tue, 20 Apr 2021 16:33:55 +0200 Subject: [PATCH 1/5] RTD Provider rebase --- modules/adnuntiusRtdProvider.js | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 modules/adnuntiusRtdProvider.js diff --git a/modules/adnuntiusRtdProvider.js b/modules/adnuntiusRtdProvider.js new file mode 100644 index 00000000000..137417106ff --- /dev/null +++ b/modules/adnuntiusRtdProvider.js @@ -0,0 +1,85 @@ +import { getGlobal } from '../src/prebidGlobal.js'; +import { submodule } from '../src/hook.js' +import { logMessage } from '../src/utils.js' +import { ajax } from '../src/ajax.js'; + +const tzo = new Date().getTimezoneOffset(); +let SEGMENT_LIST = [] +const ADN_USER_ID = JSON.parse(window.localStorage.getItem('adn.data')).browserId +const ADN_URL = 'https://data.adnuntius.com/usr?tzo=' + tzo + '&browserId=' + ADN_USER_ID + '&folderId='; +function init(config, userConsent) { + return true; +} + +const providers = { + adnuntius: { + url: 'https://data.adnuntius.com/usr?tzo=' + tzo + '&browserId=' + ADN_USER_ID + '&folderId=', + function: function (res) { + logMessage(res) + return res + }, + }, + novatiq: { + url: 'https://novatiq.consumor.io/segments/v1/novademo/45340f6d-d9ee-4ee9-b785-36f3e30ff1599999', + function: function (res) { + logMessage(res) + return res + }, + } +} + +function prepProvider(provider) { + return new Promise((resolve, reject) => { + ajax(providers[provider].url, { + success: function (res) { resolve(providers[provider].function(res)) }, + error: function (err) { reject(err) } + }) + }); +} + +function alterBidRequests(reqBidsConfigObj, callback, config, userConsent) { + const pbjsG = getGlobal() + const params = config.params + const affectedBidders = (params.bidders) ? Object.keys(params.bidders).filter(function (bidder) { + return params.bidders[bidder] == true + }) : [] + const affectedProviders = (params.providers) ? Object.keys(params.providers).filter(function (provider) { + return params.providers[provider] + }) : [] + + logMessage('ADN: UID', pbjsG.getUserIds()) + logMessage('ADN: CONF:', config) + logMessage('ADN: CONF: reqbidconf', reqBidsConfigObj) + logMessage('ADN: Providers:', affectedProviders) + + Promise.all([prepProvider('novatiq')]).then((values) => { + logMessage('ADN: PROMISE', values); + }); + + ajax(ADN_URL + config.params.folderId, { + success: function (response, req) { + const segments = JSON.parse(response).segments + SEGMENT_LIST = [...SEGMENT_LIST, ...segments] + pbjsG.setBidderConfig({ + bidders: affectedBidders, + config: { + segments: SEGMENT_LIST + } + }); + callback(); + } + }); +} + +/** @type {RtdSubmodule} */ +export const adnuntiusSubmodule = { + name: 'adnuntius', + init: init, + getBidRequestData: alterBidRequests, +}; + +export function beforeInit() { + submodule('realTimeData', adnuntiusSubmodule); +} + +beforeInit(); From 3e3f3fbcb271d80347ddb1ca3d96420285cbfe71 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Tue, 20 Apr 2021 16:41:37 +0200 Subject: [PATCH 2/5] wrongly merged to master --- modules/adnuntiusRtdProvider.js | 85 --------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 modules/adnuntiusRtdProvider.js diff --git a/modules/adnuntiusRtdProvider.js b/modules/adnuntiusRtdProvider.js deleted file mode 100644 index 137417106ff..00000000000 --- a/modules/adnuntiusRtdProvider.js +++ /dev/null @@ -1,85 +0,0 @@ -import { getGlobal } from '../src/prebidGlobal.js'; -import { submodule } from '../src/hook.js' -import { logMessage } from '../src/utils.js' -import { ajax } from '../src/ajax.js'; - -const tzo = new Date().getTimezoneOffset(); -let SEGMENT_LIST = [] -const ADN_USER_ID = JSON.parse(window.localStorage.getItem('adn.data')).browserId -const ADN_URL = 'https://data.adnuntius.com/usr?tzo=' + tzo + '&browserId=' + ADN_USER_ID + '&folderId='; -function init(config, userConsent) { - return true; -} - -const providers = { - adnuntius: { - url: 'https://data.adnuntius.com/usr?tzo=' + tzo + '&browserId=' + ADN_USER_ID + '&folderId=', - function: function (res) { - logMessage(res) - return res - }, - }, - novatiq: { - url: 'https://novatiq.consumor.io/segments/v1/novademo/45340f6d-d9ee-4ee9-b785-36f3e30ff1599999', - function: function (res) { - logMessage(res) - return res - }, - } -} - -function prepProvider(provider) { - return new Promise((resolve, reject) => { - ajax(providers[provider].url, { - success: function (res) { resolve(providers[provider].function(res)) }, - error: function (err) { reject(err) } - }) - }); -} - -function alterBidRequests(reqBidsConfigObj, callback, config, userConsent) { - const pbjsG = getGlobal() - const params = config.params - const affectedBidders = (params.bidders) ? Object.keys(params.bidders).filter(function (bidder) { - return params.bidders[bidder] == true - }) : [] - const affectedProviders = (params.providers) ? Object.keys(params.providers).filter(function (provider) { - return params.providers[provider] - }) : [] - - logMessage('ADN: UID', pbjsG.getUserIds()) - logMessage('ADN: CONF:', config) - logMessage('ADN: CONF: reqbidconf', reqBidsConfigObj) - logMessage('ADN: Providers:', affectedProviders) - - Promise.all([prepProvider('novatiq')]).then((values) => { - logMessage('ADN: PROMISE', values); - }); - - ajax(ADN_URL + config.params.folderId, { - success: function (response, req) { - const segments = JSON.parse(response).segments - SEGMENT_LIST = [...SEGMENT_LIST, ...segments] - pbjsG.setBidderConfig({ - bidders: affectedBidders, - config: { - segments: SEGMENT_LIST - } - }); - callback(); - } - }); -} - -/** @type {RtdSubmodule} */ -export const adnuntiusSubmodule = { - name: 'adnuntius', - init: init, - getBidRequestData: alterBidRequests, -}; - -export function beforeInit() { - submodule('realTimeData', adnuntiusSubmodule); -} - -beforeInit(); From 962542ba05e6f03af46ddabd58eb9df7fd3246da Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Mon, 26 Apr 2021 14:43:30 +0200 Subject: [PATCH 3/5] Added meta field for advertiser domains. --- modules/adnuntiusBidAdapter.js | 4 ++++ test/spec/modules/adnuntiusBidAdapter_spec.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index e5878ad047d..56f1bb02981 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -56,6 +56,10 @@ export const spec = { height: Number(bid.creativeHeight), creativeId: bid.creativeId, currency: (bid.bid) ? bid.bid.currency : 'EUR', + meta: { + advertiserDomains: (bid.destinationUrls.destination) ? [bid.destinationUrls.destination.split('/')[2]] : [] + + }, netRevenue: false, ttl: 360, ad: adUnit.html diff --git a/test/spec/modules/adnuntiusBidAdapter_spec.js b/test/spec/modules/adnuntiusBidAdapter_spec.js index 44afa5c59e4..d234a345b5c 100644 --- a/test/spec/modules/adnuntiusBidAdapter_spec.js +++ b/test/spec/modules/adnuntiusBidAdapter_spec.js @@ -123,6 +123,9 @@ describe('adnuntiusBidAdapter', function () { expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId); expect(interpretedResponse[0].currency).to.equal(ad.bid.currency); expect(interpretedResponse[0].netRevenue).to.equal(false); + expect(interpretedResponse[0].meta).to.have.property('advertiserDomains'); + expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(1); + expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('google.com'); expect(interpretedResponse[0].ad).to.equal(serverResponse.body.adUnits[0].html); expect(interpretedResponse[0].ttl).to.equal(360); }); From 4b74d59b5860f61f3dec27f028aef98249a975af Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Tue, 27 Apr 2021 15:36:59 +0200 Subject: [PATCH 4/5] Fixing bug where losing bids throw undefined into the response. --- modules/adnuntiusBidAdapter.js | 8 ++++---- test/spec/modules/adnuntiusBidAdapter_spec.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index 56f1bb02981..700b7333079 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -68,10 +68,10 @@ export const spec = { } else return response }, {}); - const bidResponse = bidRequest.bid.map(bid => bid.bidId) - .reduce((request, adunitId) => - request.concat(bidResponsesById[adunitId]) - , []); + const bidResponse = bidRequest.bid.map(bid => bid.bidId).reduce((request, adunitId) => { + if (bidResponsesById[adunitId]) request.push(bidResponsesById[adunitId]) + return request + }, []); return bidResponse }, diff --git a/test/spec/modules/adnuntiusBidAdapter_spec.js b/test/spec/modules/adnuntiusBidAdapter_spec.js index d234a345b5c..62073fc6aaa 100644 --- a/test/spec/modules/adnuntiusBidAdapter_spec.js +++ b/test/spec/modules/adnuntiusBidAdapter_spec.js @@ -78,8 +78,15 @@ describe('adnuntiusBidAdapter', function () { 'lineItemId': 'scyjdyv3mzgdsnpf', 'layoutId': 'sw6gtws2rdj1kwby', 'layoutName': 'Responsive image' - } + }, + ] + }, + { + 'auId': '000000000008b6bc', + 'targetId': '456', + 'matchedAdCount': 0, + 'responseId': 'adn-rsp-1460129238', } ] } @@ -115,7 +122,6 @@ describe('adnuntiusBidAdapter', function () { it('should return valid response when passed valid server response', function () { const interpretedResponse = spec.interpretResponse(serverResponse, singleBidRequest); const ad = serverResponse.body.adUnits[0].ads[0] - expect(interpretedResponse).to.have.lengthOf(1); expect(interpretedResponse[0].cpm).to.equal(ad.cpm.amount); expect(interpretedResponse[0].width).to.equal(Number(ad.creativeWidth)); From 4af08dab9e0c2b48e0079dabf18f85ad86bdff07 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Tue, 27 Apr 2021 18:19:22 +0200 Subject: [PATCH 5/5] Wrapped if-statement --- modules/adnuntiusBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index 700b7333079..8752e37a96f 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -69,7 +69,7 @@ export const spec = { }, {}); const bidResponse = bidRequest.bid.map(bid => bid.bidId).reduce((request, adunitId) => { - if (bidResponsesById[adunitId]) request.push(bidResponsesById[adunitId]) + if (bidResponsesById[adunitId]) { request.push(bidResponsesById[adunitId]) } return request }, []);