From 1be82413d5d2b18d74bf8022c09b255c6055d662 Mon Sep 17 00:00:00 2001 From: robertrmartinez Date: Wed, 1 Sep 2021 10:42:23 -0700 Subject: [PATCH] If the bidReq has gam adslot use it --- modules/priceFloors.js | 8 ++- test/spec/integration/faker/googletag.js | 5 ++ test/spec/modules/priceFloors_spec.js | 79 ++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/modules/priceFloors.js b/modules/priceFloors.js index 3555fedbf3a..5f7a39e0784 100644 --- a/modules/priceFloors.js +++ b/modules/priceFloors.js @@ -64,13 +64,19 @@ function getHostNameFromReferer(referer) { return referrerHostname; } +// First look into bidRequest! +function getGptSlotFromBidRequest(bidRequest) { + const isGam = utils.deepAccess(bidRequest, 'ortb2Imp.ext.data.adserver.name') === 'gam'; + return isGam && bidRequest.ortb2Imp.ext.data.adserver.adslot; +} + /** * @summary floor field types with their matching functions to resolve the actual matched value */ export let fieldMatchingFunctions = { 'size': (bidRequest, bidResponse) => utils.parseGPTSingleSizeArray(bidResponse.size) || '*', 'mediaType': (bidRequest, bidResponse) => bidResponse.mediaType || 'banner', - 'gptSlot': (bidRequest, bidResponse) => utils.getGptSlotInfoForAdUnitCode(bidRequest.adUnitCode).gptSlot, + 'gptSlot': (bidRequest, bidResponse) => getGptSlotFromBidRequest(bidRequest) || utils.getGptSlotInfoForAdUnitCode(bidRequest.adUnitCode).gptSlot, 'domain': (bidRequest, bidResponse) => referrerHostname || getHostNameFromReferer(getRefererInfo().referer), 'adUnitCode': (bidRequest, bidResponse) => bidRequest.adUnitCode } diff --git a/test/spec/integration/faker/googletag.js b/test/spec/integration/faker/googletag.js index 9d91bf315d9..1d1a7512153 100644 --- a/test/spec/integration/faker/googletag.js +++ b/test/spec/integration/faker/googletag.js @@ -91,4 +91,9 @@ export function disable() { window.googletag = undefined; } +export function reset() { + disable(); + enable(); +} + enable(); diff --git a/test/spec/modules/priceFloors_spec.js b/test/spec/modules/priceFloors_spec.js index 548d2789d3e..b3105dafc39 100644 --- a/test/spec/modules/priceFloors_spec.js +++ b/test/spec/modules/priceFloors_spec.js @@ -15,6 +15,7 @@ import { allowedFields } from 'modules/priceFloors.js'; import events from 'src/events.js'; +import * as mockGpt from '../integration/faker/googletag.js'; describe('the price floors module', function () { let logErrorSpy; @@ -398,6 +399,84 @@ describe('the price floors module', function () { matchingFloor: 5.0 }); }); + describe('with gpt enabled', function () { + let gptFloorData; + beforeEach(function () { + gptFloorData = { + currency: 'USD', + schema: { + fields: ['gptSlot'] + }, + values: { + '/12345/sports/soccer': 1.1, + '/12345/sports/basketball': 2.2, + '/12345/news/politics': 3.3, + '/12345/news/weather': 4.4, + '*': 5.5, + }, + default: 0.5 + }; + // reset it so no lingering stuff from other test specs + mockGpt.reset(); + mockGpt.makeSlot({ + code: '/12345/sports/soccer', + divId: 'test_div_1' + }); + mockGpt.makeSlot({ + code: '/12345/sports/basketball', + divId: 'test_div_2' + }); + }); + afterEach(function () { + // reset it so no lingering stuff from other test specs + mockGpt.reset(); + }); + it('picks the right rule when looking for gptSlot', function () { + expect(getFirstMatchingFloor(gptFloorData, basicBidRequest)).to.deep.equal({ + floorMin: 0, + floorRuleValue: 1.1, + matchingFloor: 1.1, + matchingData: '/12345/sports/soccer', + matchingRule: '/12345/sports/soccer' + }); + + let newBidRequest = { ...basicBidRequest, adUnitCode: 'test_div_2' } + expect(getFirstMatchingFloor(gptFloorData, newBidRequest)).to.deep.equal({ + floorMin: 0, + floorRuleValue: 2.2, + matchingFloor: 2.2, + matchingData: '/12345/sports/basketball', + matchingRule: '/12345/sports/basketball' + }); + }); + it('picks the gptSlot from the bidRequest and does not call the slotMatching', function () { + const newBidRequest1 = { ...basicBidRequest }; + utils.deepSetValue(newBidRequest1, 'ortb2Imp.ext.data.adserver', { + name: 'gam', + adslot: '/12345/news/politics' + }) + expect(getFirstMatchingFloor(gptFloorData, newBidRequest1)).to.deep.equal({ + floorMin: 0, + floorRuleValue: 3.3, + matchingFloor: 3.3, + matchingData: '/12345/news/politics', + matchingRule: '/12345/news/politics' + }); + + const newBidRequest2 = { ...basicBidRequest, adUnitCode: 'test_div_2' }; + utils.deepSetValue(newBidRequest2, 'ortb2Imp.ext.data.adserver', { + name: 'gam', + adslot: '/12345/news/weather' + }) + expect(getFirstMatchingFloor(gptFloorData, newBidRequest2)).to.deep.equal({ + floorMin: 0, + floorRuleValue: 4.4, + matchingFloor: 4.4, + matchingData: '/12345/news/weather', + matchingRule: '/12345/news/weather' + }); + }); + }); }); describe('pre-auction tests', function () { let exposedAdUnits;