From 031fa560069330891e49edb04d513a3a127f1c8a Mon Sep 17 00:00:00 2001 From: Paul Wyrembak Date: Tue, 15 Aug 2017 15:43:08 +0300 Subject: [PATCH 1/5] Add trustx adapter and tests for it --- modules/trustxBidAdapter.js | 210 ++++++++++++++++++ test/spec/modules/trustxBidAdapter_spec.js | 234 +++++++++++++++++++++ 2 files changed, 444 insertions(+) create mode 100644 modules/trustxBidAdapter.js create mode 100644 test/spec/modules/trustxBidAdapter_spec.js diff --git a/modules/trustxBidAdapter.js b/modules/trustxBidAdapter.js new file mode 100644 index 00000000000..a570e564ea4 --- /dev/null +++ b/modules/trustxBidAdapter.js @@ -0,0 +1,210 @@ +var utils = require('src/utils.js'); +var bidfactory = require('src/bidfactory.js'); +var bidmanager = require('src/bidmanager.js'); +var adloader = require('src/adloader'); +var adaptermanager = require('src/adaptermanager'); + +var TrustxAdapter = function TrustxAdapter() { + var bidderCode = 'trustx'; + var reqHost = '//sofia.trustx.org'; + var reqPath = '/hb?'; + var LOG_ERROR_MESS = { + noAuid: 'Bid from response has no auid parameter - ', + noAdm: 'Bid from response has no adm parameter - ', + noBid: 'Array of bid objects is empty', + noPlacementCode: 'Can\'t find placementCode for bid with auid - ', + havePCodeFor: ', placementCode is available only for the following uids - ', + emptyUids: 'Uids should be not empty', + emptySeatbid: 'Seatbid array from response has empty item', + emptyResponse: 'Response is empty', + hasEmptySeatbidArray: 'Response has empty seatbid array', + hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - ' + }; + + function _makeHandler(auids, placementMap, onTimeoutWorker, needToSendStat) { + var cbName = bidderCode + '_callback_wrapper_' + auids.join('_'); + $$PREBID_GLOBAL$$[cbName] = function(resp) { + delete $$PREBID_GLOBAL$$[cbName]; + _responseProcessing(resp, auids, placementMap, onTimeoutWorker, needToSendStat); + }; + return '$$PREBID_GLOBAL$$.' + cbName; + } + + function _sendRequest(auids, placementMap, onTimeoutWorker) { + var query = []; + var path = reqPath; + var needToSendStat = Math.random() < 0.1; + query.push('u=' + encodeURIComponent(location.href)); + query.push('auids=' + encodeURIComponent(auids.join(','))); + query.push('cb=' + _makeHandler(auids, placementMap, onTimeoutWorker, needToSendStat)); + query.push('pt=' + (window.globalPrebidTrustxPriceType === 'net' ? 'net' : 'gross')); + query.push('hbstat=' + (needToSendStat ? '1' : '0')); + + adloader.loadScript(reqHost + path + query.join('&')); + } + + function _makeTimeoutWorker() { + var active = true; + var handler = function() { + worker.called = true; + $$PREBID_GLOBAL$$.offEvent('bidTimeout', handler); + }; + $$PREBID_GLOBAL$$.onEvent('bidTimeout', handler); + var worker = { + startTime: new Date().getTime(), + off: function() { + if (active && !this.called) { + active = false; + $$PREBID_GLOBAL$$.offEvent('bidTimeout', handler); + } + }, + called: false + }; + return worker; + } + + function _callBids(params) { + var auids = []; + var placementMap = {}; + var hasBid; + var bid; + var bids = params.bids || []; + for (var i = 0; i < bids.length; i++) { + bid = bids[i]; + if (bid && bid.bidder === bidderCode && bid.placementCode) { + hasBid = true; + if (bid.params && bid.params.uid) { + if (!placementMap[bid.params.uid]) { + placementMap[bid.params.uid] = [bid.placementCode]; + auids.push(bid.params.uid); + } else { + placementMap[bid.params.uid].push(bid.placementCode); + } + } + } + } + + if (auids.length) { + var onTimeoutWorker = _makeTimeoutWorker(); + _sendRequest(auids, placementMap, onTimeoutWorker); + } else if (hasBid) { + utils.logError(LOG_ERROR_MESS.emptyUids); + } + } + + function tryToSendStat(startTime, timeout, auids, isTimeouted, error) { + var protocol = location.protocol === 'https:' ? 'https:' : 'http:'; + var stat = { + wrapper: 'prebid', + tt: timeout, + ct: new Date().getTime() - startTime, + st: isTimeouted ? 'to' : error ? 'err' : 'ok', + cr: 10 + }; + stat = encodeURIComponent(JSON.stringify(stat)); + auids = encodeURIComponent(auids.join(',')); + (new Image()).src = protocol + '//sofia.trustx.org/hbstat?auids=' + auids + '&stat=' + stat + '&rnd=' + Math.random(); + } + + function _getBidFromResponse(resp) { + if (!resp) { + utils.logError(LOG_ERROR_MESS.emptySeatbid); + } else if (!resp.bid) { + utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(resp)); + } else if (!resp.bid[0]) { + utils.logError(LOG_ERROR_MESS.noBid); + } + return resp && resp.bid && resp.bid[0]; + } + + function _forEachPlacement(error, bid, placementCode) { + var bidObject; + if (error) { + bidObject = bidfactory.createBid(2); + } else { + bidObject = bidfactory.createBid(1); + bidObject.cpm = bid.price; + bidObject.ad = bid.adm; + bidObject.width = bid.w; + bidObject.height = bid.h; + if (bid.dealid) { + bidObject.dealId = bid.dealid; + } + } + bidObject.bidderCode = bidderCode; + bidmanager.addBidResponse(placementCode, bidObject); + } + + function _addBidResponse(bid, auids, placementMap) { + if (!bid) return; + var errorMessage, placementCodes; + if (!bid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(bid); + else { + placementCodes = placementMap.hasOwnProperty(bid.auid) && placementMap[bid.auid]; + if (!placementCodes) { + errorMessage = LOG_ERROR_MESS.noPlacementCode + bid.auid + LOG_ERROR_MESS.havePCodeFor + auids.join(','); + } + } + + if (!errorMessage) { + if (!bid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(bid); + + var l = placementCodes.length; + while (l--) { + _forEachPlacement(errorMessage, bid, placementCodes[l]); + } + + delete placementMap[bid.auid]; + } + + if (errorMessage) { + utils.logError(errorMessage); + } + } + + function _responseProcessing(resp, auids, placementMap, onTimeoutWorker, needToSendStat) { + var errorMessage; + + if (!resp) errorMessage = LOG_ERROR_MESS.emptyResponse; + else if (resp.seatbid && !resp.seatbid.length) errorMessage = LOG_ERROR_MESS.hasEmptySeatbidArray; + + if (!errorMessage) { + resp = resp.seatbid || []; + var l = resp.length; + while (l--) { + _addBidResponse(_getBidFromResponse(resp[l]), auids, placementMap); + } + } + + var n, bidObj; + for (var auid in placementMap) { + if (placementMap.hasOwnProperty(auid) && placementMap[auid]) { + n = placementMap[auid].length; + while (n--) { + bidObj = bidfactory.createBid(2); + bidObj.bidderCode = bidderCode; + bidmanager.addBidResponse(placementMap[auid][n], bidObj); + } + } + } + + onTimeoutWorker.off(); + needToSendStat && tryToSendStat( + onTimeoutWorker.startTime, + $$PREBID_GLOBAL$$.cbTimeout + $$PREBID_GLOBAL$$.timeoutBuffer, + auids, + onTimeoutWorker.called, + errorMessage + ); + + if (errorMessage) utils.logError(errorMessage); + } + + return { + callBids: _callBids + }; +}; + +adaptermanager.registerBidAdapter(new TrustxAdapter(), 'trustx'); + +module.exports = TrustxAdapter; diff --git a/test/spec/modules/trustxBidAdapter_spec.js b/test/spec/modules/trustxBidAdapter_spec.js new file mode 100644 index 00000000000..e559a16d71a --- /dev/null +++ b/test/spec/modules/trustxBidAdapter_spec.js @@ -0,0 +1,234 @@ +describe('trustx adapter tests', function () { + var expect = require('chai').expect; + var assert = require('chai').assert; + var urlParse = require('url-parse'); + var querystringify = require('querystringify'); + + var adapter = require('modules/trustxBidAdapter'); + var bidmanager = require('src/bidmanager'); + var adLoader = require('src/adloader'); + var utils = require('src/utils'); + window.pbjs = window.pbjs || {}; + + if (typeof (pbjs) === 'undefined') { + var pbjs = window.pbjs; + } + let stubLoadScript; + beforeEach(function () { + stubLoadScript = sinon.stub(adLoader, 'loadScript'); + }); + afterEach(function () { + stubLoadScript.restore(); + }); + var logErrorSpy; + beforeEach(function () { + logErrorSpy = sinon.spy(utils, 'logError'); + }); + afterEach(function () { + logErrorSpy.restore(); + }); + describe('creation of request url', function () { + if (typeof (pbjs._bidsRequested) === 'undefined') { + pbjs._bidsRequested = []; + } + it('should fix parameter name', function () { + var params = { + bidderCode: 'trustx', + bids: [ + { + bidder: 'trustx', + params: { + uid: 5 + }, + placementCode: 'div-1' + }, + { + bidder: 'trustx', + params: { + uid: 6 + }, + placementCode: 'div-1' + }, + { + bidder: 'trustx', + params: {}, + placementCode: 'div-2' + }, + { + bidder: 'trustx', + params: { + uid: 6, + test: true + }, + placementCode: 'div-3' + }, + { + bidder: 'trustx', + placementCode: 'div-4' + } + ] + }; + adapter().callBids(params); + var bidUrl = stubLoadScript.getCall(0).args[0]; + sinon.assert.calledWith(stubLoadScript, bidUrl); + var parsedBidUrl = urlParse(bidUrl); + var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); + var generatedCallback = 'pbjs.trustx_callback_wrapper_5_6'; + expect(parsedBidUrl.hostname).to.equal('sofia.trustx.org'); + expect(parsedBidUrl.pathname).to.equal('/hb'); + expect(parsedBidUrlQueryString).to.have.property('auids').and.to.equal('5,6'); + expect(parsedBidUrlQueryString).to.have.property('u').and.to.equal(location.href); + expect(parsedBidUrlQueryString).to.have.property('cb').and.to.equal(generatedCallback); + }); + }); + describe('validate incoming params', function () { + if (typeof (pbjs._bidsRequested) === 'undefined') { + pbjs._bidsRequested = []; + } + it('has no correct item in config', function () { + var params = { + bidderCode: 'trustx', + bids: [ + { + bidder: 'trustx', + params: {}, + placementCode: 'div-1' + }, + { + bidder: 'trustx', + placementCode: 'div-1' + } + ] + }; + adapter().callBids(params); + sinon.assert.notCalled(stubLoadScript); + expect(logErrorSpy.getCall(0).args[0]).to.equal('Uids should be not empty'); + }); + }); + describe('handling of the callback response', function () { + if (typeof (pbjs._bidsReceived) === 'undefined') { + pbjs._bidsReceived = []; + } + if (typeof (pbjs._bidsRequested) === 'undefined') { + pbjs._bidsRequested = []; + } + if (typeof (pbjs._adsReceived) === 'undefined') { + pbjs._adsReceived = []; + } + var params = { + bidderCode: 'trustx', + bids: [ + { + bidder: 'trustx', + params: { + uid: 5 + }, + placementCode: '/19968336/header-bid-tag-0' + }, + { + bidder: 'trustx', + params: { + uid: 6 + }, + placementCode: '/19968336/header-bid-tag-1' + }, + { + bidder: 'trustx', + params: { + uid: 42 + }, + placementCode: '/19968336/header-bid-tag-2' + }, + { + bidder: 'trustx', + params: { + uid: 43 + }, + placementCode: '/19968336/header-bid-tag-3' + }, + { + bidder: 'trustx', + params: { + uid: 44 + }, + placementCode: '/19968336/header-bid-tag-4' + }, + { + bidder: 'trustx', + params: { + uid: 45 + }, + placementCode: '/19968336/header-bid-tag-5' + } + ] + }; + it('callback function should exist', function () { + adapter().callBids(params); + expect(pbjs['trustx_callback_wrapper_5_6_42_43_44_45']) + .to.exist.and.to.be.a('function'); + }); + it('bidmanager.addBidResponse should be called with correct arguments', function () { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + adapter().callBids(params); + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = '/19968336/header-bid-tag'; + adUnits.push(unit); + if (typeof (pbjs._bidsRequested) === 'undefined') { + pbjs._bidsRequested = [params]; + } else { + pbjs._bidsRequested.push(params); + } + pbjs.adUnits = adUnits; + var response = { + seatbid: [ + {bid: [{price: 1.15, adm: '
test content 1
', auid: 5, h: 90, w: 728}], seat: '1'}, + {bid: [{price: 0, auid: 6, h: 250, w: 300}], seat: '1'}, + {bid: [{price: 0, adm: '
test content 3
', h: 250, w: 300}], seat: '1'}, + undefined, + {bid: [], seat: '1'}, + {seat: '1'}, + {bid: [{price: 0, adm: '
test content 7
', auid: 46, h: 250, w: 300}], seat: '1'} + ] + }; + pbjs['trustx_callback_wrapper_5_6_42_43_44_45'](response); + var bidPlacementCode1 = stubAddBidResponse.getCall(1).args[0]; + var bidObject1 = stubAddBidResponse.getCall(1).args[1]; + var bidPlacementCode2 = stubAddBidResponse.getCall(0).args[0]; + var bidObject2 = stubAddBidResponse.getCall(0).args[1]; + var bidPlacementCode3 = stubAddBidResponse.getCall(2).args[0]; + var bidObject3 = stubAddBidResponse.getCall(2).args[1]; + var bidPlacementCode4 = stubAddBidResponse.getCall(3).args[0]; + var bidObject4 = stubAddBidResponse.getCall(3).args[1]; + var bidPlacementCode5 = stubAddBidResponse.getCall(4).args[0]; + var bidObject5 = stubAddBidResponse.getCall(4).args[1]; + var bidPlacementCode6 = stubAddBidResponse.getCall(5).args[0]; + var bidObject6 = stubAddBidResponse.getCall(5).args[1]; + expect(logErrorSpy.getCall(5).args[0]).to.equal('Bid from response has no adm parameter - {"price":0,"auid":6,"h":250,"w":300}'); + expect(logErrorSpy.getCall(4).args[0]).to.equal('Bid from response has no auid parameter - {"price":0,"adm":"<' + 'div>test content 3","h":250,"w":300}'); + expect(logErrorSpy.getCall(3).args[0]).to.equal('Seatbid array from response has empty item'); + expect(logErrorSpy.getCall(2).args[0]).to.equal('Array of bid objects is empty'); + expect(logErrorSpy.getCall(1).args[0]).to.equal('Seatbid from response has no array of bid objects - {"seat":"1"}'); + expect(logErrorSpy.getCall(0).args[0]).to.equal('Can\'t find placementCode for bid with auid - 46, placementCode is available only for the following uids - 5,6,42,43,44,45'); + expect(bidPlacementCode1).to.equal('/19968336/header-bid-tag-0'); + expect(bidObject1.cpm).to.equal(1.15); + expect(bidObject1.ad).to.equal('
test content 1
'); + expect(bidObject1.width).to.equal(728); + expect(bidObject1.height).to.equal(90); + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.bidderCode).to.equal('trustx'); + expect(bidPlacementCode2).to.equal('/19968336/header-bid-tag-1'); + expect(bidObject2.getStatusCode()).to.equal(2); + expect(bidPlacementCode3).to.equal('/19968336/header-bid-tag-2'); + expect(bidObject3.getStatusCode()).to.equal(2); + expect(bidPlacementCode4).to.equal('/19968336/header-bid-tag-3'); + expect(bidObject4.getStatusCode()).to.equal(2); + expect(bidPlacementCode5).to.equal('/19968336/header-bid-tag-4'); + expect(bidObject5.getStatusCode()).to.equal(2); + expect(bidPlacementCode6).to.equal('/19968336/header-bid-tag-5'); + expect(bidObject6.getStatusCode()).to.equal(2); + stubAddBidResponse.restore(); + }); + }); +}); From 319cadde088c6429e3cc5fd4c8d5873bdd0496fc Mon Sep 17 00:00:00 2001 From: Paul Wyrembak Date: Tue, 15 Aug 2017 16:30:23 +0300 Subject: [PATCH 2/5] update integration example --- integrationExamples/gpt/hello_world.html | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html index 0f5e24a301a..3732b84d534 100644 --- a/integrationExamples/gpt/hello_world.html +++ b/integrationExamples/gpt/hello_world.html @@ -22,11 +22,29 @@ // Replace this object to test a new Adapter! bids: [{ - bidder: 'appnexus', + bidder: 'trustx', params: { - placementId: '10433394' + uid: '42' } - }] + }, + { + bidder: 'trustx', + params: { + uid: '43' + } + }, + { + bidder: 'trustx', + params: { + uid: '44' + } + }, + { + bidder: 'trustx', + params: { + uid: '45' + } + }] }]; From 69ab1f4caf56069e42afc62d60068d9b4c93daf0 Mon Sep 17 00:00:00 2001 From: Paul Wyrembak Date: Sat, 9 Sep 2017 13:26:04 +0300 Subject: [PATCH 3/5] Update trustx adapter --- integrationExamples/gpt/hello_world.html | 24 ++-------- modules/trustxBidAdapter.js | 57 +++--------------------- 2 files changed, 10 insertions(+), 71 deletions(-) diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html index 3732b84d534..0f5e24a301a 100644 --- a/integrationExamples/gpt/hello_world.html +++ b/integrationExamples/gpt/hello_world.html @@ -22,29 +22,11 @@ // Replace this object to test a new Adapter! bids: [{ - bidder: 'trustx', + bidder: 'appnexus', params: { - uid: '42' + placementId: '10433394' } - }, - { - bidder: 'trustx', - params: { - uid: '43' - } - }, - { - bidder: 'trustx', - params: { - uid: '44' - } - }, - { - bidder: 'trustx', - params: { - uid: '45' - } - }] + }] }]; diff --git a/modules/trustxBidAdapter.js b/modules/trustxBidAdapter.js index a570e564ea4..07141f92e24 100644 --- a/modules/trustxBidAdapter.js +++ b/modules/trustxBidAdapter.js @@ -21,48 +21,29 @@ var TrustxAdapter = function TrustxAdapter() { hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - ' }; - function _makeHandler(auids, placementMap, onTimeoutWorker, needToSendStat) { + function _makeHandler(auids, placementMap) { var cbName = bidderCode + '_callback_wrapper_' + auids.join('_'); $$PREBID_GLOBAL$$[cbName] = function(resp) { delete $$PREBID_GLOBAL$$[cbName]; - _responseProcessing(resp, auids, placementMap, onTimeoutWorker, needToSendStat); + _responseProcessing(resp, auids, placementMap); }; return '$$PREBID_GLOBAL$$.' + cbName; } - function _sendRequest(auids, placementMap, onTimeoutWorker) { + function _sendRequest(auids, placementMap) { var query = []; var path = reqPath; var needToSendStat = Math.random() < 0.1; + $$PREBID_GLOBAL$$.needToSendTrustxStat = needToSendStat; query.push('u=' + encodeURIComponent(location.href)); query.push('auids=' + encodeURIComponent(auids.join(','))); - query.push('cb=' + _makeHandler(auids, placementMap, onTimeoutWorker, needToSendStat)); + query.push('cb=' + _makeHandler(auids, placementMap)); query.push('pt=' + (window.globalPrebidTrustxPriceType === 'net' ? 'net' : 'gross')); query.push('hbstat=' + (needToSendStat ? '1' : '0')); adloader.loadScript(reqHost + path + query.join('&')); } - function _makeTimeoutWorker() { - var active = true; - var handler = function() { - worker.called = true; - $$PREBID_GLOBAL$$.offEvent('bidTimeout', handler); - }; - $$PREBID_GLOBAL$$.onEvent('bidTimeout', handler); - var worker = { - startTime: new Date().getTime(), - off: function() { - if (active && !this.called) { - active = false; - $$PREBID_GLOBAL$$.offEvent('bidTimeout', handler); - } - }, - called: false - }; - return worker; - } - function _callBids(params) { var auids = []; var placementMap = {}; @@ -85,27 +66,12 @@ var TrustxAdapter = function TrustxAdapter() { } if (auids.length) { - var onTimeoutWorker = _makeTimeoutWorker(); - _sendRequest(auids, placementMap, onTimeoutWorker); + _sendRequest(auids, placementMap); } else if (hasBid) { utils.logError(LOG_ERROR_MESS.emptyUids); } } - function tryToSendStat(startTime, timeout, auids, isTimeouted, error) { - var protocol = location.protocol === 'https:' ? 'https:' : 'http:'; - var stat = { - wrapper: 'prebid', - tt: timeout, - ct: new Date().getTime() - startTime, - st: isTimeouted ? 'to' : error ? 'err' : 'ok', - cr: 10 - }; - stat = encodeURIComponent(JSON.stringify(stat)); - auids = encodeURIComponent(auids.join(',')); - (new Image()).src = protocol + '//sofia.trustx.org/hbstat?auids=' + auids + '&stat=' + stat + '&rnd=' + Math.random(); - } - function _getBidFromResponse(resp) { if (!resp) { utils.logError(LOG_ERROR_MESS.emptySeatbid); @@ -162,7 +128,7 @@ var TrustxAdapter = function TrustxAdapter() { } } - function _responseProcessing(resp, auids, placementMap, onTimeoutWorker, needToSendStat) { + function _responseProcessing(resp, auids, placementMap) { var errorMessage; if (!resp) errorMessage = LOG_ERROR_MESS.emptyResponse; @@ -188,15 +154,6 @@ var TrustxAdapter = function TrustxAdapter() { } } - onTimeoutWorker.off(); - needToSendStat && tryToSendStat( - onTimeoutWorker.startTime, - $$PREBID_GLOBAL$$.cbTimeout + $$PREBID_GLOBAL$$.timeoutBuffer, - auids, - onTimeoutWorker.called, - errorMessage - ); - if (errorMessage) utils.logError(errorMessage); } From ef500123318cb6b8cd3a2d730ee5017f799e65e3 Mon Sep 17 00:00:00 2001 From: pwyrembak Date: Tue, 19 Sep 2017 18:54:52 +0300 Subject: [PATCH 4/5] Post-review fixes of Trustx adapter --- modules/trustxBidAdapter.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/trustxBidAdapter.js b/modules/trustxBidAdapter.js index 07141f92e24..44c00c2c0b3 100644 --- a/modules/trustxBidAdapter.js +++ b/modules/trustxBidAdapter.js @@ -1,14 +1,15 @@ -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); +const utils = require('src/utils.js'); +const bidfactory = require('src/bidfactory.js'); +const bidmanager = require('src/bidmanager.js'); +const adloader = require('src/adloader'); +const adaptermanager = require('src/adaptermanager'); +const CONSTANTS = require('src/constants.json'); var TrustxAdapter = function TrustxAdapter() { - var bidderCode = 'trustx'; - var reqHost = '//sofia.trustx.org'; - var reqPath = '/hb?'; - var LOG_ERROR_MESS = { + const bidderCode = 'trustx'; + const reqHost = '//sofia.trustx.org'; + const reqPath = '/hb?'; + const LOG_ERROR_MESS = { noAuid: 'Bid from response has no auid parameter - ', noAdm: 'Bid from response has no adm parameter - ', noBid: 'Array of bid objects is empty', @@ -33,13 +34,10 @@ var TrustxAdapter = function TrustxAdapter() { function _sendRequest(auids, placementMap) { var query = []; var path = reqPath; - var needToSendStat = Math.random() < 0.1; - $$PREBID_GLOBAL$$.needToSendTrustxStat = needToSendStat; query.push('u=' + encodeURIComponent(location.href)); query.push('auids=' + encodeURIComponent(auids.join(','))); query.push('cb=' + _makeHandler(auids, placementMap)); query.push('pt=' + (window.globalPrebidTrustxPriceType === 'net' ? 'net' : 'gross')); - query.push('hbstat=' + (needToSendStat ? '1' : '0')); adloader.loadScript(reqHost + path + query.join('&')); } @@ -86,9 +84,9 @@ var TrustxAdapter = function TrustxAdapter() { function _forEachPlacement(error, bid, placementCode) { var bidObject; if (error) { - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bid); } else { - bidObject = bidfactory.createBid(1); + bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bid); bidObject.cpm = bid.price; bidObject.ad = bid.adm; bidObject.width = bid.w; @@ -147,7 +145,7 @@ var TrustxAdapter = function TrustxAdapter() { if (placementMap.hasOwnProperty(auid) && placementMap[auid]) { n = placementMap[auid].length; while (n--) { - bidObj = bidfactory.createBid(2); + bidObj = bidfactory.createBid(CONSTANTS.STATUS.NO_BID); bidObj.bidderCode = bidderCode; bidmanager.addBidResponse(placementMap[auid][n], bidObj); } From 843440dd0f923e2e77c86bac1f5a8e7591f97b1c Mon Sep 17 00:00:00 2001 From: Paul Wyrembak Date: Tue, 10 Oct 2017 17:23:05 +0300 Subject: [PATCH 5/5] Code improvement for trustx adapter: changed default price type from gross to net --- modules/trustxBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/trustxBidAdapter.js b/modules/trustxBidAdapter.js index 44c00c2c0b3..13f893a841d 100644 --- a/modules/trustxBidAdapter.js +++ b/modules/trustxBidAdapter.js @@ -37,7 +37,7 @@ var TrustxAdapter = function TrustxAdapter() { query.push('u=' + encodeURIComponent(location.href)); query.push('auids=' + encodeURIComponent(auids.join(','))); query.push('cb=' + _makeHandler(auids, placementMap)); - query.push('pt=' + (window.globalPrebidTrustxPriceType === 'net' ? 'net' : 'gross')); + query.push('pt=' + (window.globalPrebidTrustxPriceType === 'gross' ? 'gross' : 'net')); adloader.loadScript(reqHost + path + query.join('&')); }