Skip to content

Commit

Permalink
Merged in yhhuang@correct-timeout-handling (pull request prebid#20)
Browse files Browse the repository at this point in the history
handle timeout status message correctly.
  • Loading branch information
yhhuang-appier committed Mar 25, 2019
2 parents 53925d0 + f4c77b7 commit ebed9df
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
26 changes: 20 additions & 6 deletions modules/appierAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,27 @@ export const appierAnalyticsAdapter = Object.assign(adapter({DEFAULT_SERVER, ana
const bidderCode = this.parseBidderCode(bid);
for (let bid of bid.bids) {
const adUnitCode = this.parseAdUnitCode(bid);
const cachedBid = cacheManager.getBidsCache(bid.auctionId, adUnitCode, bidderCode);
cacheManager.updateBidsCache(bid.auctionId, adUnitCode, bidderCode, {
'isTimeout': cacheManager.getStatus(bid.auctionId, adUnitCode) === AUCTION_STATUS.COMPLETED
'isTimeout': cacheManager.getStatus(bid.auctionId, adUnitCode) === AUCTION_STATUS.COMPLETED ||
cachedBid.status === BIDDER_STATUS.TIMEOUT
});
}
},
handleBidResponseMessage(bid) {
const adUnitCode = this.parseAdUnitCode(bid);
const bidderCode = this.parseBidderCode(bid);
const cachedBid = cacheManager.getBidsCache(bid.auctionId, adUnitCode, bidderCode);
cacheManager.updateBidsCache(bid.auctionId, adUnitCode, bidderCode, {
'time': bid.timeToRespond,
'status': BIDDER_STATUS.BID,
'status': (cachedBid.status === BIDDER_STATUS.TIMEOUT) ? BIDDER_STATUS.TIMEOUT : BIDDER_STATUS.BID,
'cpm': bid.cpm,
'currency': bid.currency,
'originalCpm': bid.originalCpm || bid.cpm,
'cpmUsd': getCpmInUsd(bid),
'originalCurrency': bid.originalCurrency || bid.currency,
'isTimeout': cacheManager.getStatus(bid.auctionId, adUnitCode) === AUCTION_STATUS.FINISHED,
'isTimeout': cacheManager.getStatus(bid.auctionId, adUnitCode) === AUCTION_STATUS.COMPLETED ||
cachedBid.status === BIDDER_STATUS.TIMEOUT,
'prebidWon': false
});
},
Expand Down Expand Up @@ -257,9 +261,19 @@ export const appierAnalyticsAdapter = Object.assign(adapter({DEFAULT_SERVER, ana
for (let noBid of auction.noBids) {
const adUnitCode = this.parseAdUnitCode(noBid);
const bidderCode = this.parseBidderCode(noBid);
cacheManager.updateBidsCache(auction.auctionId, adUnitCode, bidderCode, {
'status': BIDDER_STATUS.NO_BID
});
const cachedBid = cacheManager.getBidsCache(auction.auctionId, adUnitCode, bidderCode);
if (cachedBid.status === BIDDER_STATUS.TIMEOUT ||
cacheManager.getStatus(auction.auctionId, adUnitCode) === AUCTION_STATUS.COMPLETED) {
cacheManager.updateBidsCache(auction.auctionId, adUnitCode, bidderCode, {
'status': BIDDER_STATUS.TIMEOUT,
'isTimeout': true
});
} else {
cacheManager.updateBidsCache(auction.auctionId, adUnitCode, bidderCode, {
'status': BIDDER_STATUS.NO_BID,
'isTimeout': false
});
}
}
},
handlePrebidWonMessage(prebidWonBids) {
Expand Down
46 changes: 45 additions & 1 deletion test/spec/modules/appierAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,51 @@ describe('Appier Prebid AnalyticsAdapter', function () {
'/12345678/adunit_2': {
'appier': {
'status': 'noBid',
'isTimeout': false,
}
}
}
});
});

it('should build message correctly for delayed bid responses', function () {
appierAnalyticsAdapter.enableAnalytics({
provider: 'appierAnalytics',
options: {
affiliateId: affiliateId,
configId: configId,
sampling: 1,
adSampling: 1
}
});

events.emit(constants.EVENTS.AUCTION_INIT, MOCK_EVENT.AUCTION_INIT);
events.emit(constants.EVENTS.BID_REQUESTED, MOCK_EVENT.BID_REQUESTED);
events.emit(constants.EVENTS.BID_TIMEOUT, MOCK_EVENT.BID_TIMEOUT);
events.emit(constants.EVENTS.BID_RESPONSE, MOCK_EVENT.BID_RESPONSE_REGULAR[1]);
appierAnalyticsAdapter.handleAuctionEndMessage(MOCK_EVENT.AUCTION_END_NOBID, []);

cache = appierAnalyticsAdapter.getCache();

expect(cache[auctionId].bids).to.deep.equal({
'adUnits': {
'/12345678/adunit_1': {
'appier': {
'status': 'requested',
'isTimeout': true
}
},
'/12345678/adunit_2': {
'appier': {
'status': 'timeout',
'isTimeout': true,
'time': 600,
'cpm': 0.43125,
'currency': 'USD',
'cpmUsd': 0.43125,
'originalCpm': 13.15313,
'originalCurrency': 'TWD',
'prebidWon': false,
}
}
}
Expand Down Expand Up @@ -474,7 +518,7 @@ describe('Appier Prebid AnalyticsAdapter', function () {
'/12345678/adunit_2': {
'appier': {
'status': 'noBid',
'isTimeout': true,
'isTimeout': false,
}
}
}
Expand Down

0 comments on commit ebed9df

Please sign in to comment.