Skip to content

Commit

Permalink
PubMatic Analytics Adapter:added parameters in logger call (#9328)
Browse files Browse the repository at this point in the history
* Logging floor related params in loger

* Adding au and mt parameters in logger and tracker call

* Added extra check

Co-authored-by: pm-azhar-mulla <azhar@L1119.local>
Co-authored-by: pm-priyanka-deshmane <priyanka.deshmane@pubmatic.com>
  • Loading branch information
3 people authored Dec 12, 2022
1 parent bf5b15f commit 374aa26
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
43 changes: 41 additions & 2 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const DEFAULT_PUBLISHER_ID = 0;
const DEFAULT_PROFILE_ID = 0;
const DEFAULT_PROFILE_VERSION_ID = 0;
const enc = window.encodeURIComponent;
const MEDIATYPE = {
BANNER: 0,
VIDEO: 1,
NATIVE: 2
}

/// /////////// VARIABLES //////////////
let publisherId = DEFAULT_PUBLISHER_ID; // int: mandatory
Expand Down Expand Up @@ -89,6 +94,7 @@ function copyRequiredBidDetails(bid) {
'status', () => NO_BID, // default a bid to NO_BID until response is recieved or bid is timed out
'finalSource as source',
'params',
'floorData',
'adUnit', () => pick(bid, [
'adUnitCode',
'transactionId',
Expand Down Expand Up @@ -153,6 +159,7 @@ function parseBidResponse(bid) {
'bidId',
'mediaType',
'params',
'floorData',
'mi',
'regexPattern', () => bid.regexPattern || undefined,
'partnerImpId', // partner impression ID
Expand Down Expand Up @@ -243,17 +250,28 @@ 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
'piid': bid.bidResponse ? (bid.bidResponse.partnerImpId || EMPTY_STRING) : EMPTY_STRING,
'frv': (s2sBidders.indexOf(bid.bidder) > -1) ? undefined : (bid.bidResponse ? (bid.bidResponse.floorData ? bid.bidResponse.floorData.floorRuleValue : undefined) : undefined)
});
});
return partnerBids;
}, [])
}

function getAdUnitAdFormats(adUnit) {
var af = adUnit ? Object.keys(adUnit.mediaTypes || {}).map(format => MEDIATYPE[format.toUpperCase()]) : [];
return af;
}

function getAdUnit(adUnits, adUnitId) {
return adUnits.filter(adUnit => (adUnit.divID && adUnit.divID == adUnitId) || (adUnit.code == adUnitId))[0];
}

function executeBidsLoggerCall(e, highestCpmBids) {
let auctionId = e.auctionId;
let referrer = config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '';
let auctionCache = cache.auctions[auctionId];
let floorData = auctionCache.floorData;
let outputObj = { s: [] };
let pixelURL = END_POINT_BID_LOGGER;

Expand Down Expand Up @@ -283,12 +301,21 @@ function executeBidsLoggerCall(e, highestCpmBids) {
return 0;
})();

if (floorData) {
outputObj['fmv'] = floorData.floorRequestData ? floorData.floorRequestData.modelVersion || undefined : undefined;
outputObj['ft'] = floorData.floorResponseData ? (floorData.floorResponseData.enforcements.enforceJS == false ? 0 : 1) : undefined;
}

outputObj.s = Object.keys(auctionCache.adUnitCodes).reduce(function(slotsArray, adUnitId) {
let adUnit = auctionCache.adUnitCodes[adUnitId];
let origAdUnit = getAdUnit(auctionCache.origAdUnits, adUnitId) || {};
let slotObject = {
'sn': adUnitId,
'au': origAdUnit.adUnitId || adUnitId,
'mt': getAdUnitAdFormats(origAdUnit),
'sz': adUnit.dimensions.map(e => e[0] + 'x' + e[1]),
'ps': gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestCpmBids.filter(bid => bid.adUnitCode === adUnitId))
'ps': gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestCpmBids.filter(bid => bid.adUnitCode === adUnitId)),
'fskp': floorData ? (floorData.floorRequestData ? (floorData.floorRequestData.skipped == false ? 0 : 1) : undefined) : undefined,
};
slotsArray.push(slotObject);
return slotsArray;
Expand Down Expand Up @@ -318,6 +345,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
}

