-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Magnite Analytics Adapter : add seat non bid handling #9696
Changes from 6 commits
ccab78d
481847d
a667e40
d4a2145
c90c7d1
d5e116f
3894aa2
0d0f275
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ const { | |
BIDDER_DONE, | ||
BID_TIMEOUT, | ||
BID_WON, | ||
BILLABLE_EVENT | ||
BILLABLE_EVENT, | ||
SEAT_NON_BID | ||
}, | ||
STATUS: { | ||
GOOD, | ||
|
@@ -464,7 +465,7 @@ const findMatchingAdUnitFromAuctions = (matchesFunction, returnFirstMatch) => { | |
} | ||
} | ||
return matches; | ||
} | ||
}; | ||
|
||
const getRenderingIds = bidWonData => { | ||
// if bid caching off -> return the bidWon auction id | ||
|
@@ -821,7 +822,16 @@ magniteAdapter.track = ({ eventType, args }) => { | |
auctionEntry.floors.dealsEnforced = args.floorData.enforcements.floorDeals; | ||
} | ||
|
||
// Log error if no matching bid! | ||
// no-bid from server. report it! | ||
if (!bid && args.seatBidId) { | ||
bid = adUnit.bids[args.seatBidId] = { | ||
bidder: args.bidderCode, | ||
source: 'server', | ||
bidId: args.seatBidId, | ||
unknownBid: true | ||
}; | ||
} | ||
|
||
if (!bid) { | ||
logError(`${MODULE_NAME}: Could not find associated bid request for bid response with requestId: `, args.requestId); | ||
break; | ||
|
@@ -852,6 +862,9 @@ magniteAdapter.track = ({ eventType, args }) => { | |
bid.pbsBidId = pbsBidId; | ||
} | ||
break; | ||
case SEAT_NON_BID: | ||
handleNonBidEvent(args); | ||
break; | ||
case BIDDER_DONE: | ||
const serverError = deepAccess(args, 'serverErrors.0'); | ||
const serverResponseTimeMs = args.serverResponseTimeMs; | ||
|
@@ -939,6 +952,61 @@ magniteAdapter.track = ({ eventType, args }) => { | |
} | ||
}; | ||
|
||
const handleNonBidEvent = function(args) { | ||
const {seatnonbid, auctionId} = args; | ||
const auction = deepAccess(cache, `auctions.${auctionId}.auction`); | ||
const adUnits = auction.adUnits; | ||
seatnonbid.forEach(seatnonbid => { | ||
let {seat} = seatnonbid; | ||
seatnonbid.nonbid.forEach(nonbid => { | ||
try { | ||
const {status, impid} = nonbid; | ||
const matchingTid = Object.keys(adUnits).find(tid => adUnits[tid].adUnitCode === impid); | ||
const adUnit = adUnits[matchingTid]; | ||
const statusInfo = statusMap[status] || { status: 'no-bid' }; | ||
adUnit.bids[generateUUID()] = { | ||
source: 'server', | ||
bidder: seat, | ||
isSeatNonBid: true, | ||
clientLatencyMillis: Date.now() - cache.auctions[args.auctionId].auction.auctionStart, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified to clientLatencyMillis: Date.now() - auction.auctionStart, since auction is saved above |
||
...statusInfo | ||
}; | ||
} catch (error) { | ||
logWarn(`Unable to match nonbid to adUnit`); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
const statusMap = { | ||
0: { | ||
status: 'no-bid' | ||
}, | ||
100: { | ||
status: 'error', | ||
error: { | ||
code: 'request-error', | ||
description: 'general error' | ||
} | ||
}, | ||
101: { | ||
status: 'error', | ||
error: { | ||
code: 'timeout-error', | ||
description: 'prebid server timeout' | ||
} | ||
}, | ||
200: { | ||
status: 'rejected' | ||
}, | ||
202: { | ||
status: 'rejected' | ||
}, | ||
301: { | ||
status: 'rejected-ipf' | ||
} | ||
}; | ||
|
||
adapterManager.registerAnalyticsAdapter({ | ||
adapter: magniteAdapter, | ||
code: 'magnite', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,8 @@ const { | |
BIDDER_DONE, | ||
BID_WON, | ||
BID_TIMEOUT, | ||
BILLABLE_EVENT | ||
BILLABLE_EVENT, | ||
SEAT_NON_BID | ||
} | ||
} = CONSTANTS; | ||
|
||
|
@@ -160,6 +161,16 @@ const MOCK = { | |
'status': 'rendered', | ||
getStatusCode: () => 1, | ||
}, | ||
SEAT_NON_BID: { | ||
auctionId: '99785e47-a7c8-4c8a-ae05-ef1c717a4b4d', | ||
seatnonbid: [{ | ||
seat: 'rubicon', | ||
nonbid: [{ | ||
status: 1, | ||
impid: 'box' | ||
}] | ||
}] | ||
}, | ||
AUCTION_END: { | ||
'auctionId': '99785e47-a7c8-4c8a-ae05-ef1c717a4b4d', | ||
'auctionEnd': 1658868384019, | ||
|
@@ -2039,4 +2050,121 @@ describe('magnite analytics adapter', function () { | |
} | ||
}) | ||
}); | ||
|
||
describe('BID_RESPONSE events', () => { | ||
beforeEach(() => { | ||
magniteAdapter.enableAnalytics({ | ||
options: { | ||
endpoint: '//localhost:9999/event', | ||
accountId: 1001 | ||
} | ||
}); | ||
config.setConfig({ rubicon: { updatePageView: true } }); | ||
}); | ||
|
||
it('should add a no-bid bid to the add unit if it recieves one from the server', () => { | ||
const bidResponse = utils.deepClone(MOCK.BID_RESPONSE); | ||
const auctionInit = utils.deepClone(MOCK.AUCTION_INIT); | ||
|
||
bidResponse.requestId = 'fakeId'; | ||
bidResponse.seatBidId = 'fakeId'; | ||
|
||
bidResponse.requestId = 'fakeId'; | ||
events.emit(AUCTION_INIT, auctionInit); | ||
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); | ||
events.emit(BID_RESPONSE, bidResponse) | ||
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); | ||
events.emit(AUCTION_END, MOCK.AUCTION_END); | ||
clock.tick(rubiConf.analyticsBatchTimeout + 1000); | ||
|
||
let message = JSON.parse(server.requests[0].requestBody); | ||
expect(utils.generateUUID.called).to.equal(true); | ||
|
||
expect(message.auctions[0].adUnits[0].bids[1]).to.deep.equal( | ||
{ | ||
bidder: 'rubicon', | ||
source: 'server', | ||
status: 'success', | ||
bidResponse: { | ||
'bidPriceUSD': 3.4, | ||
'dimensions': { | ||
'height': 250, | ||
'width': 300 | ||
}, | ||
'mediaType': 'banner' | ||
}, | ||
oldBidId: 'fakeId', | ||
unknownBid: true, | ||
bidId: 'fakeId', | ||
clientLatencyMillis: 271 | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe('SEAT_NON_BID events', () => { | ||
let seatnonbid; | ||
|
||
const runNonBidAuction = () => { | ||
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); | ||
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); | ||
events.emit(SEAT_NON_BID, seatnonbid) | ||
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); | ||
events.emit(AUCTION_END, MOCK.AUCTION_END); | ||
clock.tick(rubiConf.analyticsBatchTimeout + 1000); | ||
}; | ||
const checkStatusAgainstCode = (status, code, error, index) => { | ||
seatnonbid.seatnonbid[0].nonbid[0].status = code; | ||
runNonBidAuction(); | ||
let message = JSON.parse(server.requests[index].requestBody); | ||
let bid = message.auctions[0].adUnits[0].bids[1]; | ||
|
||
if (error) { | ||
expect(bid.error).to.deep.equal(error); | ||
} else { | ||
expect(bid.error).to.equal(undefined); | ||
} | ||
expect(bid.source).to.equal('server'); | ||
expect(bid.status).to.equal(status); | ||
expect(bid.isSeatNonBid).to.equal(true); | ||
}; | ||
beforeEach(() => { | ||
magniteAdapter.enableAnalytics({ | ||
options: { | ||
endpoint: '//localhost:9999/event', | ||
accountId: 1001 | ||
} | ||
}); | ||
seatnonbid = utils.deepClone(MOCK.SEAT_NON_BID); | ||
}); | ||
|
||
it('adds seatnonbid info to bids array', () => { | ||
runNonBidAuction(); | ||
let message = JSON.parse(server.requests[0].requestBody); | ||
|
||
expect(message.auctions[0].adUnits[0].bids[1]).to.deep.equal( | ||
{ | ||
bidder: 'rubicon', | ||
source: 'server', | ||
status: 'no-bid', | ||
isSeatNonBid: true, | ||
clientLatencyMillis: -139101369960 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this one tests if the status is not in the status map, and then below test is all of the other ones cool. |
||
); | ||
}); | ||
|
||
it('adjusts the status according to the status map', () => { | ||
const statuses = [ | ||
{code: 0, status: 'no-bid'}, | ||
{code: 100, status: 'error', error: {code: 'request-error', description: 'general error'}}, | ||
{code: 101, status: 'error', error: {code: 'timeout-error', description: 'prebid server timeout'}}, | ||
{code: 200, status: 'rejected'}, | ||
{code: 202, status: 'rejected'}, | ||
{code: 301, status: 'rejected-ipf'} | ||
]; | ||
statuses.forEach((info, index) => { | ||
checkStatusAgainstCode(info.status, info.code, info.error, index); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice! |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WE should probably safe check in case the auction was not found for some reason: