From c775f65611bae4470e2a61c8ed18af4cae66e7ee Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Tue, 29 Aug 2017 17:36:33 -0400 Subject: [PATCH 01/14] init commit realvuAnalyticsAdapter.js --- modules/realvuAnalyticsAdapter.js | 17 +++++++++++++++++ yarn.lock | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 modules/realvuAnalyticsAdapter.js diff --git a/modules/realvuAnalyticsAdapter.js b/modules/realvuAnalyticsAdapter.js new file mode 100644 index 00000000000..87926e58953 --- /dev/null +++ b/modules/realvuAnalyticsAdapter.js @@ -0,0 +1,17 @@ +// RealVu Analytics Adapter +import adapter from 'src/AnalyticsAdapter'; +import adaptermanager from 'src/adaptermanager'; + +var adloader = require('src/adloader'); + +const utils = require('src/utils'); +const url = '//ac.realvu.net/realvu_boost.js'; + +var realvuAdapter = adapter({global:'realvu_ana', handler:'on', analyticsType: 'library'}); + +adaptermanager.registerAnalyticsAdapter({ + adapter: realvuAdapter, + code: 'realvu_code' +}); + +adloader.loadScript(url,null,true); diff --git a/yarn.lock b/yarn.lock index 41b523bcbcc..d14d5c36a6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1945,7 +1945,7 @@ d@1: dependencies: es5-ext "^0.10.9" -"dargs@github:christian-bromann/dargs": +dargs@christian-bromann/dargs: version "4.0.1" resolved "https://codeload.github.com/christian-bromann/dargs/tar.gz/7d6d4164a7c4106dbd14ef39ed8d95b7b5e9b770" dependencies: From 4cdb383a277c7700cb80c8ff28a9565dceeca5a8 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Wed, 30 Aug 2017 13:18:49 -0400 Subject: [PATCH 02/14] realvuBidAdapter.js initial commit --- modules/realvuAnalyticsAdapter.js | 2 +- modules/realvuBidAdapter.js | 52 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 modules/realvuBidAdapter.js diff --git a/modules/realvuAnalyticsAdapter.js b/modules/realvuAnalyticsAdapter.js index 87926e58953..fee6992afbc 100644 --- a/modules/realvuAnalyticsAdapter.js +++ b/modules/realvuAnalyticsAdapter.js @@ -7,7 +7,7 @@ var adloader = require('src/adloader'); const utils = require('src/utils'); const url = '//ac.realvu.net/realvu_boost.js'; -var realvuAdapter = adapter({global:'realvu_ana', handler:'on', analyticsType: 'library'}); +var realvuAnalyticsAdapter = adapter({global:'realvu_ana', handler:'on', analyticsType: 'library'}); adaptermanager.registerAnalyticsAdapter({ adapter: realvuAdapter, diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js new file mode 100644 index 00000000000..b744a39c33a --- /dev/null +++ b/modules/realvuBidAdapter.js @@ -0,0 +1,52 @@ +var utils = require('src/utils.js'); +var adloader = require('src/adloader.js'); +var bidmanager = require('src/bidmanager.js'); +var bidfactory = require('src/bidfactory.js'); +var Adapter = require('src/adapter.js'); +var AppnexusAdapter = require('./appnexusBidAdapter.js'); + +var realvuAdapter = function realvuAdapter() { + var baseAdapter = Adapter.createNew('realvu'); + baseAdapter.callBids = function (params) { + var pbids = params.bids; + // + utils.logMessage('realvuBidAdapter params: '+JSON.stringify(params)); + var boost_back = function(){ + var adap=AppnexusAdapter.createNew(); + var in_back=function(rez){ + var bid_request = rez.pin.pbjs_bid; + var callbackId = bid_request.bidId; + // + utils.logMessage('realvuBidAdapter boost callback "'+callbackId+'", rez.realvu='+rez.realvu); + if(rez.realvu==='yes'){ + adloader.loadScript(adap.buildJPTCall(bid_request, callbackId)); + } + else { // not in view - respond with no bid. + var adResponse = bidfactory.createBid(2); + adResponse.bidderCode = 'realvu'; + bidmanager.addBidResponse(bid_request.placementCode, adResponse); + } + }; + for(var i=0;i Date: Thu, 31 Aug 2017 13:03:44 -0400 Subject: [PATCH 03/14] realvuBidAdapter fixed for latest version --- modules/realvuBidAdapter.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index b744a39c33a..e0375691d54 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -1,19 +1,21 @@ +import adaptermanager from 'src/adaptermanager'; + var utils = require('src/utils.js'); var adloader = require('src/adloader.js'); var bidmanager = require('src/bidmanager.js'); var bidfactory = require('src/bidfactory.js'); -var Adapter = require('src/adapter.js'); +var Adapter = require('src/adapter.js').default; var AppnexusAdapter = require('./appnexusBidAdapter.js'); var realvuAdapter = function realvuAdapter() { - var baseAdapter = Adapter.createNew('realvu'); + var baseAdapter = new Adapter('realvu'); baseAdapter.callBids = function (params) { var pbids = params.bids; // utils.logMessage('realvuBidAdapter params: '+JSON.stringify(params)); var boost_back = function(){ - var adap=AppnexusAdapter.createNew(); - var in_back=function(rez){ + var adap = new AppnexusAdapter(); + var in_back = function(rez){ var bid_request = rez.pin.pbjs_bid; var callbackId = bid_request.bidId; // @@ -43,10 +45,12 @@ var realvuAdapter = function realvuAdapter() { adloader.loadScript("//ac.realvu.net/realvu_boost.js",boost_back,1 ); }; - return { + return Object.assign(this, { callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - createNew: exports.createNew - }; + setBidderCode: baseAdapter.setBidderCode + }); }; + +adaptermanager.registerBidAdapter(new realvuAdapter(), 'realvu'); + module.exports = realvuAdapter; From e6cc8ba9dded23e4004eb1c28b1cd9118c04646c Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Thu, 31 Aug 2017 15:45:09 -0400 Subject: [PATCH 04/14] realvuBidAdapter unit_id:bid.code --- modules/realvuBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index e0375691d54..ab1a122acb1 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -34,7 +34,7 @@ var realvuAdapter = function realvuAdapter() { var sizes = utils.parseSizesInput(bid_rq.sizes); top.realvu_boost.addUnitById({ partner_id: bid_rq.params.partnerId, - unit_id: bid_rq.params.unitId, + unit_id: bid_rq.code, callback:in_back, pbjs_bid:bid_rq, size:sizes[0], From 975df01482198e93072311e5fad0e7a6090b1c89 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Tue, 5 Sep 2017 10:45:38 -0400 Subject: [PATCH 05/14] tabs and spaces --- modules/realvuAnalyticsAdapter.js | 10 ++++----- modules/realvuBidAdapter.js | 34 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/realvuAnalyticsAdapter.js b/modules/realvuAnalyticsAdapter.js index fee6992afbc..1f7aa4af358 100644 --- a/modules/realvuAnalyticsAdapter.js +++ b/modules/realvuAnalyticsAdapter.js @@ -4,14 +4,14 @@ import adaptermanager from 'src/adaptermanager'; var adloader = require('src/adloader'); -const utils = require('src/utils'); const url = '//ac.realvu.net/realvu_boost.js'; -var realvuAnalyticsAdapter = adapter({global:'realvu_ana', handler:'on', analyticsType: 'library'}); +var realvuAnalyticsAdapter = adapter({global:'RealVuPrebidAnalytics', handler:'on', analyticsType: 'library'}); adaptermanager.registerAnalyticsAdapter({ - adapter: realvuAdapter, - code: 'realvu_code' + adapter: realvuAnalyticsAdapter, + code: 'realvu' }); -adloader.loadScript(url,null,true); +adloader.loadScript(url, null, true); +export default realvuAnalyticsAdapter; diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index ab1a122acb1..63df1ec5f16 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -7,20 +7,20 @@ var bidfactory = require('src/bidfactory.js'); var Adapter = require('src/adapter.js').default; var AppnexusAdapter = require('./appnexusBidAdapter.js'); -var realvuAdapter = function realvuAdapter() { +var RealVuAdapter = function RealVuAdapter() { var baseAdapter = new Adapter('realvu'); baseAdapter.callBids = function (params) { var pbids = params.bids; - // - utils.logMessage('realvuBidAdapter params: '+JSON.stringify(params)); - var boost_back = function(){ + + utils.logMessage('realvuBidAdapter params: ' + JSON.stringify(params)); + var boost_back = function() { var adap = new AppnexusAdapter(); - var in_back = function(rez){ + var in_back = function(rez) { var bid_request = rez.pin.pbjs_bid; var callbackId = bid_request.bidId; - // - utils.logMessage('realvuBidAdapter boost callback "'+callbackId+'", rez.realvu='+rez.realvu); - if(rez.realvu==='yes'){ + + utils.logMessage('realvuBidAdapter boost callback "' + callbackId + '", rez.realvu=' + rez.realvu); + if (rez.realvu === 'yes') { adloader.loadScript(adap.buildJPTCall(bid_request, callbackId)); } else { // not in view - respond with no bid. @@ -29,20 +29,20 @@ var realvuAdapter = function realvuAdapter() { bidmanager.addBidResponse(bid_request.placementCode, adResponse); } }; - for(var i=0;i Date: Thu, 7 Sep 2017 13:35:45 -0400 Subject: [PATCH 06/14] test implemented --- modules/realvuAnalyticsAdapter.js | 2 +- modules/realvuBidAdapter.js | 39 ++++++++--------- test/spec/modules/realvuBidAdapter_spec.js | 50 ++++++++++++++++++++++ 3 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 test/spec/modules/realvuBidAdapter_spec.js diff --git a/modules/realvuAnalyticsAdapter.js b/modules/realvuAnalyticsAdapter.js index 1f7aa4af358..65f1eac5fa7 100644 --- a/modules/realvuAnalyticsAdapter.js +++ b/modules/realvuAnalyticsAdapter.js @@ -6,7 +6,7 @@ var adloader = require('src/adloader'); const url = '//ac.realvu.net/realvu_boost.js'; -var realvuAnalyticsAdapter = adapter({global:'RealVuPrebidAnalytics', handler:'on', analyticsType: 'library'}); +var realvuAnalyticsAdapter = adapter({global: 'RealVuPrebidAnalytics', handler: 'on', analyticsType: 'library'}); adaptermanager.registerAnalyticsAdapter({ adapter: realvuAnalyticsAdapter, diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index 63df1ec5f16..b779eb2337f 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -10,32 +10,16 @@ var AppnexusAdapter = require('./appnexusBidAdapter.js'); var RealVuAdapter = function RealVuAdapter() { var baseAdapter = new Adapter('realvu'); baseAdapter.callBids = function (params) { + // utils.logMessage('realvuBidAdapter params: ' + JSON.stringify(params)); var pbids = params.bids; - - utils.logMessage('realvuBidAdapter params: ' + JSON.stringify(params)); var boost_back = function() { - var adap = new AppnexusAdapter(); - var in_back = function(rez) { - var bid_request = rez.pin.pbjs_bid; - var callbackId = bid_request.bidId; - - utils.logMessage('realvuBidAdapter boost callback "' + callbackId + '", rez.realvu=' + rez.realvu); - if (rez.realvu === 'yes') { - adloader.loadScript(adap.buildJPTCall(bid_request, callbackId)); - } - else { // not in view - respond with no bid. - var adResponse = bidfactory.createBid(2); - adResponse.bidderCode = 'realvu'; - bidmanager.addBidResponse(bid_request.placementCode, adResponse); - } - }; for (var i = 0; i < pbids.length; i++) { var bid_rq = pbids[i]; var sizes = utils.parseSizesInput(bid_rq.sizes); top.realvu_boost.addUnitById({ partner_id: bid_rq.params.partnerId, - unit_id: bid_rq.code, - callback: in_back, + unit_id: bid_rq.placementCode, + callback: baseAdapter.boostCall, pbjs_bid: bid_rq, size: sizes[0], mode: 'kvp' @@ -45,9 +29,24 @@ var RealVuAdapter = function RealVuAdapter() { adloader.loadScript('//ac.realvu.net/realvu_boost.js', boost_back, 1); }; + baseAdapter.boostCall = function(rez) { + var bid_request = rez.pin.pbjs_bid; + var callbackId = bid_request.bidId; + // utils.logMessage('realvuBidAdapter boost callback "' + callbackId + '", rez.realvu=' + rez.realvu); + if (rez.realvu === 'yes') { + var adap = new AppnexusAdapter(); + adloader.loadScript(adap.buildJPTCall(bid_request, callbackId)); + } else { // not in view - respond with no bid. + var adResponse = bidfactory.createBid(2); + adResponse.bidderCode = 'realvu'; + bidmanager.addBidResponse(bid_request.placementCode, adResponse); + } + }; + return Object.assign(this, { callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode + setBidderCode: baseAdapter.setBidderCode, + boostCall: baseAdapter.boostCall }); }; diff --git a/test/spec/modules/realvuBidAdapter_spec.js b/test/spec/modules/realvuBidAdapter_spec.js new file mode 100644 index 00000000000..b6e1eb946e9 --- /dev/null +++ b/test/spec/modules/realvuBidAdapter_spec.js @@ -0,0 +1,50 @@ +import {expect} from 'chai'; +import Adapter from '../../../modules/realvuBidAdapter'; +import bidmanager from '../../../src/bidmanager'; +import adloader from '../../../src/adloader'; + +describe('RealVu Adapter Test', () => { + let adapter; + + const REQUEST = { + bidderCode: 'realvu', + requestId: '0d67ddab-1502-4897-a7bf-e8078e983405', + bidderRequestId: '1b5e314fe79b1d', + bids: [ + { + bidId: '2d86a04312d95d', + bidder: 'realvu', + bidderRequestId: '1b5e314fe79b1d', + // mediaType:undefined, + params: { + partnerId: '1Y', + placementId: '9339508', + }, + placementCode: 'ad_container_1', + // renderer:undefined, + sizes: [[300, 250]], + transactionId: '0d67ddab-1502-4897-a7bf-e8078e983405' + } + ], + start: 1504628062271 + }; + + var bidResponseStub = sinon.stub(bidmanager, 'addBidResponse'); + var adloaderStub = sinon.stub(adloader, 'loadScript'); + adapter = new Adapter(); + + describe('load boost', () => { + adapter.callBids(REQUEST); + expect(adloaderStub.getCall(0).args[0]).to.contain('realvu_boost.js'); + }); + + describe('callBid "yes"', () => { + adapter.boostCall({realvu: 'yes', pin: {pbjs_bid: REQUEST.bids[0]}}); + expect(adloaderStub.getCall(1).args[0]).to.contain('id=9339508'); + }); + + describe('callBid "no"', () => { + adapter.boostCall({realvu: 'no', pin: {pbjs_bid: REQUEST.bids[0]}}); + expect(bidResponseStub.getCall(0).args[1].getStatusCode()).to.equal(2); + }); +}); From e3d099c6a381f24f2bc6036317c9488c6e7b6dab Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Thu, 7 Sep 2017 13:55:37 -0400 Subject: [PATCH 07/14] postpone analytics --- modules/realvuAnalyticsAdapter.js | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 modules/realvuAnalyticsAdapter.js diff --git a/modules/realvuAnalyticsAdapter.js b/modules/realvuAnalyticsAdapter.js deleted file mode 100644 index 65f1eac5fa7..00000000000 --- a/modules/realvuAnalyticsAdapter.js +++ /dev/null @@ -1,17 +0,0 @@ -// RealVu Analytics Adapter -import adapter from 'src/AnalyticsAdapter'; -import adaptermanager from 'src/adaptermanager'; - -var adloader = require('src/adloader'); - -const url = '//ac.realvu.net/realvu_boost.js'; - -var realvuAnalyticsAdapter = adapter({global: 'RealVuPrebidAnalytics', handler: 'on', analyticsType: 'library'}); - -adaptermanager.registerAnalyticsAdapter({ - adapter: realvuAnalyticsAdapter, - code: 'realvu' -}); - -adloader.loadScript(url, null, true); -export default realvuAnalyticsAdapter; From 185856f92dc3b9580498eca06926cf45da2b08c1 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Thu, 14 Sep 2017 07:33:28 -0400 Subject: [PATCH 08/14] try-catch for top --- modules/realvuBidAdapter.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index b779eb2337f..f4dce10aa34 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -13,10 +13,19 @@ var RealVuAdapter = function RealVuAdapter() { // utils.logMessage('realvuBidAdapter params: ' + JSON.stringify(params)); var pbids = params.bids; var boost_back = function() { + var top1 = window; + realvu_frm = 0; + try { + var wnd = window; + while ((top1 != top) && (typeof (wnd.document) != 'undefined')) { + top1 = wnd; + wnd = wnd.parent; + } + } catch (e) { }; for (var i = 0; i < pbids.length; i++) { var bid_rq = pbids[i]; var sizes = utils.parseSizesInput(bid_rq.sizes); - top.realvu_boost.addUnitById({ + top1.realvu_boost.addUnitById({ partner_id: bid_rq.params.partnerId, unit_id: bid_rq.placementCode, callback: baseAdapter.boostCall, From 98b2ef1011da35d94429e898a61ceff2290a82c0 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Fri, 29 Sep 2017 16:09:13 -0400 Subject: [PATCH 09/14] appnexusBidAdapter inline --- modules/realvuBidAdapter.js | 220 +++++++++++++++++++++++++++++++++++- 1 file changed, 218 insertions(+), 2 deletions(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index f4dce10aa34..05f1f410211 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -1,11 +1,13 @@ +import { getBidRequest } from 'src/utils'; import adaptermanager from 'src/adaptermanager'; +var CONSTANTS = require('src/constants'); var utils = require('src/utils.js'); var adloader = require('src/adloader.js'); var bidmanager = require('src/bidmanager.js'); var bidfactory = require('src/bidfactory.js'); var Adapter = require('src/adapter.js').default; -var AppnexusAdapter = require('./appnexusBidAdapter.js'); +// var AppnexusAdapter = require('./appnexusBidAdapter.js'); var RealVuAdapter = function RealVuAdapter() { var baseAdapter = new Adapter('realvu'); @@ -43,7 +45,7 @@ var RealVuAdapter = function RealVuAdapter() { var callbackId = bid_request.bidId; // utils.logMessage('realvuBidAdapter boost callback "' + callbackId + '", rez.realvu=' + rez.realvu); if (rez.realvu === 'yes') { - var adap = new AppnexusAdapter(); + var adap = new RvAppNexusAdapter(); adloader.loadScript(adap.buildJPTCall(bid_request, callbackId)); } else { // not in view - respond with no bid. var adResponse = bidfactory.createBid(2); @@ -52,6 +54,220 @@ var RealVuAdapter = function RealVuAdapter() { } }; + // +copy/pasted appnexusBidAdapter, "handleAnCB" replaced with "handleRvAnCB" + var RvAppNexusAdapter = function RvAppNexusAdapter() { + var baseAdapter = new Adapter('appnexus'); + var usersync = false; + + baseAdapter.callBids = function (params) { + // var bidCode = baseAdapter.getBidderCode(); + + var anArr = params.bids; + + // var bidsCount = anArr.length; + + // set expected bids count for callback execution + // bidmanager.setExpectedBidsCount(bidCode, bidsCount); + + for (var i = 0; i < anArr.length; i++) { + var bidRequest = anArr[i]; + var callbackId = bidRequest.bidId; + adloader.loadScript(buildJPTCall(bidRequest, callbackId)); + + // store a reference to the bidRequest from the callback id + // bidmanager.pbCallbackMap[callbackId] = bidRequest; + } + }; + + this.buildJPTCall = function (bid, callbackId) { + // determine tag params + var placementId = utils.getBidIdParameter('placementId', bid.params); + + // memberId will be deprecated, use member instead + var memberId = utils.getBidIdParameter('memberId', bid.params); + var member = utils.getBidIdParameter('member', bid.params); + var inventoryCode = utils.getBidIdParameter('invCode', bid.params); + var query = utils.getBidIdParameter('query', bid.params); + var referrer = utils.getBidIdParameter('referrer', bid.params); + var altReferrer = utils.getBidIdParameter('alt_referrer', bid.params); + var jptCall = '//ib.adnxs.com/jpt?'; + + jptCall = utils.tryAppendQueryString(jptCall, 'callback', '$$PREBID_GLOBAL$$.handleRvAnCB'); + jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); + jptCall = utils.tryAppendQueryString(jptCall, 'psa', '0'); + jptCall = utils.tryAppendQueryString(jptCall, 'id', placementId); + if (member) { + jptCall = utils.tryAppendQueryString(jptCall, 'member', member); + } else if (memberId) { + jptCall = utils.tryAppendQueryString(jptCall, 'member', memberId); + utils.logMessage('appnexus.callBids: "memberId" will be deprecated soon. Please use "member" instead'); + } + + jptCall = utils.tryAppendQueryString(jptCall, 'code', inventoryCode); + jptCall = utils.tryAppendQueryString(jptCall, 'traffic_source_code', (utils.getBidIdParameter('trafficSourceCode', bid.params))); + + // sizes takes a bit more logic + var sizeQueryString = ''; + var parsedSizes = utils.parseSizesInput(bid.sizes); + + // combine string into proper querystring for impbus + var parsedSizesLength = parsedSizes.length; + if (parsedSizesLength > 0) { + // first value should be "size" + sizeQueryString = 'size=' + parsedSizes[0]; + if (parsedSizesLength > 1) { + // any subsequent values should be "promo_sizes" + sizeQueryString += '&promo_sizes='; + for (var j = 1; j < parsedSizesLength; j++) { + sizeQueryString += parsedSizes[j] += ','; + } + + // remove trailing comma + if (sizeQueryString && sizeQueryString.charAt(sizeQueryString.length - 1) === ',') { + sizeQueryString = sizeQueryString.slice(0, sizeQueryString.length - 1); + } + } + } + + if (sizeQueryString) { + jptCall += sizeQueryString + '&'; + } + + // this will be deprecated soon + var targetingParams = utils.parseQueryStringParameters(query); + + if (targetingParams) { + // don't append a & here, we have already done it in parseQueryStringParameters + jptCall += targetingParams; + } + + // append custom attributes: + var paramsCopy = Object.assign({}, bid.params); + + // delete attributes already used + delete paramsCopy.placementId; + delete paramsCopy.memberId; + delete paramsCopy.invCode; + delete paramsCopy.query; + delete paramsCopy.referrer; + delete paramsCopy.alt_referrer; + delete paramsCopy.member; + + // get the reminder + var queryParams = utils.parseQueryStringParameters(paramsCopy); + + // append + if (queryParams) { + jptCall += queryParams; + } + + // append referrer + if (referrer === '') { + referrer = utils.getTopWindowUrl(); + } + + jptCall = utils.tryAppendQueryString(jptCall, 'referrer', referrer); + jptCall = utils.tryAppendQueryString(jptCall, 'alt_referrer', altReferrer); + + // remove the trailing "&" + if (jptCall.lastIndexOf('&') === jptCall.length - 1) { + jptCall = jptCall.substring(0, jptCall.length - 1); + } + + // @if NODE_ENV='debug' + utils.logMessage('jpt request built: ' + jptCall); + + // @endif + + // append a timer here to track latency + bid.startTime = new Date().getTime(); + + return jptCall; + } + + // expose the callback to the global object: + $$PREBID_GLOBAL$$.handleRvAnCB = function (jptResponseObj) { + var bidCode; + + if (jptResponseObj && jptResponseObj.callback_uid) { + var responseCPM; + var id = jptResponseObj.callback_uid; + var placementCode = ''; + var bidObj = getBidRequest(id); + if (bidObj) { + bidCode = bidObj.bidder; + + placementCode = bidObj.placementCode; + + // set the status + bidObj.status = CONSTANTS.STATUS.GOOD; + } + + // @if NODE_ENV='debug' + utils.logMessage('JSONP callback function called for ad ID: ' + id); + + // @endif + var bid = []; + if (jptResponseObj.result && jptResponseObj.result.cpm && jptResponseObj.result.cpm !== 0) { + responseCPM = parseInt(jptResponseObj.result.cpm, 10); + + // CPM response from /jpt is dollar/cent multiplied by 10000 + // in order to avoid using floats + // switch CPM to "dollar/cent" + responseCPM = responseCPM / 10000; + + // store bid response + // bid status is good (indicating 1) + var adId = jptResponseObj.result.creative_id; + bid = bidfactory.createBid(1, bidObj); + bid.creative_id = adId; + bid.bidderCode = bidCode; + bid.cpm = responseCPM; + bid.adUrl = jptResponseObj.result.ad; + bid.width = jptResponseObj.result.width; + bid.height = jptResponseObj.result.height; + bid.dealId = jptResponseObj.result.deal_id; + + bidmanager.addBidResponse(placementCode, bid); + } else { + // no response data + // @if NODE_ENV='debug' + utils.logMessage('No prebid response from AppNexus for placement code ' + placementCode); + + // @endif + // indicate that there is no bid for this placement + bid = bidfactory.createBid(2, bidObj); + bid.bidderCode = bidCode; + bidmanager.addBidResponse(placementCode, bid); + } + + if (!usersync) { + var iframe = utils.createInvisibleIframe(); + iframe.src = '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html'; + try { + document.body.appendChild(iframe); + } catch (error) { + utils.logError(error); + } + usersync = true; + } + } else { + // no response data + // @if NODE_ENV='debug' + utils.logMessage('No prebid response for placement %%PLACEMENT%%'); + + // @endif + } + }; + /* + return Object.assign(this, { + callBids: baseAdapter.callBids, + setBidderCode: baseAdapter.setBidderCode, + buildJPTCall: buildJPTCall + }); + */ + }; + // -copy/pasted appnexusBidAdapter return Object.assign(this, { callBids: baseAdapter.callBids, setBidderCode: baseAdapter.setBidderCode, From 89e7c709ad50a32270df7dda2c3d34039ae85128 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Mon, 9 Oct 2017 11:34:25 -0400 Subject: [PATCH 10/14] var replaced with const in require statements --- modules/realvuBidAdapter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index 05f1f410211..633799762bd 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -1,12 +1,12 @@ import { getBidRequest } from 'src/utils'; import adaptermanager from 'src/adaptermanager'; -var CONSTANTS = require('src/constants'); -var utils = require('src/utils.js'); -var adloader = require('src/adloader.js'); -var bidmanager = require('src/bidmanager.js'); -var bidfactory = require('src/bidfactory.js'); -var Adapter = require('src/adapter.js').default; +const CONSTANTS = require('src/constants'); +const utils = require('src/utils.js'); +const adloader = require('src/adloader.js'); +const bidmanager = require('src/bidmanager.js'); +const bidfactory = require('src/bidfactory.js'); +const Adapter = require('src/adapter.js').default; // var AppnexusAdapter = require('./appnexusBidAdapter.js'); var RealVuAdapter = function RealVuAdapter() { From 4d2374fbc9ab1e91d13cd23065b33476b90f525a Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Mon, 16 Oct 2017 17:03:54 -0400 Subject: [PATCH 11/14] unwanted code removed, test fixed --- modules/realvuBidAdapter.js | 42 +--------------------- test/spec/modules/realvuBidAdapter_spec.js | 23 ++++++++---- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index 633799762bd..04e4d9c2e8e 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -7,12 +7,10 @@ const adloader = require('src/adloader.js'); const bidmanager = require('src/bidmanager.js'); const bidfactory = require('src/bidfactory.js'); const Adapter = require('src/adapter.js').default; -// var AppnexusAdapter = require('./appnexusBidAdapter.js'); var RealVuAdapter = function RealVuAdapter() { var baseAdapter = new Adapter('realvu'); baseAdapter.callBids = function (params) { - // utils.logMessage('realvuBidAdapter params: ' + JSON.stringify(params)); var pbids = params.bids; var boost_back = function() { var top1 = window; @@ -43,7 +41,6 @@ var RealVuAdapter = function RealVuAdapter() { baseAdapter.boostCall = function(rez) { var bid_request = rez.pin.pbjs_bid; var callbackId = bid_request.bidId; - // utils.logMessage('realvuBidAdapter boost callback "' + callbackId + '", rez.realvu=' + rez.realvu); if (rez.realvu === 'yes') { var adap = new RvAppNexusAdapter(); adloader.loadScript(adap.buildJPTCall(bid_request, callbackId)); @@ -59,26 +56,6 @@ var RealVuAdapter = function RealVuAdapter() { var baseAdapter = new Adapter('appnexus'); var usersync = false; - baseAdapter.callBids = function (params) { - // var bidCode = baseAdapter.getBidderCode(); - - var anArr = params.bids; - - // var bidsCount = anArr.length; - - // set expected bids count for callback execution - // bidmanager.setExpectedBidsCount(bidCode, bidsCount); - - for (var i = 0; i < anArr.length; i++) { - var bidRequest = anArr[i]; - var callbackId = bidRequest.bidId; - adloader.loadScript(buildJPTCall(bidRequest, callbackId)); - - // store a reference to the bidRequest from the callback id - // bidmanager.pbCallbackMap[callbackId] = bidRequest; - } - }; - this.buildJPTCall = function (bid, callbackId) { // determine tag params var placementId = utils.getBidIdParameter('placementId', bid.params); @@ -176,7 +153,6 @@ var RealVuAdapter = function RealVuAdapter() { // @if NODE_ENV='debug' utils.logMessage('jpt request built: ' + jptCall); - // @endif // append a timer here to track latency @@ -230,12 +206,7 @@ var RealVuAdapter = function RealVuAdapter() { bidmanager.addBidResponse(placementCode, bid); } else { - // no response data - // @if NODE_ENV='debug' - utils.logMessage('No prebid response from AppNexus for placement code ' + placementCode); - - // @endif - // indicate that there is no bid for this placement + // no bid bid = bidfactory.createBid(2, bidObj); bid.bidderCode = bidCode; bidmanager.addBidResponse(placementCode, bid); @@ -252,20 +223,9 @@ var RealVuAdapter = function RealVuAdapter() { usersync = true; } } else { - // no response data - // @if NODE_ENV='debug' utils.logMessage('No prebid response for placement %%PLACEMENT%%'); - - // @endif } }; - /* - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - buildJPTCall: buildJPTCall - }); - */ }; // -copy/pasted appnexusBidAdapter return Object.assign(this, { diff --git a/test/spec/modules/realvuBidAdapter_spec.js b/test/spec/modules/realvuBidAdapter_spec.js index b6e1eb946e9..fc7ca3486ff 100644 --- a/test/spec/modules/realvuBidAdapter_spec.js +++ b/test/spec/modules/realvuBidAdapter_spec.js @@ -29,21 +29,32 @@ describe('RealVu Adapter Test', () => { start: 1504628062271 }; - var bidResponseStub = sinon.stub(bidmanager, 'addBidResponse'); - var adloaderStub = sinon.stub(adloader, 'loadScript'); + var bidResponseStub; + var adloaderStub; + + beforeEach(function(){ + bidResponseStub = sinon.stub(bidmanager, 'addBidResponse'); + adloaderStub = sinon.stub(adloader, 'loadScript'); + }); + + afterEach(function(){ + adloaderStub.restore(); + bidResponseStub.restore(); + }); + adapter = new Adapter(); - describe('load boost', () => { + it('load boost', () => { adapter.callBids(REQUEST); expect(adloaderStub.getCall(0).args[0]).to.contain('realvu_boost.js'); }); - describe('callBid "yes"', () => { + it('callBid "yes"', () => { adapter.boostCall({realvu: 'yes', pin: {pbjs_bid: REQUEST.bids[0]}}); - expect(adloaderStub.getCall(1).args[0]).to.contain('id=9339508'); + expect(adloaderStub.getCall(0).args[0]).to.contain('id=9339508'); }); - describe('callBid "no"', () => { + it('callBid "no"', () => { adapter.boostCall({realvu: 'no', pin: {pbjs_bid: REQUEST.bids[0]}}); expect(bidResponseStub.getCall(0).args[1].getStatusCode()).to.equal(2); }); From 1e0c4035d424afee6b746b0769f51cee0a932286 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Tue, 17 Oct 2017 12:00:21 -0400 Subject: [PATCH 12/14] lint and test-coverage fix --- modules/realvuBidAdapter.js | 7 +++---- test/spec/modules/realvuBidAdapter_spec.js | 8 ++++---- yarn.lock | 4 ++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index 04e4d9c2e8e..63c6aee72b4 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -8,7 +8,7 @@ const bidmanager = require('src/bidmanager.js'); const bidfactory = require('src/bidfactory.js'); const Adapter = require('src/adapter.js').default; -var RealVuAdapter = function RealVuAdapter() { +var realvuAdapter = function realvuAdapter() { var baseAdapter = new Adapter('realvu'); baseAdapter.callBids = function (params) { var pbids = params.bids; @@ -53,7 +53,6 @@ var RealVuAdapter = function RealVuAdapter() { // +copy/pasted appnexusBidAdapter, "handleAnCB" replaced with "handleRvAnCB" var RvAppNexusAdapter = function RvAppNexusAdapter() { - var baseAdapter = new Adapter('appnexus'); var usersync = false; this.buildJPTCall = function (bid, callbackId) { @@ -235,6 +234,6 @@ var RealVuAdapter = function RealVuAdapter() { }); }; -adaptermanager.registerBidAdapter(new RealVuAdapter(), 'realvu'); +adaptermanager.registerBidAdapter(new realvuAdapter(), 'realvu'); -module.exports = RealVuAdapter; +module.exports = realvuAdapter; diff --git a/test/spec/modules/realvuBidAdapter_spec.js b/test/spec/modules/realvuBidAdapter_spec.js index fc7ca3486ff..639a980cadd 100644 --- a/test/spec/modules/realvuBidAdapter_spec.js +++ b/test/spec/modules/realvuBidAdapter_spec.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import Adapter from '../../../modules/realvuBidAdapter'; +import realvuAdapter from '../../../modules/realvuBidAdapter'; import bidmanager from '../../../src/bidmanager'; import adloader from '../../../src/adloader'; @@ -32,17 +32,17 @@ describe('RealVu Adapter Test', () => { var bidResponseStub; var adloaderStub; - beforeEach(function(){ + beforeEach(function() { bidResponseStub = sinon.stub(bidmanager, 'addBidResponse'); adloaderStub = sinon.stub(adloader, 'loadScript'); }); - afterEach(function(){ + afterEach(function() { adloaderStub.restore(); bidResponseStub.restore(); }); - adapter = new Adapter(); + adapter = new realvuAdapter(); it('load boost', () => { adapter.callBids(REQUEST); diff --git a/yarn.lock b/yarn.lock index f6efe31c6a5..30e6b93b544 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4249,6 +4249,10 @@ ieee754@^1.1.4: version "1.1.8" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" +ignore-loader@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/ignore-loader/-/ignore-loader-0.1.2.tgz#d81f240376d0ba4f0d778972c3ad25874117a463" + ignore@^3.3.3: version "3.3.5" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.5.tgz#c4e715455f6073a8d7e5dae72d2fc9d71663dba6" From a316cfc98301a21d8d7cdcdba278bd2c69205017 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Tue, 17 Oct 2017 13:11:25 -0400 Subject: [PATCH 13/14] lint fix --- modules/realvuBidAdapter.js | 6 +++--- test/spec/modules/realvuBidAdapter_spec.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index 63c6aee72b4..b3e0e4f043f 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -8,7 +8,7 @@ const bidmanager = require('src/bidmanager.js'); const bidfactory = require('src/bidfactory.js'); const Adapter = require('src/adapter.js').default; -var realvuAdapter = function realvuAdapter() { +var RealVuAdapter = function RealVuAdapter() { var baseAdapter = new Adapter('realvu'); baseAdapter.callBids = function (params) { var pbids = params.bids; @@ -234,6 +234,6 @@ var realvuAdapter = function realvuAdapter() { }); }; -adaptermanager.registerBidAdapter(new realvuAdapter(), 'realvu'); +adaptermanager.registerBidAdapter(new RealVuAdapter(), 'realvu'); -module.exports = realvuAdapter; +module.exports = RealVuAdapter; diff --git a/test/spec/modules/realvuBidAdapter_spec.js b/test/spec/modules/realvuBidAdapter_spec.js index 639a980cadd..36517fa723e 100644 --- a/test/spec/modules/realvuBidAdapter_spec.js +++ b/test/spec/modules/realvuBidAdapter_spec.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import realvuAdapter from '../../../modules/realvuBidAdapter'; +import RealVuAdapter from '../../../modules/realvuBidAdapter'; import bidmanager from '../../../src/bidmanager'; import adloader from '../../../src/adloader'; @@ -42,7 +42,7 @@ describe('RealVu Adapter Test', () => { bidResponseStub.restore(); }); - adapter = new realvuAdapter(); + adapter = new RealVuAdapter(); it('load boost', () => { adapter.callBids(REQUEST); From b55d6a6929921a2554dd26df833ced9e1f348df4 Mon Sep 17 00:00:00 2001 From: Igor Tchibirev Date: Fri, 3 Nov 2017 09:39:23 -0400 Subject: [PATCH 14/14] unused variable removed --- modules/realvuBidAdapter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/realvuBidAdapter.js b/modules/realvuBidAdapter.js index b3e0e4f043f..dfed3d64370 100644 --- a/modules/realvuBidAdapter.js +++ b/modules/realvuBidAdapter.js @@ -14,7 +14,6 @@ var RealVuAdapter = function RealVuAdapter() { var pbids = params.bids; var boost_back = function() { var top1 = window; - realvu_frm = 0; try { var wnd = window; while ((top1 != top) && (typeof (wnd.document) != 'undefined')) {