Skip to content
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

Pubxai Analytics Adapter: add additional event listener to collect bidRejected data #12063

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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