Skip to content

Commit

Permalink
Using origbidid instead of piid (prebid#11415)
Browse files Browse the repository at this point in the history
Co-authored-by: pm-azhar-mulla <[email protected]>
  • Loading branch information
pm-azhar-mulla and pm-azhar-mulla authored Apr 29, 2024
1 parent 428ae3b commit ee509d3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
4 changes: 2 additions & 2 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'pn': adapterName,
'bc': bid.bidderCode || bid.bidder,
'bidid': bid.bidId || bidId,
'origbidid': bid?.bidResponse?.partnerImpId || bid?.bidResponse?.prebidBidId || bid.bidId || bidId,
'db': bid.bidResponse ? 0 : 1,
'kgpv': getValueForKgpv(bid, adUnitId),
'kgpsv': bid.params && bid.params.kgpv ? bid.params.kgpv : adUnitId,
Expand All @@ -313,7 +314,6 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'af': bid.bidResponse ? (bid.bidResponse.mediaType || undefined) : undefined,
'ocpm': bid.bidResponse ? (bid.bidResponse.originalCpm || 0) : 0,
'ocry': bid.bidResponse ? (bid.bidResponse.originalCurrency || CURRENCY_USD) : CURRENCY_USD,
'piid': bid.bidResponse ? (bid.bidResponse.partnerImpId || EMPTY_STRING) : EMPTY_STRING,
'frv': bid.bidResponse ? bid.bidResponse.floorData?.floorRuleValue : undefined,
'md': bid.bidResponse ? getMetadata(bid.bidResponse.meta) : undefined,
'pb': pg || undefined
Expand Down Expand Up @@ -487,7 +487,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
pixelURL += '&eg=' + enc(winningBid.bidResponse.bidGrossCpmUSD);
pixelURL += '&kgpv=' + enc(getValueForKgpv(winningBid, adUnitId));
pixelURL += '&piid=' + enc(winningBid.bidResponse.partnerImpId || EMPTY_STRING);
pixelURL += '&origbidid=' + enc(winningBid?.bidResponse?.partnerImpId || winningBid?.bidResponse?.prebidBidId || winningBid.bidId);
pixelURL += '&di=' + enc(winningBid?.bidResponse?.dealId || OPEN_AUCTION_DEAL_ID);
pixelURL += '&pb=' + enc(pg);

Expand Down
66 changes: 56 additions & 10 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bc).to.equal('pubmatic');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].piid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].origbidid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].db).to.equal(0);
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].kgpsv).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -618,7 +618,7 @@ describe('pubmatic analytics adapter', function () {
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].origbidid).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');
Expand Down Expand Up @@ -659,7 +659,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.bc).to.equal('pubmatic');
expect(data.eg).to.equal('1.23');
expect(data.en).to.equal('1.23');
expect(data.piid).to.equal('partnerImpressionID-1');
expect(data.origbidid).to.equal('partnerImpressionID-1');
expect(data.plt).to.equal('1');
expect(data.psz).to.equal('640x480');
expect(data.tgid).to.equal('15');
Expand Down Expand Up @@ -1372,7 +1372,7 @@ describe('pubmatic analytics adapter', function () {
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].origbidid).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');
Expand Down Expand Up @@ -1453,7 +1453,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bc).to.equal('pubmatic_alias');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].piid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].origbidid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].db).to.equal(0);
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].kgpsv).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -1487,7 +1487,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[1].ps[0].pn).to.equal('pubmatic');
expect(data.s[1].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].origbidid).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');
Expand Down Expand Up @@ -1528,7 +1528,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.bc).to.equal('pubmatic_alias');
expect(data.eg).to.equal('1.23');
expect(data.en).to.equal('1.23');
expect(data.piid).to.equal('partnerImpressionID-1');
expect(data.origbidid).to.equal('partnerImpressionID-1');
});

it('Logger: best case + win tracker in case of GroupM as alternate bidder', function() {
Expand Down Expand Up @@ -1585,7 +1585,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bc).to.equal('groupm');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].piid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].origbidid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].db).to.equal(0);
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].kgpsv).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -1615,7 +1615,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[1].ps[0].pn).to.equal('pubmatic');
expect(data.s[1].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].origbidid).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');
Expand Down Expand Up @@ -1654,7 +1654,53 @@ describe('pubmatic analytics adapter', function () {
expect(data.bc).to.equal('groupm');
expect(data.eg).to.equal('1.23');
expect(data.en).to.equal('1.23');
expect(data.piid).to.equal('partnerImpressionID-1');
expect(data.origbidid).to.equal('partnerImpressionID-1');
});

it('Logger: best case + win tracker. Log bidId when partnerimpressionid is missing', function() {
delete MOCK.BID_RESPONSE[1]['partnerImpId'];
MOCK.BID_RESPONSE[1]['prebidBidId'] = 'Prebid-bid-id-1';
sandbox.stub($$PREBID_GLOBAL$$, 'getHighestCpmBids').callsFake((key) => {
return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]]
});

config.setConfig({
testGroupId: 15
});

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_RESPONSE, MOCK.BID_RESPONSE[1]);
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]);
events.emit(BID_WON, MOCK.BID_WON[1]);

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

// slot 1
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].origbidid).to.equal('partnerImpressionID-1');

// slot 2
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].origbidid).to.equal('3bd4ebb1c900e2');

// tracker slot1
let firstTracker = requests[0].url;
expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt');
data = {};
firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]);
expect(data.bidid).to.equal('2ecff0db240757');
expect(data.origbidid).to.equal('partnerImpressionID-1');
});
});

Expand Down

0 comments on commit ee509d3

Please sign in to comment.