Skip to content

Commit

Permalink
Merge pull request #24 from Pubx-ai/bug/PUB-2794
Browse files Browse the repository at this point in the history
send BidRejected Events to capture floored bids
  • Loading branch information
pnhegde authored Jul 31, 2024
2 parents 0c6b844 + 5bfc260 commit 9fef481
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions modules/pubxaiAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,19 @@ const track = ({ eventType, args }) => {
// handle invalid bids, and remove them from the adUnit cache
case EVENTS.BID_TIMEOUT:
args.map(extractBid).forEach((bid) => {
bid.renderStatus = 3;
bid.bidType = 3;
auctionCache[bid.auctionId].bids.push(bid);
});
break;
// handle valid bid responses and record them as part of an auction
case EVENTS.BID_RESPONSE:
const bid = Object.assign(extractBid(args), { renderStatus: 2 });
const bid = Object.assign(extractBid(args), { bidType: 2 });
auctionCache[bid.auctionId].bids.push(bid);
break;
case EVENTS.BID_REJECTED:
const rejectedBid = Object.assign(extractBid(args), { bidType: 1 });
auctionCache[rejectedBid.auctionId].bids.push(rejectedBid);
break;
// capture extra information from the auction, and if there were no bids
// (and so no chance of a win) send the auction
case EVENTS.AUCTION_END:
Expand All @@ -183,7 +187,7 @@ const track = ({ eventType, args }) => {
timestamp: args.timestamp,
});
if (
auctionCache[args.auctionId].bids.every((bid) => bid.renderStatus === 3)
auctionCache[args.auctionId].bids.every((bid) => bid.bidType === 3)
) {
prepareSend(args.auctionId);
}
Expand All @@ -201,7 +205,7 @@ const track = ({ eventType, args }) => {
isFloorSkipped: floorDetail?.skipped || false,
isWinningBid: true,
renderedSize: args.size,
renderStatus: 4,
bidType: 4,
});
winningBid.adServerData = getAdServerDataForBid(winningBid);
auctionCache[winningBid.auctionId].winningBid = winningBid;
Expand Down Expand Up @@ -283,6 +287,7 @@ const prepareSend = (auctionId) => {
auctionTimestamp: auctionData.auctionDetail.timestamp,
pubxaiAnalyticsVersion: pubxaiAnalyticsVersion,
prebidVersion: '$prebid.version$',
pubxId: initOptions.pubxId,
},
});
sendCache[pubxaiAnalyticsRequestUrl].push(data);
Expand Down
13 changes: 9 additions & 4 deletions test/spec/modules/pubxaiAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ describe('pubxai analytics adapter', () => {
});

describe('track', () => {
const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625';
let initOptions = {
samplingRate: '1',
pubxId: '6c415fc0-8b0e-4cf5-be73-01526a4db625',
pubxId: pubxId,
};

let originalVS;
Expand Down Expand Up @@ -148,7 +149,7 @@ describe('pubxai analytics adapter', () => {
timeout: 1000,
config: {
samplingRate: '1',
pubxId: '6c415fc0-8b0e-4cf5-be73-01526a4db625',
pubxId: pubxId,
},
},
bidRequested: {
Expand Down Expand Up @@ -529,7 +530,7 @@ describe('pubxai analytics adapter', () => {
null,
auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4',
sizes: '300x250',
renderStatus: 2,
bidType: 2,
requestTimestamp: 1616654312804,
creativeId: 96846035,
currency: 'USD',
Expand Down Expand Up @@ -651,7 +652,7 @@ describe('pubxai analytics adapter', () => {
placementId: 13144370,
renderedSize: '300x250',
sizes: '300x250',
renderStatus: 4,
bidType: 4,
responseTimestamp: 1616654313071,
requestTimestamp: 1616654312804,
status: 'rendered',
Expand Down Expand Up @@ -764,6 +765,7 @@ describe('pubxai analytics adapter', () => {
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down Expand Up @@ -807,6 +809,7 @@ describe('pubxai analytics adapter', () => {
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});

// Step 9: check that the data sent in the request is correct
Expand Down Expand Up @@ -932,6 +935,7 @@ describe('pubxai analytics adapter', () => {
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down Expand Up @@ -1048,6 +1052,7 @@ describe('pubxai analytics adapter', () => {
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down

0 comments on commit 9fef481

Please sign in to comment.