const adapterName = getAdapterNameForAlias(winningBid.adapterCode || winningBid.bidder);
let origAdUnit = getAdUnit(cache.auctions[auctionId].origAdUnits, adUnitId) || {};
let pixelURL = END_POINT_WIN_BID_LOGGER;
pixelURL += 'pubid=' + publisherId;
pixelURL += '&purl=' + enc(config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '');
Expand All @@ -327,6 +355,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&pid=' + enc(profileId);
pixelURL += '&pdvid=' + enc(profileVersionId);
pixelURL += '&slot=' + enc(adUnitId);
pixelURL += '&au=' + enc(origAdUnit.adUnitId || adUnitId);
pixelURL += '&pn=' + enc(adapterName);
pixelURL += '&bc=' + enc(winningBid.bidderCode || winningBid.bidder);
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
Expand Down Expand Up @@ -358,6 +387,8 @@ function auctionInitHandler(args) {
'bidderDonePendingCount', () => args.bidderRequests.length,
]);
cacheEntry.adUnitCodes = {};
cacheEntry.floorData = {};
cacheEntry.origAdUnits = args.adUnits;
cacheEntry.referer = args.bidderRequests[0].refererInfo.topmostLocation;
cache.auctions[args.auctionId] = cacheEntry;
}
Expand All @@ -372,6 +403,9 @@ function bidRequestedHandler(args) {
};
}
cache.auctions[args.auctionId].adUnitCodes[bid.adUnitCode].bids[bid.bidId] = [copyRequiredBidDetails(bid)];
if (bid.floorData) {
cache.auctions[args.auctionId].floorData['floorRequestData'] = bid.floorData;
}
})
}

Expand All @@ -386,6 +420,11 @@ function bidResponseHandler(args) {
bid = copyRequiredBidDetails(args);
cache.auctions[args.auctionId].adUnitCodes[args.adUnitCode].bids[args.requestId].push(bid);
}

if (args.floorData) {
cache.auctions[args.auctionId].floorData['floorResponseData'] = args.floorData;
}

bid.adId = args.adId;
bid.source = formatSource(bid.source || args.source);
setBidStatus(bid, args);
Expand Down
52 changes: 51 additions & 1 deletion test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ const BID = {
'hb_size': '640x480',
'hb_source': 'server'
},
'floorData': {
'cpmAfterAdjustments': 6.3,
'enforcements': {'enforceJS': true, 'enforcePBS': false, 'floorDeals': false, 'bidAdjustment': true},
'floorCurrency': 'USD',
'floorRule': 'banner',
'floorRuleValue': 1.1,
'floorValue': 1.1
},
getStatusCode() {
return 1;
}
Expand Down Expand Up @@ -200,7 +208,18 @@ const MOCK = {
'bidId': '3bd4ebb1c900e2',
'seatBidId': 'aaaa-bbbb-cccc-dddd',
'bidderRequestId': '1be65d7958826a',
'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa'
'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa',
'floorData': {
'fetchStatus': 'success',
'floorMin': undefined,
'floorProvider': 'pubmatic',
'location': 'fetch',
'modelTimestamp': undefined,
'modelVersion': 'floorModelTest',
'modelWeight': undefined,
'skipRate': 0,
'skipped': false
}
}
],
'auctionStart': 1519149536560,
Expand Down Expand Up @@ -343,10 +362,13 @@ describe('pubmatic analytics adapter', function () {
expect(data.orig).to.equal('www.test.com');
expect(data.tst).to.equal(1519767016);
expect(data.tgid).to.equal(15);
expect(data.fmv).to.equal('floorModelTest');
expect(data.ft).to.equal(1);
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].fskp).to.equal(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);
Expand All @@ -370,8 +392,10 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[0].ps[0].frv).to.equal(undefined);
// slot 2
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
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);
Expand All @@ -397,6 +421,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[1].ps[0].frv).to.equal(undefined);

