Skip to content

Commit

Permalink
PubMatic Analytics Adapter: added support for Bidder alias (prebid#7153)
Browse files Browse the repository at this point in the history
* Changed net revenue to True

* Added support for bidderAlias

* Removed the code converting bidder to lowercase

Co-authored-by: Azhar <azhar@L1119.local>
  • Loading branch information
2 people authored and agrandes-tappx committed Sep 29, 2021
1 parent 4d3458f commit 7acf606
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 3 deletions.
13 changes: 10 additions & 3 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function setMediaTypes(types, bid) {

function copyRequiredBidDetails(bid) {
return utils.pick(bid, [
'bidder', bidder => bidder.toLowerCase(),
'bidder',
'bidId',
'status', () => NO_BID, // default a bid to NO_BID until response is recieved or bid is timed out
'finalSource as source',
Expand Down Expand Up @@ -196,12 +196,17 @@ function getValueForKgpv(bid, adUnitId) {
}
}

function getAdapterNameForAlias(aliasName) {
return adapterManager.aliasRegistry[aliasName] || aliasName;
}

function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null;
return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) {
let bid = adUnit.bids[bidId];
partnerBids.push({
'pn': bid.bidder,
'pn': getAdapterNameForAlias(bid.bidder),
'bc': bid.bidder,
'bidid': bid.bidId,
'db': bid.bidResponse ? 0 : 1,
'kgpv': getValueForKgpv(bid, adUnitId),
Expand Down Expand Up @@ -287,6 +292,7 @@ function executeBidsLoggerCall(e, highestCpmBids) {
function executeBidWonLoggerCall(auctionId, adUnitId) {
const winningBidId = cache.auctions[auctionId].adUnitCodes[adUnitId].bidWon;
const winningBid = cache.auctions[auctionId].adUnitCodes[adUnitId].bids[winningBidId];
const adapterName = getAdapterNameForAlias(winningBid.bidder);
let pixelURL = END_POINT_WIN_BID_LOGGER;
pixelURL += 'pubid=' + publisherId;
pixelURL += '&purl=' + enc(config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '');
Expand All @@ -296,7 +302,8 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&pid=' + enc(profileId);
pixelURL += '&pdvid=' + enc(profileVersionId);
pixelURL += '&slot=' + enc(adUnitId);
pixelURL += '&pn=' + enc(winningBid.bidder);
pixelURL += '&pn=' + enc(adapterName);
pixelURL += '&bc=' + enc(winningBid.bidder);
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
pixelURL += '&eg=' + enc(winningBid.bidResponse.bidGrossCpmUSD);
pixelURL += '&kgpv=' + enc(getValueForKgpv(winningBid, adUnitId));
Expand Down
127 changes: 127 additions & 0 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pubmaticAnalyticsAdapter from 'modules/pubmaticAnalyticsAdapter.js';
import adapterManager from 'src/adapterManager.js';
import CONSTANTS from 'src/constants.json';
import { config } from 'src/config.js';
import {
Expand Down Expand Up @@ -342,6 +343,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps).to.be.an('array');
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');
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].db).to.equal(0);
Expand All @@ -366,6 +368,7 @@ describe('pubmatic analytics adapter', function () {
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);
Expand Down Expand Up @@ -401,6 +404,7 @@ describe('pubmatic analytics adapter', function () {
expect(decodeURIComponent(data.slot)).to.equal('/19968336/header-bid-tag-0');
expect(decodeURIComponent(data.kgpv)).to.equal('/19968336/header-bid-tag-0');
expect(data.pn).to.equal('pubmatic');
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');
Expand Down Expand Up @@ -441,6 +445,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps).to.be.an('array');
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');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].eg).to.equal(1.23);
Expand Down Expand Up @@ -508,6 +513,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps).to.be.an('array');
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');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].eg).to.equal(1);
Expand Down Expand Up @@ -551,6 +557,7 @@ describe('pubmatic analytics adapter', function () {
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].db).to.equal(1);
expect(data.s[1].ps[0].kgpv).to.equal('this-is-a-kgpv');
Expand Down Expand Up @@ -587,6 +594,7 @@ describe('pubmatic analytics adapter', function () {
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].db).to.equal(1);
expect(data.s[1].ps[0].kgpv).to.equal('this-is-a-kgpv');
Expand Down Expand Up @@ -629,6 +637,7 @@ describe('pubmatic analytics adapter', function () {
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[1].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('this-is-a-kgpv');
Expand Down Expand Up @@ -685,6 +694,7 @@ describe('pubmatic analytics adapter', function () {
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[1].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('this-is-a-kgpv');
Expand Down Expand Up @@ -730,6 +740,7 @@ describe('pubmatic analytics adapter', function () {
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[1].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('*');
Expand Down Expand Up @@ -783,6 +794,7 @@ describe('pubmatic analytics adapter', function () {
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[1].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('*');
Expand Down Expand Up @@ -833,6 +845,7 @@ describe('pubmatic analytics adapter', function () {
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[1].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('*');
Expand Down Expand Up @@ -885,6 +898,7 @@ describe('pubmatic analytics adapter', function () {
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[1].ps[0].bc).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('*');
Expand All @@ -910,5 +924,118 @@ describe('pubmatic analytics adapter', function () {
firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]);
expect(data.kgpv).to.equal('*');
});

it('Logger: best case + win tracker in case of Bidder Aliases', function() {
MOCK.BID_REQUESTED['bids'][0]['bidder'] = 'pubmatic_alias';
adapterManager.aliasRegistry['pubmatic_alias'] = 'pubmatic';

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.pubid).to.equal('9999');
expect(data.pid).to.equal('1111');
expect(data.pdvid).to.equal('20');
expect(data.iid).to.equal('25c6d7f5-699a-4bfc-87c9-996f915341fa');
expect(data.to).to.equal('3000');
expect(data.purl).to.equal('http://www.test.com/page.html');
expect(data.orig).to.equal('www.test.com');
expect(data.tst).to.equal(1519767016);
expect(data.tgid).to.equal(15);
expect(data.s).to.be.an('array');
expect(data.s.length).to.equal(2);

// slot 1
expect(data.s[0].sn).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].ps).to.be.an('array');
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');
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].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');
expect(data.s[0].ps[0].psz).to.equal('640x480');
expect(data.s[0].ps[0].eg).to.equal(1.23);
expect(data.s[0].ps[0].en).to.equal(1.23);
expect(data.s[0].ps[0].di).to.equal('');
expect(data.s[0].ps[0].dc).to.equal('');
expect(data.s[0].ps[0].l1).to.equal(3214);
expect(data.s[0].ps[0].l2).to.equal(0);
expect(data.s[0].ps[0].ss).to.equal(0);
expect(data.s[0].ps[0].t).to.equal(0);
expect(data.s[0].ps[0].wb).to.equal(1);
expect(data.s[0].ps[0].af).to.equal('video');
expect(data.s[0].ps[0].ocpm).to.equal(1.23);
expect(data.s[0].ps[0].ocry).to.equal('USD');

// slot 2
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
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[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].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(1.52);
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].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');

// 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.pubid).to.equal('9999');
expect(decodeURIComponent(data.purl)).to.equal('http://www.test.com/page.html');
expect(data.tst).to.equal('1519767014');
expect(data.iid).to.equal('25c6d7f5-699a-4bfc-87c9-996f915341fa');
expect(data.bidid).to.equal('2ecff0db240757');
expect(data.pid).to.equal('1111');
expect(data.pdvid).to.equal('20');
expect(decodeURIComponent(data.slot)).to.equal('/19968336/header-bid-tag-0');
expect(decodeURIComponent(data.kgpv)).to.equal('/19968336/header-bid-tag-0');
expect(data.pn).to.equal('pubmatic');
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');
});
});
});

0 comments on commit 7acf606

Please sign in to comment.