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

improves additional data passed to the handler in AuctionInit and AuctionEnd events #3168

Merged
merged 1 commit into from
Oct 16, 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
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