From f6ce8f287d0cd317d0bc06a13475ac9d11c86096 Mon Sep 17 00:00:00 2001 From: Haohan Yang Date: Mon, 16 Apr 2018 18:19:34 -0700 Subject: [PATCH] Do client-side user syncs when using the OpenRTB endpoint --- modules/prebidServerBidAdapter.js | 23 ++++++++++++------- .../modules/prebidServerBidAdapter_spec.js | 20 ++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index e12f569b3b2..775a6c1035a 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -149,6 +149,20 @@ function doBidderSync(type, url, bidder) { } } +/** + * Do client-side syncs for bidders. + * + * @param {Array} bidders a list of bidder names + */ +function doClientSideSyncs(bidders) { + bidders.forEach(bidder => { + let clientAdapter = adaptermanager.getBidAdapter(bidder); + if (clientAdapter && clientAdapter.registerSyncs) { + clientAdapter.registerSyncs([]); + } + }); +} + /** * Try to convert a value to a type. * If it can't be done, the value will be returned. @@ -338,14 +352,6 @@ const LEGACY_PROTOCOL = { }); } - // do client-side syncs if available - requestedBidders.forEach(bidder => { - let clientAdapter = adaptermanager.getBidAdapter(bidder); - if (clientAdapter && clientAdapter.registerSyncs) { - clientAdapter.registerSyncs([]); - } - }); - if (result.bids) { result.bids.forEach(bidObj => { const bidRequest = utils.getBidRequest(bidObj.bid_id, bidRequests); @@ -645,6 +651,7 @@ export function PrebidServer() { } done(); + doClientSideSyncs(requestedBidders); } return Object.assign(this, { diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index d525db857bc..a44587a71e6 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -703,6 +703,26 @@ describe('S2S Adapter', () => { adapterManager.getBidAdapter.restore(); }); + it('registers client user syncs when using OpenRTB endpoint', () => { + let rubiconAdapter = { + registerSyncs: sinon.spy() + }; + sinon.stub(adapterManager, 'getBidAdapter').returns(rubiconAdapter); + + const s2sConfig = Object.assign({}, CONFIG, { + endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' + }); + config.setConfig({s2sConfig}); + + server.respondWith(JSON.stringify(RESPONSE_OPENRTB)); + adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + server.respond(); + + sinon.assert.calledOnce(rubiconAdapter.registerSyncs); + + adapterManager.getBidAdapter.restore(); + }); + it('registers bid responses when server requests cookie sync', () => { server.respondWith(JSON.stringify(RESPONSE_NO_PBS_COOKIE));