Skip to content

Commit

Permalink
improves additional data passed to the handler in AuctionInit and Auc…
Browse files Browse the repository at this point in the history
…tionEnd events (prebid#3168)
  • Loading branch information
Marco Masotti authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent b0e3595 commit 4faa3ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
30 changes: 22 additions & 8 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
let _bidderRequests = [];
let _bidsReceived = [];
let _auctionStart;
let _auctionEnd;
let _auctionId = utils.generateUUID();
let _auctionStatus;
let _callback = callback;
Expand All @@ -106,6 +107,22 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
function addBidRequests(bidderRequests) { _bidderRequests = _bidderRequests.concat(bidderRequests) };
function addBidReceived(bidsReceived) { _bidsReceived = _bidsReceived.concat(bidsReceived); }

function getProperties() {
return {
auctionId: _auctionId,
auctionStart: _auctionStart,
auctionEnd: _auctionEnd,
auctionStatus: _auctionStatus,
adUnits: _adUnits,
adUnitCodes: _adUnitCodes,
labels: _labels,
bidderRequests: _bidderRequests,
bidsReceived: _bidsReceived,
winningBids: _winningBids,
timeout: _timeout
};
}

function startAuctionTimer() {
const timedOut = true;
const timeoutCallback = executeCallback.bind(null, timedOut);
Expand All @@ -129,10 +146,12 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
}
}

events.emit(CONSTANTS.EVENTS.AUCTION_END, {auctionId: _auctionId});

try {
_auctionStatus = AUCTION_COMPLETED;
_auctionEnd = Date.now();

events.emit(CONSTANTS.EVENTS.AUCTION_END, getProperties());

const adUnitCodes = _adUnitCodes;
const bids = _bidsReceived
.filter(adUnitsFilter.bind(this, adUnitCodes))
Expand Down Expand Up @@ -185,12 +204,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})

_auctionStatus = AUCTION_IN_PROGRESS;

const auctionInit = {
timestamp: _auctionStart,
auctionId: _auctionId,
timeout: _timeout
};
events.emit(CONSTANTS.EVENTS.AUCTION_INIT, auctionInit);
events.emit(CONSTANTS.EVENTS.AUCTION_INIT, getProperties());

let callbacks = auctionCallbacks(auctionDone, this);
let boundObj = {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1591,8 +1591,8 @@ describe('Unit: Prebid Module', function () {
describe('emit', function () {
it('should be able to emit event without arguments', function () {
var spyEventsEmit = sinon.spy(events, 'emit');
events.emit(CONSTANTS.EVENTS.AUCTION_END);
assert.ok(spyEventsEmit.calledWith('auctionEnd'));
events.emit(CONSTANTS.EVENTS.REQUEST_BIDS);
assert.ok(spyEventsEmit.calledWith('requestBids'));
events.emit.restore();
});
});
Expand Down

0 comments on commit 4faa3ec

Please sign in to comment.