// tracker slot1
let firstTracker = requests[0].url;
Expand Down Expand Up @@ -446,11 +471,14 @@ describe('pubmatic analytics adapter', function () {
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.pubid).to.equal('9999');
expect(data.pid).to.equal('1111');
expect(data.fmv).to.equal('floorModelTest');
expect(data.ft).to.equal(1);
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].fskp).to.equal(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);
Expand All @@ -464,6 +492,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[1].ps[0].frv).to.equal(undefined);
// tracker slot1
let firstTracker = requests[0].url;
expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt');
Expand Down Expand Up @@ -515,6 +544,8 @@ describe('pubmatic analytics adapter', function () {
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.fmv).to.equal('floorModelTest');
expect(data.ft).to.equal(1);
expect(data.s).to.be.an('array');
expect(data.s.length).to.equal(2);
// slot 1
Expand Down Expand Up @@ -563,6 +594,7 @@ describe('pubmatic analytics adapter', function () {
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].fskp).to.equal(0);
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);
Expand All @@ -586,6 +618,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[1].ps[0].af).to.equal(undefined);
expect(data.s[1].ps[0].ocpm).to.equal(0);
expect(data.s[1].ps[0].ocry).to.equal('USD');
expect(data.s[1].ps[0].frv).to.equal(undefined);
});

it('Logger: post-timeout check without bid response', function() {
Expand Down Expand Up @@ -643,6 +676,7 @@ describe('pubmatic analytics adapter', function () {
let request = requests[0];
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
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);
Expand All @@ -667,6 +701,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[1].ps[0].frv).to.equal(undefined);
});

it('Logger: currency conversion check', function() {
Expand Down Expand Up @@ -748,6 +783,7 @@ describe('pubmatic analytics adapter', function () {
expect(request.url).to.equal('https://t.pubmatic.com/wl?pubid=9999');
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
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);
Expand All @@ -772,6 +808,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[1].ps[0].frv).to.equal(undefined);
expect(data.dvc).to.deep.equal({'plt': 2});
// respective tracker slot
let firstTracker = requests[1].url;
Expand Down Expand Up @@ -829,6 +866,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[1].ps[0].ocpm).to.equal(1.52);
expect(data.s[1].ps[0].ocry).to.equal('USD');
expect(data.dvc).to.deep.equal({'plt': 1});
expect(data.s[1].ps[0].frv).to.equal(undefined);
// respective tracker slot
let firstTracker = requests[1].url;
expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt');
Expand Down Expand Up @@ -856,6 +894,7 @@ describe('pubmatic analytics adapter', function () {
expect(request.url).to.equal('https://t.pubmatic.com/wl?pubid=9999');
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
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);
Expand All @@ -880,6 +919,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[1].ps[0].frv).to.equal(undefined);
// respective tracker slot
let firstTracker = requests[1].url;
expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt');
Expand Down Expand Up @@ -979,11 +1019,14 @@ describe('pubmatic analytics adapter', function () {
expect(data.orig).to.equal('www.test.com');
expect(data.tst).to.equal(1519767016);
expect(data.tgid).to.equal(15);
expect(data.fmv).to.equal('floorModelTest');
expect(data.ft).to.equal(1);
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].fskp).to.equal(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);
Expand All @@ -1007,9 +1050,11 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[0].ps[0].frv).to.equal(1.1);

// slot 2
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
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);
Expand All @@ -1035,6 +1080,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[1].ps[0].frv).to.equal(undefined);

// tracker slot1
let firstTracker = requests[0].url;
Expand Down Expand Up @@ -1091,11 +1137,14 @@ describe('pubmatic analytics adapter', function () {
expect(data.orig).to.equal('www.test.com');
expect(data.tst).to.equal(1519767016);
expect(data.tgid).to.equal(15);
expect(data.fmv).to.equal('floorModelTest');
expect(data.ft).to.equal(1);
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].fskp).to.equal(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);
Expand All @@ -1119,6 +1168,7 @@ describe('pubmatic analytics adapter', function () {
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');
expect(data.s[0].ps[0].frv).to.equal(1.1);

// slot 2
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
Expand Down

0 comments on commit 374aa26

Please sign in to comment.