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

Fixing the BidAdjustmentEvent fire time #1399

Merged
merged 4 commits into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 6 additions & 5 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ exports.addBidResponse = function (adUnitCode, bid) {
// Postprocess the bids so that all the universal properties exist, no matter which bidder they came from.
// This should be called before addBidToAuction().
function prepareBidForAuction() {
// Let listeners know that now is the time to adjust the bid, if they want to.
//
// This must be fired first, so that we calculate derived values from the updates
events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, bid);

const bidRequest = getBidderRequest(bid.bidderCode, adUnitCode);

Object.assign(bid, {
Expand All @@ -148,6 +143,12 @@ exports.addBidResponse = function (adUnitCode, bid) {

bid.timeToRespond = bid.responseTimestamp - bid.requestTimestamp;

// Let listeners know that now is the time to adjust the bid, if they want to.
//
// CAREFUL: Publishers rely on certain bid properties to be available (like cpm),
// but others to not be set yet (like priceStrings). See #1372 and #1389.
events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, bid);

// a publisher-defined renderer can be used to render bids
const adUnitRenderer =
bidRequest.bids && bidRequest.bids[0] && bidRequest.bids[0].renderer;
Expand Down
30 changes: 30 additions & 0 deletions test/spec/unit/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ describe('The Bid Manager', () => {
*/
function prepAuction(adUnits, bidRequestTweaker) {
function bidAdjuster(bid) {
if (bid.hasOwnProperty('cpm')) {
bid.hadCpmDuringBidAdjustment = true;
}
if (bid.hasOwnProperty('adUnitCode')) {
bid.hadAdUnitCodeDuringBidAdjustment = true;
}
if (bid.hasOwnProperty('timeToRespond')) {
bid.hadTimeToRespondDuringBidAdjustment = true;
}
if (bid.hasOwnProperty('requestTimestamp')) {
bid.hadRequestTimestampDuringBidAdjustment = true;
}
if (bid.hasOwnProperty('responseTimestamp')) {
bid.hadResponseTimestampDuringBidAdjustment = true;
}
bid.cpm = adjustCpm(bid.cpm);
}
beforeEach(() => {
Expand Down Expand Up @@ -142,6 +157,21 @@ describe('The Bid Manager', () => {
bidManager.addBidResponse('mock/code');
expect($$PREBID_GLOBAL$$._bidsReceived.length).to.equal(0);
});

it('should attach properties for analytics *before* the BID_ADJUSTMENT event listeners are called', () => {
console.log('testing this bug');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this console.log slipped through 🐍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh... thanks

const copy = Object.assign({}, bidResponse);
copy.getSize = function() {
return `${this.height}x${this.width}`;
};
delete copy.cpm;
bidManager.addBidResponse('mock/code', copy);
expect(copy).to.have.property('hadCpmDuringBidAdjustment', true);
expect(copy).to.have.property('hadAdUnitCodeDuringBidAdjustment', true);
expect(copy).to.have.property('hadTimeToRespondDuringBidAdjustment', true);
expect(copy).to.have.property('hadRequestTimestampDuringBidAdjustment', true);
expect(copy).to.have.property('hadResponseTimestampDuringBidAdjustment', true);
});
});

describe('when the auction has timed out', () => {
Expand Down