Skip to content

Commit

Permalink
OpenX Analytics Adapter: Adding bid timeout tracking logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Tu committed Mar 25, 2020
1 parent fed3a1e commit 2cc5688
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions modules/openxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function filterBidsByAdUnit(bids) {

function isValidEvent(eventType, adUnitCode) {
if (checkAdUnitConfig()) {
let validationEvents = [bidAdjustmentConst, bidResponseConst, bidWonConst];
let validationEvents = [bidAdjustmentConst, bidResponseConst, bidWonConst, bidTimeoutConst];
if (
!includes(initOptions.adUnits, adUnitCode) &&
includes(validationEvents, eventType)
Expand Down Expand Up @@ -246,19 +246,18 @@ let openxAdapter = Object.assign(adapter({ urlParam, analyticsType }), {
info.ad = '';
}

let auctionId = info.auctionId;
// utils.logInfo('OX: Got auctionId', auctionId);
// on bid timeout events, the info is an array of bids
let auctionId = eventType === CONSTANTS.EVENTS.BID_TIMEOUT
? info[0].auctionId
: info.auctionId;

if (eventType === auctionInitConst) {
eventStack[auctionId] = { options: {}, events: [] };
// utils.logInfo('OX: Event Stack updated after AuctionInit', eventStack);
}
else if (eventType === bidWonConst) { // && auctionStatus[auctionId] !== 'started'
} else if (eventType === bidWonConst) {
pushEvent(eventType, info, auctionId);
// utils.logInfo('OX: Bid won called for', auctionId);
return;
}
else if (eventType === auctionEndConst) {
} else if (eventType === auctionEndConst) {
pushEvent(eventType, removeads(info), auctionId);
// utils.logInfo('OX: Auction end called for', auctionId);
updateSessionId();
Expand All @@ -280,8 +279,7 @@ let openxAdapter = Object.assign(adapter({ urlParam, analyticsType }), {
// utils.logInfo('OX: Deleted Auction Info for auctionId', auctionId);
}, AUCTION_END_WAIT_TIME);
}
}
else if (eventType === bidTimeoutConst) {
} else if (eventType === bidTimeoutConst) {
// utils.logInfo('SA: Bid Timedout for', auctionId);
pushEvent(eventType, info, auctionId);
}
Expand Down Expand Up @@ -486,13 +484,11 @@ function send(eventType, eventStack, auctionId) {
utils.logError('OX: Invalid data format');
delete eventStack[auctionId];
// utils.logInfo('OX: Deleted Auction Info for auctionId', auctionId);
return;
}
} else {
utils.logError('OX: Invalid data format');
delete eventStack[auctionId];
// utils.logInfo('OX: Deleted Auction Info for auctionId', auctionId);
return;
}
}
function pushEvent(eventType, args, auctionId) {
Expand All @@ -505,7 +501,13 @@ function pushEvent(eventType, args, auctionId) {
}
} else {
if (isValidEvent(eventType, args.adUnitCode)) {
eventStack[auctionId].events.push({ eventType: eventType, args: args });
if (eventType === CONSTANTS.EVENTS.BID_TIMEOUT) {
// convert object to array
let timedOutBids = utils._map(args, timedOutBid => timedOutBid);
eventStack[auctionId].events.push({ eventType: eventType, args: timedOutBids });
} else {
eventStack[auctionId].events.push({ eventType: eventType, args: args });
}
}
}
}
Expand Down

0 comments on commit 2cc5688

Please sign in to comment.