Skip to content

Commit

Permalink
PubMatic Analytics Adapter: Handled bid rejection in case of "Floor n…
Browse files Browse the repository at this point in the history
…ot met" (prebid#10374)

* Handling bids rejected due to floors

* Updated test case after new changes to s2s floors

---------

Co-authored-by: pm-azhar-mulla <azhar@L1119.local>
  • Loading branch information
pm-azhar-mulla and pm-azhar-mulla authored Aug 24, 2023
1 parent 487c0ed commit ef8188e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
13 changes: 13 additions & 0 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,16 @@ function bidResponseHandler(args) {
bid.bidResponse = parseBidResponse(args);
}

function bidRejectedHandler(args) {
// If bid is rejected due to floors value did not met
// make cpm as 0, status as bidRejected and forward the bid for logging
if (args.rejectionReason === CONSTANTS.REJECTION_REASON.FLOOR_NOT_MET) {
args.cpm = 0;
args.status = CONSTANTS.BID_STATUS.BID_REJECTED;
bidResponseHandler(args);
}
}

function bidderDoneHandler(args) {
cache.auctions[args.auctionId].bidderDonePendingCount--;
args.bids.forEach(bid => {
Expand Down Expand Up @@ -607,6 +617,9 @@ let pubmaticAdapter = Object.assign({}, baseAdapter, {
case CONSTANTS.EVENTS.BID_RESPONSE:
bidResponseHandler(args);
break;
case CONSTANTS.EVENTS.BID_REJECTED:
bidRejectedHandler(args)
break;
case CONSTANTS.EVENTS.BIDDER_DONE:
bidderDoneHandler(args);
break;
Expand Down
65 changes: 63 additions & 2 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
AUCTION_END,
BID_REQUESTED,
BID_RESPONSE,
BID_REJECTED,
BIDDER_DONE,
BID_WON,
BID_TIMEOUT,
Expand Down Expand Up @@ -107,6 +108,9 @@ const BID2 = Object.assign({}, BID, {
}
});

const BID3 = Object.assign({}, BID2, {
rejectionReason: CONSTANTS.REJECTION_REASON.FLOOR_NOT_MET
})
const MOCK = {
SET_TARGETING: {
[BID.adUnitCode]: BID.adserverTargeting,
Expand Down Expand Up @@ -236,6 +240,9 @@ const MOCK = {
BID,
BID2
],
REJECTED_BID: [
BID3
],
AUCTION_END: {
'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa'
},
Expand Down Expand Up @@ -1076,6 +1083,60 @@ describe('pubmatic analytics adapter', function () {
expect(data.kgpv).to.equal('*');
});

it('Logger: to handle floor rejected bids', function() {
this.timeout(5000)

sandbox.stub($$PREBID_GLOBAL$$, 'getHighestCpmBids').callsFake((key) => {
return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]]
});

events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
events.emit(BID_REJECTED, MOCK.REJECTED_BID[0]);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);
events.emit(BID_WON, MOCK.BID_WON[0]);

clock.tick(2000 + 1000);
expect(requests.length).to.equal(2); // 1 logger and 1 win-tracker
let request = requests[1]; // logger is executed late, trackers execute first
expect(request.url).to.equal('https://t.pubmatic.com/wl?pubid=9999');
let data = getLoggerJsonFromRequest(request.requestBody);

// slot 2
// Testing only for rejected bid as other scenarios will be covered under other TCs
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
expect(data.s[1].sz).to.deep.equal(['1000x300', '970x250', '728x90']);
expect(data.s[1].ps).to.be.an('array');
expect(data.s[1].ps.length).to.equal(1);
expect(data.s[1].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].piid).to.equal('partnerImpressionID-2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('this-is-a-kgpv');
expect(data.s[1].ps[0].kgpsv).to.equal('this-is-a-kgpv');
expect(data.s[1].ps[0].psz).to.equal('728x90');
expect(data.s[1].ps[0].eg).to.equal(1.52);
expect(data.s[1].ps[0].en).to.equal(0); // Net CPM is market as 0 due to bid rejection
expect(data.s[1].ps[0].di).to.equal('the-deal-id');
expect(data.s[1].ps[0].dc).to.equal('PMP');
expect(data.s[1].ps[0].mi).to.equal('matched-impression');
expect(data.s[1].ps[0].adv).to.equal('example.com');
expect(data.s[1].ps[0].l1).to.equal(3214);
expect(data.s[1].ps[0].l2).to.equal(0);
expect(data.s[1].ps[0].ss).to.equal(1);
expect(data.s[1].ps[0].t).to.equal(0);
expect(data.s[1].ps[0].wb).to.equal(1);
expect(data.s[1].ps[0].af).to.equal('banner');
expect(data.s[1].ps[0].ocpm).to.equal(1.52);
expect(data.s[1].ps[0].ocry).to.equal('USD');
expect(data.s[1].ps[0].frv).to.equal(1.1);
});

it('Logger: best case + win tracker in case of Bidder Aliases', function() {
MOCK.BID_REQUESTED['bids'][0]['bidder'] = 'pubmatic_alias';
MOCK.BID_REQUESTED['bids'][0]['bidderCode'] = 'pubmatic_alias';
Expand Down Expand Up @@ -1123,7 +1184,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].fskp).to.equal(0);
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps.length).to.equal(1);
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bc).to.equal('pubmatic_alias');
Expand Down Expand Up @@ -1242,7 +1303,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].fskp).to.equal(0);
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps.length).to.equal(1);
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bc).to.equal('groupm');
Expand Down

0 comments on commit ef8188e

Please sign in to comment.