Skip to content

Commit

Permalink
PubMatic Analytics Adapter : sending 'ffs' floors param in tracker an…
Browse files Browse the repository at this point in the history
…d optional chaining in logger and tracker (#12739)

* Added 'ffs' to tracker call

* Added optional chaining to logger and tracker

* Added fix for ds

* added safe check for floor root values
  • Loading branch information
pm-asit-sahoo authored Feb 19, 2025
1 parent 01a73c1 commit ed011ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
46 changes: 22 additions & 24 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,15 @@ function getFloorFetchStatus(floorData) {

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

if (!auctionCache) {
return;
}

if (auctionCache.sent) {
if (!auctionCache || auctionCache.sent) {
return;
}

Expand Down Expand Up @@ -479,35 +475,35 @@ function executeBidsLoggerCall(e, highestCpmBids) {
}

function executeBidWonLoggerCall(auctionId, adUnitId) {
const winningBidId = cache.auctions[auctionId].adUnitCodes[adUnitId].bidWon;
const winningBids = cache.auctions[auctionId].adUnitCodes[adUnitId].bids[winningBidId];
const winningBidId = cache.auctions[auctionId]?.adUnitCodes[adUnitId]?.bidWon;
const winningBids = cache.auctions[auctionId]?.adUnitCodes[adUnitId]?.bids[winningBidId];
if (!winningBids) {
logWarn(LOG_PRE_FIX + 'Could not find winningBids for : ', auctionId);
return;
}

let winningBid = winningBids[0];
if (winningBids.length > 1) {
winningBid = winningBids.filter(bid => bid.adId === cache.auctions[auctionId].adUnitCodes[adUnitId].bidWonAdId)[0];
winningBid = winningBids.filter(bid => bid.adId === cache.auctions[auctionId]?.adUnitCodes[adUnitId]?.bidWonAdId)[0];
}

const adapterName = getAdapterNameForAlias(winningBid.adapterCode || winningBid.bidder);
if (isOWPubmaticBid(adapterName) && isS2SBidder(winningBid.bidder)) {
return;
}
let origAdUnit = getAdUnit(cache.auctions[auctionId].origAdUnits, adUnitId) || {};
let origAdUnit = getAdUnit(cache.auctions[auctionId]?.origAdUnits, adUnitId) || {};
let owAdUnitId = origAdUnit.owAdUnitId || getGptSlotInfoForAdUnitCode(adUnitId)?.gptSlot || adUnitId;
let auctionCache = cache.auctions[auctionId];
let floorData = auctionCache.floorData;
let floorData = auctionCache?.floorData;
let wiid = cache.auctions[auctionId]?.wiid || auctionId;
let referrer = config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '';
let referrer = config.getConfig('pageUrl') || cache.auctions[auctionId]?.referer || '';
let adv = winningBid.bidResponse ? getAdDomain(winningBid.bidResponse) || undefined : undefined;
let fskp = floorData ? (floorData.floorRequestData ? (floorData.floorRequestData.skipped == false ? 0 : 1) : undefined) : undefined;
let pg = window.parseFloat(Number(winningBid?.bidResponse?.adserverTargeting?.hb_pb || winningBid?.bidResponse?.adserverTargeting?.pwtpb)) || undefined;
let pixelURL = END_POINT_WIN_BID_LOGGER;

pixelURL += 'pubid=' + publisherId;
pixelURL += '&purl=' + enc(config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '');
pixelURL += '&purl=' + enc(config.getConfig('pageUrl') || cache.auctions[auctionId]?.referer || '');
pixelURL += '&tst=' + Math.round((new window.Date()).getTime() / 1000);
pixelURL += '&iid=' + enc(wiid);
pixelURL += '&bidid=' + enc(winningBidId);
Expand All @@ -517,12 +513,12 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&au=' + enc(owAdUnitId);
pixelURL += '&pn=' + enc(adapterName);
pixelURL += '&bc=' + enc(winningBid.bidderCode || winningBid.bidder);
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
pixelURL += '&eg=' + enc(winningBid.bidResponse.bidGrossCpmUSD);
pixelURL += '&en=' + enc(winningBid.bidResponse?.bidPriceUSD);
pixelURL += '&eg=' + enc(winningBid.bidResponse?.bidGrossCpmUSD);
pixelURL += '&kgpv=' + enc(getValueForKgpv(winningBid, adUnitId));
pixelURL += '&origbidid=' + enc(winningBid?.bidResponse?.partnerImpId || winningBid?.bidResponse?.prebidBidId || winningBid.bidId);
pixelURL += '&di=' + enc(winningBid?.bidResponse?.dealId || OPEN_AUCTION_DEAL_ID);
const ds = winningBid.bidResponse?.meta ? getMetadata(winningBid.bidResponse.meta).ds : undefined;
const ds = winningBid.bidResponse?.meta ? getMetadata(winningBid.bidResponse.meta)?.ds : undefined;
if (ds) {
pixelURL += '&ds=' + enc(ds);
}
Expand All @@ -538,13 +534,15 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
(fskp != undefined) && (pixelURL += '&fskp=' + enc(fskp));
if (floorData) {
const floorRootValues = getFloorsCommonField(floorData.floorRequestData);
const { fsrc, fp, mv } = floorRootValues || {};
const params = { fsrc, fp, fmv: mv };
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
pixelURL += `&${key}=${enc(value)}`;
}
});
if (floorRootValues) {
const { ffs, fsrc, fp, mv } = floorRootValues || {};
const params = { ffs, fsrc, fp, fmv: mv };
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
pixelURL += `&${key}=${enc(value)}`;
}
});
}
const floorType = getFloorType(floorData.floorResponseData);
if (floorType !== undefined) {
pixelURL += '&ft=' + enc(floorType);
Expand Down
1 change: 1 addition & 0 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.ss).to.equal('1');
expect(data.fskp).to.equal('0');
expect(data.af).to.equal('video');
expect(data.ffs).to.equal('1');
expect(data.ds).to.equal('1208');
});

Expand Down

0 comments on commit ed011ea

Please sign in to comment.