From f830b12806a609adcd8caddb516328f12f7dce9f Mon Sep 17 00:00:00 2001 From: robertrmartinez Date: Wed, 29 Jul 2020 09:49:23 -0700 Subject: [PATCH] Rubicon analytics supress floor data from other providers --- modules/rubiconAnalyticsAdapter.js | 47 ++++++++++++------- .../modules/rubiconAnalyticsAdapter_spec.js | 36 +++++++++++++- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/modules/rubiconAnalyticsAdapter.js b/modules/rubiconAnalyticsAdapter.js index 00ad14dd316..7a1bdce84d5 100644 --- a/modules/rubiconAnalyticsAdapter.js +++ b/modules/rubiconAnalyticsAdapter.js @@ -40,6 +40,8 @@ const cache = { timeouts: {}, }; +const validFloorProviders = ['rubicon', 'rubi', 'magnite', 'mgni']; + export function getHostNameFromReferer(referer) { try { rubiconAdapter.referrerHostname = utils.parseUrl(referer, {noDecodeWholeURL: true}).hostname; @@ -195,15 +197,22 @@ function sendMessage(auctionId, bidWonId) { // pick our of top level floor data we want to send! if (auctionCache.floorData) { - auction.floors = utils.pick(auctionCache.floorData, [ - 'location', - 'modelName', () => auctionCache.floorData.modelVersion, - 'skipped', - 'enforcement', () => utils.deepAccess(auctionCache.floorData, 'enforcements.enforceJS'), - 'dealsEnforced', () => utils.deepAccess(auctionCache.floorData, 'enforcements.floorDeals'), - 'skipRate', skipRate => !isNaN(skipRate) ? skipRate : 0, - 'fetchStatus' - ]); + if (auctionCache.floorData.location === 'noData') { + auction.floors = utils.pick(auctionCache.floorData, [ + 'location', + 'fetchStatus' + ]); + } else { + auction.floors = utils.pick(auctionCache.floorData, [ + 'location', + 'modelName', () => auctionCache.floorData.modelVersion, + 'skipped', + 'enforcement', () => utils.deepAccess(auctionCache.floorData, 'enforcements.enforceJS'), + 'dealsEnforced', () => utils.deepAccess(auctionCache.floorData, 'enforcements.floorDeals'), + 'skipRate', + 'fetchStatus' + ]); + } } if (serverConfig) { @@ -269,14 +278,14 @@ function getBidPrice(bid) { } } -export function parseBidResponse(bid, previousBidResponse) { +export function parseBidResponse(bid, previousBidResponse, auctionFloorData) { // The current bidResponse for this matching requestId/bidRequestId let responsePrice = getBidPrice(bid) // we need to compare it with the previous one (if there was one) if (previousBidResponse && previousBidResponse.bidPriceUSD > responsePrice) { return previousBidResponse; } - return utils.pick(bid, [ + let bidResponse = utils.pick(bid, [ 'bidPriceUSD', () => responsePrice, 'dealId', 'status', @@ -286,9 +295,12 @@ export function parseBidResponse(bid, previousBidResponse) { 'height' ]), 'seatBidId', - 'floorValue', () => utils.deepAccess(bid, 'floorData.floorValue'), - 'floorRule', () => utils.debugTurnedOn() ? utils.deepAccess(bid, 'floorData.floorRule') : undefined ]); + if (auctionFloorData) { + bidResponse.floorValue = utils.deepAccess(bid, 'floorData.floorValue'); + bidResponse.floorRule = utils.debugTurnedOn() ? utils.deepAccess(bid, 'floorData.floorRule') : undefined + } + return bidResponse; } let samplingFactor = 1; @@ -368,8 +380,9 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { cacheEntry.bids = {}; cacheEntry.bidsWon = {}; cacheEntry.referrer = args.bidderRequests[0].refererInfo.referer; - if (utils.deepAccess(args, 'bidderRequests.0.bids.0.floorData')) { - cacheEntry.floorData = {...utils.deepAccess(args, 'bidderRequests.0.bids.0.floorData')}; + const floorProvider = utils.deepAccess(args, 'bidderRequests.0.bids.0.floorData.floorProvider'); + if (validFloorProviders.indexOf(floorProvider) !== -1) { + cacheEntry.floorData = {...args.bidderRequests[0].bids[0].floorData}; } cache.auctions[args.auctionId] = cacheEntry; break; @@ -455,7 +468,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { bid.adUnit.adSlot = args.floorData.matchedFields.gptSlot; } // if we have not set enforcements yet set it - if (!utils.deepAccess(auctionEntry, 'floorData.enforcements') && utils.deepAccess(args, 'floorData.enforcements')) { + if (auctionEntry.floorData && !auctionEntry.floorData.enforcements && utils.deepAccess(args, 'floorData.enforcements')) { auctionEntry.floorData.enforcements = {...args.floorData.enforcements}; } if (!bid) { @@ -479,7 +492,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { }; } bid.clientLatencyMillis = Date.now() - cache.auctions[args.auctionId].timestamp; - bid.bidResponse = parseBidResponse(args, bid.bidResponse); + bid.bidResponse = parseBidResponse(args, bid.bidResponse, auctionEntry.floorData); break; case BIDDER_DONE: args.bids.forEach(bid => { diff --git a/test/spec/modules/rubiconAnalyticsAdapter_spec.js b/test/spec/modules/rubiconAnalyticsAdapter_spec.js index 1639389fe24..466435d9652 100644 --- a/test/spec/modules/rubiconAnalyticsAdapter_spec.js +++ b/test/spec/modules/rubiconAnalyticsAdapter_spec.js @@ -659,14 +659,15 @@ describe('rubicon analytics adapter', function () { expect(message).to.deep.equal(ANALYTICS_MESSAGE); }); - it('should capture price floor information correctly', function () { + function performFloorAuction(provider) { let auctionInit = utils.deepClone(MOCK.AUCTION_INIT); auctionInit.bidderRequests[0].bids[0].floorData = { skipped: false, modelVersion: 'someModelName', location: 'setConfig', skipRate: 15, - fetchStatus: 'error' + fetchStatus: 'error', + floorProvider: provider }; let flooredResponse = { ...BID, @@ -727,6 +728,11 @@ describe('rubicon analytics adapter', function () { let message = JSON.parse(server.requests[0].requestBody); validate(message); + return message; + } + + it('should capture price floor information correctly', function () { + let message = performFloorAuction('rubicon') // verify our floor stuff is passed // top level floor info @@ -759,6 +765,32 @@ describe('rubicon analytics adapter', function () { expect(message.auctions[0].adUnits[1].bids[0].bidResponse.bidPriceUSD).to.equal(1.52); }); + it('should not send floor info if provider is not rubicon', function () { + let message = performFloorAuction('randomProvider') + + // verify our floor stuff is passed + // top level floor info + expect(message.auctions[0].floors).to.be.undefined; + // first adUnit's adSlot + expect(message.auctions[0].adUnits[0].adSlot).to.equal('12345/sports'); + // since no other bids, we set adUnit status to no-bid + expect(message.auctions[0].adUnits[0].status).to.equal('no-bid'); + // first adUnits bid is rejected + expect(message.auctions[0].adUnits[0].bids[0].status).to.equal('rejected'); + expect(message.auctions[0].adUnits[0].bids[0].bidResponse.floorValue).to.be.undefined; + // if bid rejected should take cpmAfterAdjustments val + expect(message.auctions[0].adUnits[0].bids[0].bidResponse.bidPriceUSD).to.equal(2.1); + + // second adUnit's adSlot + expect(message.auctions[0].adUnits[1].adSlot).to.equal('12345/news'); + // top level adUnit status is success + expect(message.auctions[0].adUnits[1].status).to.equal('success'); + // second adUnits bid is success + expect(message.auctions[0].adUnits[1].bids[0].status).to.equal('success'); + expect(message.auctions[0].adUnits[1].bids[0].bidResponse.floorValue).to.be.undefined; + expect(message.auctions[0].adUnits[1].bids[0].bidResponse.bidPriceUSD).to.equal(1.52); + }); + it('should correctly overwrite bidId if seatBidId is on the bidResponse', function () { // Only want one bid request in our mock auction let bidRequested = utils.deepClone(MOCK.BID_REQUESTED);