Skip to content

Commit

Permalink
PubMatic bidAdapter and analyticsAdapter (#5495)
Browse files Browse the repository at this point in the history
* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* passing piId in bid object

* piId will be logged in PubMatic analytics too

* if testGroupId is set in pbjs config then that value will be passed in PM analytics call

* bid.piId ==> bid.partnerImpId

* chnaged key names, added a Todo

* capping testGroupId in 0-15; defaults to 0

* testGroupId should be INT
  • Loading branch information
pm-harshad-mane authored Jul 16, 2020
1 parent dbfa543 commit 1049d07
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
12 changes: 11 additions & 1 deletion modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function parseBidResponse(bid) {
'mediaType',
'params',
'mi',
'partnerImpId', // partner impression ID
'dimensions', () => utils.pick(bid, [
'width',
'height'
Expand Down Expand Up @@ -188,7 +189,8 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'mi': bid.bidResponse ? (bid.bidResponse.mi || undefined) : undefined,
'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
'ocry': bid.bidResponse ? (bid.bidResponse.originalCurrency || CURRENCY_USD) : CURRENCY_USD,
'piid': bid.bidResponse ? (bid.bidResponse.partnerImpId || EMPTY_STRING) : EMPTY_STRING
});
return partnerBids;
}, [])
Expand Down Expand Up @@ -218,6 +220,13 @@ function executeBidsLoggerCall(e, highestCpmBids) {
outputObj['tst'] = Math.round((new window.Date()).getTime() / 1000);
outputObj['pid'] = '' + profileId;
outputObj['pdvid'] = '' + profileVersionId;
outputObj['tgid'] = (function() {
var testGroupId = parseInt(config.getConfig('testGroupId') || 0);
if (testGroupId <= 15 && testGroupId >= 0) {
return testGroupId;
}
return 0;
})();

// GDPR support
if (auctionCache.gdprConsent) {
Expand Down Expand Up @@ -267,6 +276,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
pixelURL += '&eg=' + enc(winningBid.bidResponse.bidGrossCpmUSD);
pixelURL += '&kgpv=' + enc(winningBid.params.kgpv || adUnitId);
pixelURL += '&piid=' + enc(winningBid.bidResponse.partnerImpId || EMPTY_STRING);
ajax(
pixelURL,
null,
Expand Down
3 changes: 2 additions & 1 deletion modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@ export const spec = {
referrer: parsedReferrer,
ad: bid.adm,
pm_seat: seatbidder.seat || null,
pm_dspid: bid.ext && bid.ext.dspid ? bid.ext.dspid : null
pm_dspid: bid.ext && bid.ext.dspid ? bid.ext.dspid : null,
partnerImpId: bid.id || '' // partner impression Id
};
if (parsedRequest.imp && parsedRequest.imp.length > 0) {
parsedRequest.imp.forEach(req => {
Expand Down
21 changes: 21 additions & 0 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const BID = {
'mediaType': 'video',
'statusMessage': 'Bid available',
'bidId': '2ecff0db240757',
'partnerImpId': 'partnerImpressionID-1',
'adId': 'fake_ad_id',
'source': 's2s',
'requestId': '2ecff0db240757',
Expand Down Expand Up @@ -69,6 +70,7 @@ const BID = {
const BID2 = Object.assign({}, BID, {
adUnitCode: '/19968336/header-bid-tag-1',
bidId: '3bd4ebb1c900e2',
partnerImpId: 'partnerImpressionID-2',
adId: 'fake_ad_id_2',
requestId: '3bd4ebb1c900e2',
width: 728,
Expand Down Expand Up @@ -297,6 +299,10 @@ describe('pubmatic analytics adapter', function () {
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]);
Expand All @@ -322,6 +328,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.tst).to.equal(1519767016);
expect(data.cns).to.equal('here-goes-gdpr-consent-string');
expect(data.gdpr).to.equal(1);
expect(data.tgid).to.equal(15);
expect(data.s).to.be.an('array');
expect(data.s.length).to.equal(2);
// slot 1
Expand All @@ -331,6 +338,7 @@ describe('pubmatic analytics adapter', function () {
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].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');
Expand All @@ -354,6 +362,7 @@ describe('pubmatic analytics adapter', function () {
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].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');
Expand Down Expand Up @@ -389,6 +398,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.pn).to.equal('pubmatic');
expect(data.eg).to.equal('1.23');
expect(data.en).to.equal('1.23');
expect(data.piid).to.equal('partnerImpressionID-1');
});

it('bidCpmAdjustment: USD: Logger: best case + win tracker', function() {
Expand Down Expand Up @@ -419,6 +429,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.pid).to.equal('1111');
expect(data.s).to.be.an('array');
expect(data.s.length).to.equal(2);
expect(data.tgid).to.equal(0);
// slot 1
expect(data.s[0].sn).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].sz).to.deep.equal(['640x480']);
Expand Down Expand Up @@ -446,6 +457,10 @@ describe('pubmatic analytics adapter', function () {
});

it('bidCpmAdjustment: JPY: Logger: best case + win tracker', function() {
config.setConfig({
testGroupId: 25
});

setConfig({
adServerCurrency: 'JPY',
rates: {
Expand Down Expand Up @@ -479,6 +494,7 @@ describe('pubmatic analytics adapter', function () {
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.pubid).to.equal('9999');
expect(data.pid).to.equal('1111');
expect(data.tgid).to.equal(0);// test group id should be between 0-15 else set to 0
expect(data.s).to.be.an('array');
expect(data.s.length).to.equal(2);
// slot 1
Expand Down Expand Up @@ -508,6 +524,10 @@ describe('pubmatic analytics adapter', function () {
});

it('Logger: when bid is not submitted, default bid status 1 check: pubmatic set as s2s', function() {
config.setConfig({
testGroupId: '25'
});

events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
Expand All @@ -520,6 +540,7 @@ describe('pubmatic analytics adapter', function () {
expect(requests.length).to.equal(2); // 1 logger and 1 win-tracker
let request = requests[1]; // logger is executed late, trackers execute first
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.tgid).to.equal(0);// test group id should be an INT between 0-15 else set to 0
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');
Expand Down
2 changes: 2 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,7 @@ describe('PubMatic adapter', function () {
expect(response[0].ad).to.equal(bidResponses.body.seatbid[0].bid[0].adm);
expect(response[0].pm_seat).to.equal(bidResponses.body.seatbid[0].seat);
expect(response[0].pm_dspid).to.equal(bidResponses.body.seatbid[0].bid[0].ext.dspid);
expect(response[0].partnerImpId).to.equal(bidResponses.body.seatbid[0].bid[0].id);

expect(response[1].requestId).to.equal(bidResponses.body.seatbid[1].bid[0].impid);
expect(response[1].cpm).to.equal((bidResponses.body.seatbid[1].bid[0].price).toFixed(2));
Expand All @@ -2328,6 +2329,7 @@ describe('PubMatic adapter', function () {
expect(response[1].ad).to.equal(bidResponses.body.seatbid[1].bid[0].adm);
expect(response[1].pm_seat).to.equal(bidResponses.body.seatbid[1].seat || null);
expect(response[1].pm_dspid).to.equal(bidResponses.body.seatbid[1].bid[0].ext.dspid);
expect(response[0].partnerImpId).to.equal(bidResponses.body.seatbid[0].bid[0].id);
});

it('should check for dealChannel value selection', function () {
Expand Down

0 comments on commit 1049d07

Please sign in to comment.