diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index 413147b4fa4..ec8fea42bac 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -77,6 +77,7 @@ 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; @@ -84,7 +85,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE 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; @@ -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; @@ -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 = []; diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index 1e5f089ca53..4b7f7bc2bac 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -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', @@ -99,7 +117,8 @@ const MOCK = { }, BID_RESPONSE: [ BID1, - BID2 + BID2, + BID2_2 ], AUCTION_END: { }, @@ -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); @@ -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' + } + }); + }); }); });