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

Count bids with function on adapter if present #773

Closed
wants to merge 4 commits into from
Closed
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
1 change: 0 additions & 1 deletion src/adapters/indexExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
};

function _countBids(bid) {
const bidCount = bid.sizes
return bid && bid.sizes && bid.sizes.length || null;
}

Expand Down
18 changes: 7 additions & 11 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { uniques, flatten } from './utils';
import { uniques, flatten, add } from './utils';
import {getPriceBucketString} from './cpmBucketManager';

var CONSTANTS = require('./constants.json');
var utils = require('./utils.js');
var events = require('./events');
var adaptermanager = require('./adaptermanager');

var objectType_function = 'function';

Expand Down Expand Up @@ -41,10 +40,6 @@ function getBidders(bid) {
return bid.bidder;
}

function add(a, b) {
return a + b;
}

/**
* Bidders handle multiple requests and multiple sizes in different ways.
* A Bidder Adapter can export a `countBids` function if this is anything
Copy link
Member

Choose a reason for hiding this comment

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

should we call this "countExpectedBids" ?

Expand All @@ -53,9 +48,9 @@ function add(a, b) {
* @param bid
* @returns {*|number}
*/
function getExpectedBidCount(bid) {
const bidder = bid.bidder;
const countBids = adaptermanager.bidderRegistry[bidder].countBids || function() { return 1; };
function countExpectedBids(bid) {
const adapter = $$PREBID_GLOBAL$$.getBidderRegistry()[bid.bidder];
const countBids = adapter && adapter.countBids || function() { return 1; };
return countBids(bid);
}

Expand All @@ -64,7 +59,8 @@ function bidsBackAdUnit(adUnitCode) {
.map(request => request.bids
.filter(bid => bid.placementCode === adUnitCode))
.reduce(flatten)
.map(getExpectedBidCount).reduce(add, 0);
.map(countExpectedBids)
.reduce(add, 0);

const received = $$PREBID_GLOBAL$$._bidsReceived.filter(bid => bid.adUnitCode === adUnitCode).length;
return requested === received;
Expand All @@ -74,7 +70,7 @@ function bidsBackAll() {
const requested = $$PREBID_GLOBAL$$._bidsRequested
.map(request => request.bids)
.reduce(flatten)
.map(getExpectedBidCount)
.map(countExpectedBids)
.reduce(add, 0);

const received = $$PREBID_GLOBAL$$._bidsReceived.length;
Expand Down
8 changes: 8 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,12 @@ $$PREBID_GLOBAL$$.getHighestCpmBids = function (adUnitCode) {
return getWinningBids(adUnitCode);
};

/**
* Returns the adaptermanager.bidderRegistry
* @returns {*}
*/
$$PREBID_GLOBAL$$.getBidderRegistry = function() {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this added to the global? We shouldn't need to expose this. If we need a means to store objects let's put it into a separate file that does not have global access.

return adaptermanager.bidderRegistry;
};

processQue();
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,7 @@ export function shuffle(array) {

return array;
}

export function add(a, b) {
return a + b;
}