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

Livewrapped adapter: Ensure correct winning bid is stored when multiple bids are submitted #12568

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
12 changes: 11 additions & 1 deletion modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
logInfo('LIVEWRAPPED_BID_RESPONSE:', args);

let bidResponse = cache.auctions[args.auctionId].bids[args.requestId];
if (bidResponse.cpm > args.cpm) break; // For now we only store the highest bid
bidResponse.isBid = args.getStatusCode() === STATUS.GOOD;
bidResponse.width = args.width;
bidResponse.height = args.height;
bidResponse.cpm = args.cpm;
bidResponse.originalCpm = prebidGlobal.convertCurrency(args.originalCpm, args.originalCurrency, args.currency);
bidResponse.ttr = args.timeToRespond;
bidResponse.readyToSend = 1;
bidResponse.mediaType = args.mediaType == 'native' ? 2 : (args.mediaType == 'video' ? 4 : 1);
bidResponse.mediaType = getMediaTypeEnum(args.mediaType);
bidResponse.floorData = args.floorData;
bidResponse.meta = args.meta;

Expand Down Expand Up @@ -115,6 +116,11 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
logInfo('LIVEWRAPPED_BID_WON:', args);
let wonBid = cache.auctions[args.auctionId].bids[args.requestId];
wonBid.won = true;
wonBid.width = args.width;
wonBid.height = args.height;
wonBid.cpm = args.cpm;
wonBid.originalCpm = prebidGlobal.convertCurrency(args.originalCpm, args.originalCurrency, args.currency);
wonBid.mediaType = getMediaTypeEnum(args.mediaType);
wonBid.floorData = args.floorData;
wonBid.rUp = args.rUp;
wonBid.meta = args.meta;
Expand Down Expand Up @@ -185,6 +191,10 @@ livewrappedAnalyticsAdapter.sendEvents = function() {
ajax(initOptions.endpoint || URL, undefined, JSON.stringify(events), {method: 'POST'});
};

function getMediaTypeEnum(mediaType) {
return mediaType == 'native' ? 2 : (mediaType == 'video' ? 4 : 1);
}

function getSentRequests() {
var sentRequests = [];
var gdpr = [];
Expand Down
61 changes: 60 additions & 1 deletion test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ const BID2 = Object.assign({}, BID1, {
dealId: undefined
});

const BID2_2 = Object.assign({}, BID2, {
width: 320,
height: 320,
cpm: 10.0,
originalCpm: 20.0,
currency: 'USD',
originalCurrency: 'FOO',
timeToRespond: 300,
bidId: '3ecff0db240758',
requestId: '3ecff0db240757',
adId: '3ecff0db240758',
mediaType: 'video',
meta: {
data: 'value2_2'
},
dealId: 'deal2_2'
});

const BID3 = {
bidId: '4ecff0db240757',
requestId: '4ecff0db240757',
Expand Down Expand Up @@ -99,7 +117,8 @@ const MOCK = {
},
BID_RESPONSE: [
BID1,
BID2
BID2,
BID2_2
],
AUCTION_END: {
},
Expand Down Expand Up @@ -281,6 +300,7 @@ function performStandardAuction() {
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[2]);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);
Expand Down Expand Up @@ -643,5 +663,44 @@ describe('Livewrapped analytics adapter', function () {
expect(message.ext).to.not.equal(null);
expect(message.ext.testparam).to.equal(123);
});

it('should forward the correct winning bid from a multi-bid response', function () {
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[2]);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);
events.emit(BID_WON, Object.assign({}, BID2_2, {
'status': 'rendered',
'requestId': '3ecff0db240757'
}));

clock.tick(BID_WON_TIMEOUT + 1000);

expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);

expect(message.wins.length).to.equal(1);
expect(message.wins[0]).to.deep.equal({
timeStamp: 1519149562216,
adUnit: 'box_d_1',
adUnitId: 'adunitid',
bidder: 'livewrapped',
width: 320,
height: 320,
cpm: 10.0,
orgCpm: 200,
mediaType: 4,
dealId: 'deal2_2',
gdpr: 0,
auctionId: 0,
meta: {
data: 'value2_2'
}
});
});
});
});
Loading