Skip to content

Commit

Permalink
PubMaticAnalyticAdapter : Added new fields related to floors (fetch s…
Browse files Browse the repository at this point in the history
…tatus, source of floor, provider and unique id) in analytics call (#10768)

* Added floors field to logger call

* Added sid in logger records
  • Loading branch information
kapil-tuptewar authored Dec 11, 2023
1 parent 3ec81e6 commit 6275c00
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
30 changes: 23 additions & 7 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {_each, isArray, isStr, logError, logWarn, pick} from '../src/utils.js';
import {_each, isArray, isStr, logError, logWarn, pick, generateUUID} from '../src/utils.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
Expand Down Expand Up @@ -286,7 +286,7 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'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 ? bid.bidResponse.floorData.floorRuleValue : undefined) : undefined),
'frv': bid.bidResponse ? bid.bidResponse.floorData?.floorRuleValue : undefined,
'md': bid.bidResponse ? getMetadata(bid.bidResponse.meta) : undefined
});
});
Expand Down Expand Up @@ -337,11 +337,10 @@ 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 floorData = auctionCache?.floorData;
let floorFetchStatus = getFloorFetchStatus(auctionCache?.floorData);
let outputObj = { s: [] };
let pixelURL = END_POINT_BID_LOGGER;
// will return true if floor data is present.
let fetchStatus = getFloorFetchStatus(auctionCache.floorData);

