Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22 in AOLP_ADS_JS/prebid.js from bug/analytics-ti…
Browse files Browse the repository at this point in the history
…med-out-bids to master

* commit 'aa8aa97beffce40e82a2ec26949744018af4d1a0':
  Prebid 1.0.7
  Fixed AOL analytics adapter to report timed out bids
  • Loading branch information
marian-r committed Sep 6, 2016
2 parents 5d0c788 + aa8aa97 commit f4b0170
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
AOL Prebid 1.0.7
----------------
BUGFIX: AOL analytics adapter reports timed out bids.


AOL Prebid 1.0.6
----------------
BUGFIX: Ensure that auctionId never exceeds max 64 bit value. Limit length to 18 digits.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aol-container-tag",
"version": "1.0.6",
"version": "1.0.7",
"description": "AOL Header Bidding Container Tag Library",
"main": "src/prebid.js",
"scripts": {
Expand Down
75 changes: 49 additions & 26 deletions src/adapters/analytics/aol.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,30 @@ export default utils.extend(adapter({
track({ eventType, args }) {
switch (eventType) {
case AUCTION_COMPLETED:
let bidsReceived = args.bidsReceived;
let adUnitsConf = args.adUnits;

for (let bid of bidsReceived) {
let bidsReceived = args.bidsReceived;
let bidsReceivedIds = bidsReceived.map(receivedBid => receivedBid.adId);
let timedOutBids = args.bidsRequested
.map(bidderRequest => bidderRequest.bids
.filter(bid => bidsReceivedIds.indexOf(bid.bidId) < 0)
.map(bid => {
return {
adUnitCode: bid.placementCode,
bidder: bid.bidder,
cpm: 0,
getStatusCode: () => 3, // ERROR_TIMEOUT
timeToRespond: (new Date().getTime() - bidderRequest.start)
};
})
)
.reduce((a, b) => a.concat(b), []);

for (let bid of bidsReceived.concat(timedOutBids)) {
const currentAdUnitCode = bid.adUnitCode;
let adUnit = adUnits[currentAdUnitCode];
if (!adUnit) {
adUnit = {
code: currentAdUnitCode,
bids: [],
winner: {
cpm: 0
},
};

const filteredBids = bidsReceived.filter(
bid => bid.bidderCode === AOL_BIDDER_CODE && bid.adUnitCode === currentAdUnitCode
);
const pubapiId = (filteredBids.length === 1) ? filteredBids[0].pubapiId : '';

for (let adUnitConf of adUnitsConf) {
if (adUnitConf.code === currentAdUnitCode) {
for (let adUnitBid of adUnitConf.bids) {
if (adUnitBid.bidder === AOL_BIDDER_CODE) {
adUnit.aolParams = adUnitBid.params;
adUnit.aolParams.pubapiId = pubapiId;
}
}
}
}
adUnit = initAdUnit(currentAdUnitCode);
adUnit = addAolParams(adUnit, adUnitsConf, bidsReceived);
adUnits[currentAdUnitCode] = adUnit;
}
adUnit.winner = (adUnit.winner.cpm < bid.cpm) ? bid : adUnit.winner;
Expand Down Expand Up @@ -277,3 +271,32 @@ function getStatusCode(bid) {
return -1; // INVALID
}
}

function initAdUnit(adUnitCode) {
return {
code: adUnitCode,
bids: [],
winner: {
cpm: 0
}
};
}

function addAolParams(adUnit, adUnitsConf, bidsReceived) {
const filteredBids = bidsReceived.filter(
bid => bid.bidderCode === AOL_BIDDER_CODE && bid.adUnitCode === adUnit.code
);
const pubapiId = (filteredBids.length === 1) ? filteredBids[0].pubapiId : '';

for (let adUnitConf of adUnitsConf) {
if (adUnitConf.code === adUnit.code) {
for (let adUnitBid of adUnitConf.bids) {
if (adUnitBid.bidder === AOL_BIDDER_CODE) {
adUnit.aolParams = adUnitBid.params;
adUnit.aolParams.pubapiId = pubapiId;
}
}
}
}
return adUnit;
}
1 change: 1 addition & 0 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ exports.executeCallback = function () {
events.emit(CONSTANTS.EVENTS.AUCTION_COMPLETED,
{
bidsReceived: $$PREBID_GLOBAL$$._bidsReceived,
bidsRequested: $$PREBID_GLOBAL$$._bidsRequested,
adUnits: $$PREBID_GLOBAL$$.adUnits
});
processCallbacks([externalOneTimeCallback]);
Expand Down

0 comments on commit f4b0170

Please sign in to comment.