From d6d4e3c58b0e29459fdf070b6dcc0bae27bf7f30 Mon Sep 17 00:00:00 2001 From: Geoffroy Hutin Date: Wed, 2 Jun 2021 10:06:23 +0000 Subject: [PATCH 1/3] audiencerun adapter : remove bid.adId, timeout pixel, gdpr version --- modules/audiencerunBidAdapter.js | 87 ++++++++++++++----- .../modules/audiencerunBidAdapter_spec.js | 6 ++ 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index b90471ee21a..0447784719f 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -4,10 +4,28 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; const BIDDER_CODE = 'audiencerun'; -const ENDPOINT_URL = 'https://d.audiencerun.com/prebid'; +const BASE_URL = 'https://d.audiencerun.com'; +const AUCTION_URL = `${BASE_URL}/prebid`; +const TIMEOUT_EVENT_URL = `${BASE_URL}/ps/pbtimeout`; + +let requestedBids = []; + +/** + * Get bidder request referer + * + * @param {Object} bidderRequest + * @return {string} + */ +function getPageUrl(bidderRequest) { + return ( + config.getConfig('pageUrl') || + utils.deepAccess(bidderRequest, 'refererInfo.referer') || + null + ); +} export const spec = { - version: '1.0.0', + version: '1.1.0', code: BIDDER_CODE, supportedMediaTypes: [BANNER], @@ -33,50 +51,53 @@ export const spec = { * @param {*} bidderRequest * @return {ServerRequest} Info describing the request to the server. */ - buildRequests: function(bidRequests, bidderRequest) { - const bids = bidRequests.map(bid => { + buildRequests: function (bidRequests, bidderRequest) { + const bids = bidRequests.map((bid) => { const sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes', []); return { zoneId: utils.getValue(bid.params, 'zoneId'), - sizes: sizes.map(size => ({ + sizes: sizes.map((size) => ({ w: size[0], - h: size[1] + h: size[1], })), bidfloor: bid.params.bidfloor || 0.0, bidId: bid.bidId, bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), adUnitCode: utils.getBidIdParameter('adUnitCode', bid), auctionId: utils.getBidIdParameter('auctionId', bid), - transactionId: utils.getBidIdParameter('transactionId', bid) + transactionId: utils.getBidIdParameter('transactionId', bid), }; }); const payload = { libVersion: this.version, - referer: bidderRequest.refererInfo ? bidderRequest.refererInfo.referer || null : null, + referer: getPageUrl(bidderRequest), currencyCode: config.getConfig('currency.adServerCurrency'), timeout: config.getConfig('bidderTimeout'), - bids + bids, }; if (bidderRequest && bidderRequest.gdprConsent) { payload.gdpr = { consent: bidderRequest.gdprConsent.consentString, - applies: bidderRequest.gdprConsent.gdprApplies + applies: bidderRequest.gdprConsent.gdprApplies, + version: bidderRequest.gdprConsent.apiVersion, }; } else { payload.gdpr = { - consent: '' - } + consent: '', + }; } + requestedBids = bids; + return { method: 'POST', - url: ENDPOINT_URL, + url: AUCTION_URL, data: JSON.stringify(payload), options: { - withCredentials: true - } + withCredentials: true, + }, }; }, @@ -100,10 +121,11 @@ export const spec = { // Common properties bid.requestId = bidObject.bidId; - bid.adId = bidObject.zoneId; bid.cpm = parseFloat(bidObject.cpm); bid.creativeId = bidObject.crid; - bid.currency = bidObject.currency ? bidObject.currency.toUpperCase() : 'USD'; + bid.currency = bidObject.currency + ? bidObject.currency.toUpperCase() + : 'USD'; bid.height = bidObject.h; bid.width = bidObject.w; @@ -122,21 +144,42 @@ export const spec = { * @param {ServerResponse[]} serverResponses List of server's responses. * @return {UserSync[]} The user syncs which should be dropped. */ - getUserSyncs: function(syncOptions, serverResponses) { + getUserSyncs: function (syncOptions, serverResponses) { if (!serverResponses || !serverResponses.length) return []; const syncs = []; - serverResponses.forEach(response => { - response.body.bid.forEach(bidObject => { + serverResponses.forEach((response) => { + response.body.bid.forEach((bidObject) => { syncs.push({ type: 'iframe', - url: bidObject.syncUrl + url: bidObject.syncUrl, }); }); }); return syncs; - } + }, + + /** + * Register bidder specific code, which will execute if bidder timed out after an auction + * + * @param {Array} timeoutData timeout specific data + */ + onTimeout: function (timeoutData) { + if (!utils.isArray(timeoutData)) { + return; + } + + timeoutData.forEach((bid) => { + const bidOnTimeout = requestedBids.find((requestedBid) => requestedBid.bidId === bid.bidId); + + if (bidOnTimeout) { + utils.triggerPixel( + `${TIMEOUT_EVENT_URL}/${bidOnTimeout.zoneId}/${bidOnTimeout.bidId}` + ); + } + }); + }, }; registerBidder(spec); diff --git a/test/spec/modules/audiencerunBidAdapter_spec.js b/test/spec/modules/audiencerunBidAdapter_spec.js index 826944abaf5..a0bdeb4043e 100644 --- a/test/spec/modules/audiencerunBidAdapter_spec.js +++ b/test/spec/modules/audiencerunBidAdapter_spec.js @@ -201,4 +201,10 @@ describe('AudienceRun bid adapter tests', function() { expect(syncs).to.deep.equal([{type: 'iframe', url: 'https://ac.audiencerun.com/f/sync.html'}]) }); }); + + describe('onTimeout', function () { + it('should exists and be a function', () => { + expect(spec.onTimeout).to.exist.and.to.be.a('function'); + }); + }); }); From 65c70b4dc79a3089f6edfc2f2aecb25e1eb967b0 Mon Sep 17 00:00:00 2001 From: Abdessalam Benharira Date: Mon, 7 Jun 2021 07:52:40 +0000 Subject: [PATCH 2/3] Audiencerun fix: handle advertiserDomains on meta object and remove adId from spec tests --- modules/audiencerunBidAdapter.js | 6 ++++++ test/spec/modules/audiencerunBidAdapter_spec.js | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index 0447784719f..b5f27257939 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -131,6 +131,12 @@ export const spec = { bid.width = bidObject.w; bid.netRevenue = bidObject.isNet ? bidObject.isNet : false; bid.ttl = 300; + bid.meta = { + advertiserDomains: + bidObject.adomain && Array.isArray(bidObject.adomain) + ? bidObject.adomain + : [], + }; bids.push(bid); }); diff --git a/test/spec/modules/audiencerunBidAdapter_spec.js b/test/spec/modules/audiencerunBidAdapter_spec.js index a0bdeb4043e..f49c3c159af 100644 --- a/test/spec/modules/audiencerunBidAdapter_spec.js +++ b/test/spec/modules/audiencerunBidAdapter_spec.js @@ -10,7 +10,6 @@ const BID_SERVER_RESPONSE = { { 'bidId': '51ef8751f9aead', 'zoneId': '12345abcde', - 'adId': '1234', 'crid': '5678', 'cpm': 8.021951999999999999, 'currency': 'USD', @@ -19,7 +18,8 @@ const BID_SERVER_RESPONSE = { 'isNet': false, 'buying_type': 'rtb', 'syncUrl': 'https://ac.audiencerun.com/f/sync.html', - 'adm': '' + 'adm': '', + 'adomain': ['example.com'] } ] } @@ -161,7 +161,6 @@ describe('AudienceRun bid adapter tests', function() { describe('interpretResponse', function () { const expectedResponse = [{ 'requestId': '51ef8751f9aead', - 'adId': '12345abcde', 'cpm': 8.021951999999999999, 'width': '728', 'height': '90', @@ -170,7 +169,10 @@ describe('AudienceRun bid adapter tests', function() { 'netRevenue': false, 'ttl': 300, 'ad': '', - 'mediaType': 'banner' + 'mediaType': 'banner', + 'meta': { + 'advertiserDomains': ['example.com'] + } }]; it('should get the correct bid response by display ad', function () { @@ -178,7 +180,7 @@ describe('AudienceRun bid adapter tests', function() { expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('handles empty bid response', function () { + it('should handle empty bid response', function () { const response = { body: {} }; From 4151110d107811eef2d29e058ca2dc2a48d5271c Mon Sep 17 00:00:00 2001 From: Geoffroy Hutin Date: Wed, 30 Jun 2021 09:43:43 +0000 Subject: [PATCH 3/3] AudienceRun fix: add support for floors module and advertiserDomains --- modules/audiencerunBidAdapter.js | 30 ++++++++++++++-- modules/audiencerunBidAdapter.md | 2 +- .../modules/audiencerunBidAdapter_spec.js | 35 ++++++++++++++++++- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index b5f27257939..da0cbb39925 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -7,11 +7,12 @@ const BIDDER_CODE = 'audiencerun'; const BASE_URL = 'https://d.audiencerun.com'; const AUCTION_URL = `${BASE_URL}/prebid`; const TIMEOUT_EVENT_URL = `${BASE_URL}/ps/pbtimeout`; +const DEFAULT_CURRENCY = 'USD'; let requestedBids = []; /** - * Get bidder request referer + * Gets bidder request referer * * @param {Object} bidderRequest * @return {string} @@ -24,6 +25,29 @@ function getPageUrl(bidderRequest) { ); } +/** + * Returns bidfloor through floors module if available + * + * @param {Object} bid + * @returns {number} + */ +function getBidFloor(bid) { + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); + } + + try { + const bidFloor = bid.getFloor({ + currency: DEFAULT_CURRENCY, + mediaType: BANNER, + size: '*', + }); + return bidFloor.floor; + } catch (_) { + return 0 + } +} + export const spec = { version: '1.1.0', code: BIDDER_CODE, @@ -60,7 +84,7 @@ export const spec = { w: size[0], h: size[1], })), - bidfloor: bid.params.bidfloor || 0.0, + bidfloor: getBidFloor(bid), bidId: bid.bidId, bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), adUnitCode: utils.getBidIdParameter('adUnitCode', bid), @@ -125,7 +149,7 @@ export const spec = { bid.creativeId = bidObject.crid; bid.currency = bidObject.currency ? bidObject.currency.toUpperCase() - : 'USD'; + : DEFAULT_CURRENCY; bid.height = bidObject.h; bid.width = bidObject.w; diff --git a/modules/audiencerunBidAdapter.md b/modules/audiencerunBidAdapter.md index 3704922fdd5..2257e939f3b 100644 --- a/modules/audiencerunBidAdapter.md +++ b/modules/audiencerunBidAdapter.md @@ -2,7 +2,7 @@ **Module Name**: AudienceRun Bidder Adapter **Module Type**: Bidder Adapter -**Maintainer**: prebid@audiencerun.com +**Maintainer**: github@audiencerun.com # Description diff --git a/test/spec/modules/audiencerunBidAdapter_spec.js b/test/spec/modules/audiencerunBidAdapter_spec.js index f49c3c159af..7c1279f5073 100644 --- a/test/spec/modules/audiencerunBidAdapter_spec.js +++ b/test/spec/modules/audiencerunBidAdapter_spec.js @@ -77,7 +77,7 @@ describe('AudienceRun bid adapter tests', function() { }); describe('buildRequests', function() { - let bidRequests = [ + const bidRequests = [ { 'bidder': 'audiencerun', 'bidId': '51ef8751f9aead', @@ -96,6 +96,7 @@ describe('AudienceRun bid adapter tests', function() { 'bidRequestsCount': 1 } ]; + const bidRequest = bidRequests[0]; it('sends a valid bid request to ENDPOINT via POST', function() { const request = spec.buildRequests(bidRequests, { @@ -156,6 +157,38 @@ describe('AudienceRun bid adapter tests', function() { expect(payload2.gdpr.consent).to.equal(consentString); expect(payload2.gdpr.applies).to.equal(false); }); + + it('should use a bidfloor with a 0 value', function() { + const bid = Object.assign({}, bidRequest); + const request = spec.buildRequests([bid]); + const payload = JSON.parse(request.data); + expect(payload.bids[0].bidfloor).to.exist.and.to.equal(0); + }) + + it('should use bidfloor param value', function () { + const bid = Object.assign({}, bidRequest, { + params: { + 'bidfloor': 0.2 + } + }) + const request = spec.buildRequests([bid]); + const payload = JSON.parse(request.data); + expect(payload.bids[0].bidfloor).to.exist.and.to.equal(0.2); + }); + + it('should use floors module value', function () { + const bid = Object.assign({}, bidRequest, { + params: { + 'bidfloor': 0.5 + } + }) + bid.getFloor = () => { + return { floor: 1, currency: 'USD' } + } + const request = spec.buildRequests([bid]); + const payload = JSON.parse(request.data); + expect(payload.bids[0].bidfloor).to.exist.and.to.equal(1); + }); }); describe('interpretResponse', function () {