From b7d5da33a7cc8162468df77e301dbfb2380a777c Mon Sep 17 00:00:00 2001 From: Matt Kendall Date: Tue, 19 Dec 2017 17:12:05 -0500 Subject: [PATCH] added hb_source to default keys (#1969) * added hb_source * dropped function to add hb_source since it is now default key * fixed lint error --- modules/s2sTesting.js | 36 -------- src/auction.js | 6 ++ src/bidfactory.js | 2 + src/constants.json | 3 +- test/spec/auctionmanager_spec.js | 23 +++-- test/spec/modules/s2sTesting_spec.js | 127 --------------------------- 6 files changed, 28 insertions(+), 169 deletions(-) diff --git a/modules/s2sTesting.js b/modules/s2sTesting.js index a821383dc2d..60ab150530f 100644 --- a/modules/s2sTesting.js +++ b/modules/s2sTesting.js @@ -1,8 +1,6 @@ import { config } from 'src/config'; import { setS2STestingModule } from 'src/adaptermanager'; -var CONSTANTS = require('src/constants.json'); -const AST = CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING; export const SERVER = 'server'; export const CLIENT = 'client'; @@ -12,43 +10,9 @@ var bidSource = {}; // store bidder sources determined from s2sConfing bidderCon // load s2sConfig config.getConfig('s2sConfig', config => { testing = config.s2sConfig && config.s2sConfig.testing; - addBidderSourceTargeting(config.s2sConfig) calculateBidSources(config.s2sConfig); }); -// function to add hb_source_ adServerTargeting (AST) kvp to bidder settings -function addBidderSourceTargeting(s2sConfig = {}) { - // bail if testing is not turned on - if (!testing) { - return; - } - var bidderSettings = $$PREBID_GLOBAL$$.bidderSettings || {}; - var bidderControl = s2sConfig.bidderControl || {}; - // for each configured bidder - (s2sConfig.bidders || []).forEach((bidder) => { - // remove any existing kvp setting - if (bidderSettings[bidder] && bidderSettings[bidder][AST]) { - bidderSettings[bidder][AST] = bidderSettings[bidder][AST].filter((kvp) => { - return kvp.key !== `hb_source_${bidder}`; - }); - } - // if includeSourceKvp === true add new kvp setting - if (bidderControl[bidder] && bidderControl[bidder].includeSourceKvp) { - bidderSettings[bidder] = bidderSettings[bidder] || {}; - bidderSettings[bidder][AST] = bidderSettings[bidder][AST] || []; - bidderSettings[bidder][AST].push({ - key: `hb_source_${bidder}`, - val: function (bidResponse) { - // default to client (currently only S2S sets this) - return bidResponse.source || CLIENT; - } - }); - // make sure "alwaysUseBid" is true so targeting is set - bidderSettings[bidder].alwaysUseBid = true; - } - }); -} - export function getSourceBidderMap(adUnits = []) { var sourceBidders = {[SERVER]: {}, [CLIENT]: {}}; diff --git a/src/auction.js b/src/auction.js index 45d06c23f59..7c6a752c057 100644 --- a/src/auction.js +++ b/src/auction.js @@ -361,6 +361,12 @@ export function getStandardBidderSettings() { val: function (bidResponse) { return bidResponse.dealId; } + }, + { + key: 'hb_source', + val: function (bidResponse) { + return bidResponse.source; + } } ] } diff --git a/src/bidfactory.js b/src/bidfactory.js index ff57abb8a39..6250969d6df 100644 --- a/src/bidfactory.js +++ b/src/bidfactory.js @@ -16,6 +16,7 @@ var utils = require('./utils.js'); */ function Bid(statusCode, bidRequest) { var _bidId = (bidRequest && bidRequest.bidId) || utils.getUniqueIdentifierStr(); + var _bidSrc = (bidRequest && bidRequest.src) || 'client'; var _statusCode = statusCode || 0; this.bidderCode = (bidRequest && bidRequest.bidder) || ''; @@ -24,6 +25,7 @@ function Bid(statusCode, bidRequest) { this.statusMessage = _getStatus(); this.adId = _bidId; this.mediaType = 'banner'; + this.source = _bidSrc; function _getStatus() { switch (_statusCode) { diff --git a/src/constants.json b/src/constants.json index 3e20d462ac7..e80c118ea83 100644 --- a/src/constants.json +++ b/src/constants.json @@ -51,7 +51,8 @@ "hb_adid", "hb_pb", "hb_size", - "hb_deal" + "hb_deal", + "hb_source" ], "S2S" : { "SRC" : "s2s", diff --git a/test/spec/auctionmanager_spec.js b/test/spec/auctionmanager_spec.js index c773974d177..688afc35d9d 100644 --- a/test/spec/auctionmanager_spec.js +++ b/test/spec/auctionmanager_spec.js @@ -34,6 +34,7 @@ describe('auctionmanager.js', function () { var bidderCode = 'appnexus'; var size = '300x250'; var adId = '1adId'; + var source = 'client'; before(function () { bid.cpm = bidPriceCpm; @@ -50,6 +51,7 @@ describe('auctionmanager.js', function () { }; bid.bidderCode = bidderCode; bid.adId = adId; + bid.source = source; }); it('No bidder level configuration defined - default', function () { @@ -57,7 +59,8 @@ describe('auctionmanager.js', function () { 'hb_bidder': bidderCode, 'hb_adid': adId, 'hb_pb': bidPbMg, - 'hb_size': size + 'hb_size': size, + 'hb_source': source }; var response = getKeyValueTargetingPairs(bidderCode, bid, CONSTANTS.GRANULARITY_OPTIONS.MEDIUM); assert.deepEqual(response, expected); @@ -89,6 +92,12 @@ describe('auctionmanager.js', function () { val: function (bidResponse) { return bidResponse.size; } + }, + { + key: 'hb_source', + val: function (bidResponse) { + return bidResponse.source; + } } ] @@ -99,7 +108,8 @@ describe('auctionmanager.js', function () { 'hb_bidder': bidderCode, 'hb_adid': adId, 'hb_pb': bidPbHg, - 'hb_size': size + 'hb_size': size, + 'hb_source': source }; var response = getKeyValueTargetingPairs(bidderCode, bid, CONSTANTS.GRANULARITY_OPTIONS.MEDIUM); assert.deepEqual(response, expected); @@ -141,7 +151,8 @@ describe('auctionmanager.js', function () { 'hb_bidder': bidderCode, 'hb_adid': adId, 'hb_pb': bidPbHg, - 'hb_size': size + 'hb_size': size, + 'hb_source': source }; var response = getKeyValueTargetingPairs(bidderCode, bid); assert.deepEqual(response, expected); @@ -183,7 +194,8 @@ describe('auctionmanager.js', function () { 'hb_bidder': bidderCode, 'hb_adid': adId, 'hb_pb': bidPbMg, - 'hb_size': size + 'hb_size': size, + 'hb_source': source }; var response = getKeyValueTargetingPairs(bidderCode, bid, CONSTANTS.GRANULARITY_OPTIONS.MEDIUM); assert.deepEqual(response, expected); @@ -347,7 +359,8 @@ describe('auctionmanager.js', function () { 'hb_bidder': bidderCode, 'hb_adid': adId, 'hb_pb': 5.57, - 'hb_size': '300x250' + 'hb_size': '300x250', + 'hb_source': source }; var response = getKeyValueTargetingPairs(bidderCode, bid); assert.deepEqual(response, expected); diff --git a/test/spec/modules/s2sTesting_spec.js b/test/spec/modules/s2sTesting_spec.js index 26d5eb8884b..845947a0b38 100644 --- a/test/spec/modules/s2sTesting_spec.js +++ b/test/spec/modules/s2sTesting_spec.js @@ -308,131 +308,4 @@ describe('s2sTesting', function () { }); }); }); - - describe('addBidderSourceTargeting', () => { - const AST = CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING; - - function checkTargeting(bidder) { - var targeting = window.$$PREBID_GLOBAL$$.bidderSettings[bidder][AST]; - var srcTargeting = targeting[targeting.length - 1]; - expect(srcTargeting.key).to.equal(`hb_source_${bidder}`); - expect(srcTargeting.val).to.be.a('function'); - expect(window.$$PREBID_GLOBAL$$.bidderSettings[bidder].alwaysUseBid).to.be.true; - } - - function checkNoTargeting(bidder) { - var bs = window.$$PREBID_GLOBAL$$.bidderSettings; - var targeting = bs[bidder] && bs[bidder][AST]; - if (!targeting) { - expect(targeting).to.be.undefined; - return; - } - expect(find(targeting, (kvp) => { - return kvp.key === `hb_source_${bidder}`; - })).to.be.undefined; - } - - function checkTargetingVal(bidResponse, expectedVal) { - var targeting = window.$$PREBID_GLOBAL$$.bidderSettings[bidResponse.bidderCode][AST]; - var targetingFunc = targeting[targeting.length - 1].val; - expect(targetingFunc(bidResponse)).to.equal(expectedVal); - } - - beforeEach(() => { - // set bidderSettings - window.$$PREBID_GLOBAL$$.bidderSettings = {}; - }); - - it('should not set hb_source_ unless testing is on and includeSourceKvp is set', () => { - config.setConfig({s2sConfig: {bidders: ['rubicon', 'appnexus']}}); - expect(window.$$PREBID_GLOBAL$$.bidderSettings).to.eql({}); - - config.setConfig({s2sConfig: {bidders: ['rubicon', 'appnexus'], testing: true}}); - expect(window.$$PREBID_GLOBAL$$.bidderSettings).to.eql({}); - - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: true, - bidderControl: { - rubicon: {bidSource: {server: 2, client: 1}}, - appnexus: {bidSource: {server: 1}} - } - }}); - expect(window.$$PREBID_GLOBAL$$.bidderSettings).to.eql({}); - - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: false, - bidderControl: { - rubicon: {includeSourceKvp: true}, - appnexus: {includeSourceKvp: true} - } - }}); - expect(window.$$PREBID_GLOBAL$$.bidderSettings).to.eql({}); - }); - - it('should set hb_source_ if includeSourceKvp is set', () => { - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: true, - bidderControl: { - rubicon: {includeSourceKvp: true}, - appnexus: {includeSourceKvp: true} - } - }}); - checkTargeting('rubicon'); - checkTargeting('appnexus'); - checkTargetingVal({bidderCode: 'rubicon', source: 'server'}, 'server'); - checkTargetingVal({bidderCode: 'appnexus', source: 'client'}, 'client'); - - // turn off appnexus - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: true, - bidderControl: { - rubicon: {includeSourceKvp: true}, - appnexus: {includeSourceKvp: false} - } - }}); - checkTargeting('rubicon'); - checkNoTargeting('appnexus'); - checkTargetingVal({bidderCode: 'rubicon', source: 'client'}, 'client'); - - // should default to "client" - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: true, - bidderControl: { - rubicon: {includeSourceKvp: true}, - appnexus: {includeSourceKvp: true} - } - }}); - checkTargeting('rubicon'); - checkTargeting('appnexus'); - checkTargetingVal({bidderCode: 'rubicon'}, 'client'); - checkTargetingVal({bidderCode: 'appnexus'}, 'client'); - }); - - it('should reset adServerTargeting when a new config is set', () => { - // set config with targeting - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: true, - bidderControl: { - rubicon: {includeSourceKvp: true}, - appnexus: {includeSourceKvp: true} - } - }}); - checkTargeting('rubicon'); - checkTargeting('appnexus'); - - // set config without targeting - config.setConfig({s2sConfig: { - bidders: ['rubicon', 'appnexus'], - testing: true - }}); - checkNoTargeting('rubicon'); - checkNoTargeting('appnexus'); - }); - }); });