Skip to content

Commit

Permalink
If the bidReq has gam adslot use it (prebid#7374)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez authored and Chris Pabst committed Jan 10, 2022
1 parent ca52b65 commit ee5a66c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
8 changes: 7 additions & 1 deletion modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions test/spec/integration/faker/googletag.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ export function disable() {
window.googletag = undefined;
}

export function reset() {
disable();
enable();
}

enable();
79 changes: 79 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ee5a66c

Please sign in to comment.