Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added hb_source to default keys #1969

Merged
merged 3 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions modules/s2sTesting.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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_<bidder> 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]: {}};

Expand Down
6 changes: 6 additions & 0 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ export function getStandardBidderSettings() {
val: function (bidResponse) {
return bidResponse.dealId;
}
},
{
key: 'hb_source',
val: function (bidResponse) {
return bidResponse.source;
}
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions src/bidfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) || '';
Expand All @@ -24,6 +25,7 @@ function Bid(statusCode, bidRequest) {
this.statusMessage = _getStatus();
this.adId = _bidId;
this.mediaType = 'banner';
this.source = _bidSrc;

function _getStatus() {
switch (_statusCode) {
Expand Down
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"hb_adid",
"hb_pb",
"hb_size",
"hb_deal"
"hb_deal",
"hb_source"
],
"S2S" : {
"SRC" : "s2s",
Expand Down
23 changes: 18 additions & 5 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,14 +51,16 @@ describe('auctionmanager.js', function () {
};
bid.bidderCode = bidderCode;
bid.adId = adId;
bid.source = source;
});

it('No bidder level configuration defined - default', function () {
var expected = {
'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);
Expand Down Expand Up @@ -89,6 +92,12 @@ describe('auctionmanager.js', function () {
val: function (bidResponse) {
return bidResponse.size;
}
},
{
key: 'hb_source',
val: function (bidResponse) {
return bidResponse.source;
}
}
]

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
127 changes: 0 additions & 127 deletions test/spec/modules/s2sTesting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_<bidder> 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_<bidder> 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');
});
});
});