if (!auctionCache) {
return;
Expand All @@ -364,7 +363,7 @@ function executeBidsLoggerCall(e, highestCpmBids) {
outputObj['tgid'] = getTgId();
outputObj['pbv'] = getGlobal()?.version || '-1';

if (floorData && fetchStatus) {
if (floorData && floorFetchStatus) {
outputObj['fmv'] = floorData.floorRequestData ? floorData.floorRequestData.modelVersion || undefined : undefined;
outputObj['ft'] = floorData.floorResponseData ? (floorData.floorResponseData.enforcements.enforceJS == false ? 0 : 1) : undefined;
}
Expand All @@ -379,8 +378,25 @@ function executeBidsLoggerCall(e, highestCpmBids) {
'mt': getAdUnitAdFormats(origAdUnit),
'sz': getSizesForAdUnit(adUnit, adUnitId),
'ps': gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestCpmBids.filter(bid => bid.adUnitCode === adUnitId)),
'fskp': (floorData && fetchStatus) ? (floorData.floorRequestData ? (floorData.floorRequestData.skipped == false ? 0 : 1) : undefined) : undefined,
'fskp': floorData && floorFetchStatus ? (floorData.floorRequestData ? (floorData.floorRequestData.skipped == false ? 0 : 1) : undefined) : undefined,
'sid': generateUUID()
};
if (floorData?.floorRequestData) {
const { location, fetchStatus, floorProvider } = floorData?.floorRequestData;
slotObject.ffs = {
[CONSTANTS.FLOOR_VALUES.SUCCESS]: 1,
[CONSTANTS.FLOOR_VALUES.ERROR]: 2,
[CONSTANTS.FLOOR_VALUES.TIMEOUT]: 4,
undefined: 0
}[fetchStatus];
slotObject.fsrc = {
[CONSTANTS.FLOOR_VALUES.FETCH]: 2,
[CONSTANTS.FLOOR_VALUES.NO_DATA]: 2,
[CONSTANTS.FLOOR_VALUES.AD_UNIT]: 1,
[CONSTANTS.FLOOR_VALUES.SET_CONFIG]: 1
}[location];
slotObject.fp = floorProvider;
}
slotsArray.push(slotObject);
return slotsArray;
}, []);
Expand Down
4 changes: 3 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
"AD_UNIT": "adUnit",
"SET_CONFIG": "setConfig",
"FETCH": "fetch",
"SUCCESS": "success"
"SUCCESS": "success",
"ERROR": "error",
"TIMEOUT": "timeout"
}
}
51 changes: 51 additions & 0 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ describe('pubmatic analytics adapter', function () {
// 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].sid).not.to.be.undefined;
expect(data.s[0].ffs).to.equal(1);
expect(data.s[0].fsrc).to.equal(2);
expect(data.s[0].fp).to.equal('pubmatic');
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -403,6 +407,10 @@ describe('pubmatic analytics adapter', function () {
// 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].sid).not.to.be.undefined;
expect(data.s[1].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');
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 Down Expand Up @@ -583,6 +591,10 @@ describe('pubmatic analytics adapter', function () {
// 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].sid).not.to.be.undefined;
expect(data.s[0].ffs).to.equal(1);
expect(data.s[0].fsrc).to.equal(2);
expect(data.s[0].fp).to.equal('pubmatic');
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -702,6 +714,13 @@ describe('pubmatic analytics adapter', function () {
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].sid).not.to.be.undefined;

expect(data.s[1].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');

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 Down Expand Up @@ -784,6 +803,10 @@ describe('pubmatic analytics adapter', function () {
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].sid).not.to.be.undefined;
expect(data.s[1].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');
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 Down Expand Up @@ -846,6 +869,7 @@ describe('pubmatic analytics adapter', function () {
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].sid).not.to.be.undefined;
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');
Expand Down Expand Up @@ -893,6 +917,10 @@ describe('pubmatic analytics adapter', function () {
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].sid).not.to.be.undefined;
expect(data.s[1].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');
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 Down Expand Up @@ -952,6 +980,7 @@ describe('pubmatic analytics adapter', function () {
let data = getLoggerJsonFromRequest(request.requestBody);
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].sid).not.to.be.undefined;
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');
Expand Down Expand Up @@ -1006,6 +1035,10 @@ describe('pubmatic analytics adapter', function () {
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].sid).not.to.be.undefined;
expect(data.s[1].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');
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 Down Expand Up @@ -1063,6 +1096,7 @@ describe('pubmatic analytics adapter', function () {
let data = getLoggerJsonFromRequest(request.requestBody);
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].sid).not.to.be.undefined;
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');
Expand Down Expand Up @@ -1121,7 +1155,11 @@ describe('pubmatic analytics adapter', function () {
// Testing only for rejected bid as other scenarios will be covered under other TCs
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].fskp).to.equal(0);
expect(data.s[1].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');
expect(data.s[1].sz).to.deep.equal(['1000x300', '970x250', '728x90']);
expect(data.s[1].sid).not.to.be.undefined;
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');
Expand Down Expand Up @@ -1196,7 +1234,11 @@ describe('pubmatic analytics adapter', function () {
// 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].ffs).to.equal(1);
expect(data.s[0].fsrc).to.equal(2);
expect(data.s[0].fp).to.equal('pubmatic');
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].sid).not.to.be.undefined;
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps.length).to.equal(1);
Expand Down Expand Up @@ -1226,7 +1268,11 @@ describe('pubmatic analytics adapter', function () {
// 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].ffs).to.equal(1);
expect(data.s[1].fsrc).to.equal(2);
expect(data.s[1].fp).to.equal('pubmatic');
expect(data.s[1].sz).to.deep.equal(['1000x300', '970x250', '728x90']);
expect(data.s[1].sid).not.to.be.undefined;
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');
Expand Down Expand Up @@ -1318,7 +1364,11 @@ describe('pubmatic analytics adapter', function () {
// 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].ffs).to.equal(1);
expect(data.s[0].fsrc).to.equal(2);
expect(data.s[0].fp).to.equal('pubmatic');
expect(data.s[0].sz).to.deep.equal(['640x480']);
expect(data.s[0].sid).not.to.be.undefined;
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].au).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps.length).to.equal(1);
Expand Down Expand Up @@ -1348,6 +1398,7 @@ describe('pubmatic analytics adapter', function () {
// 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].sid).not.to.be.undefined;
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');
Expand Down

0 comments on commit 6275c00

Please sign in to comment.