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

Do client-side user syncs when using the OpenRTB endpoint #2410

Merged
merged 1 commit into from
Apr 30, 2018
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
23 changes: 15 additions & 8 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -645,6 +651,7 @@ export function PrebidServer() {
}

done();
doClientSideSyncs(requestedBidders);
}

return Object.assign(this, {
Expand Down
20 changes: 20 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down