Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pubmatic Analytics Adapter : skip duplicate data for pubmatic bids in logger and tracker #10897

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js';

/// /////////// CONSTANTS //////////////
const ADAPTER_CODE = 'pubmatic';
const VENDOR_OPENWRAP = 'openwrap';
const SEND_TIMEOUT = 2000;
const END_POINT_HOST = 'https://t.pubmatic.com/';
const END_POINT_BID_LOGGER = END_POINT_HOST + 'wl?';
Expand Down Expand Up @@ -258,12 +259,27 @@ function isS2SBidder(bidder) {
return (s2sBidders.indexOf(bidder) > -1) ? 1 : 0
}

function isOWPubmaticBid(adapterName) {
let s2sConf = config.getConfig('s2sConfig');
let s2sConfArray = isArray(s2sConf) ? s2sConf : [s2sConf];
return s2sConfArray.some(conf => {
if (adapterName === ADAPTER_CODE && conf.defaultVendor === VENDOR_OPENWRAP &&
conf.bidders.indexOf(ADAPTER_CODE) > -1) {
return true;
}
})
}

function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null;
return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) {
adUnit.bids[bidId].forEach(function(bid) {
let adapterName = getAdapterNameForAlias(bid.adapterCode || bid.bidder);
if (isOWPubmaticBid(adapterName) && isS2SBidder(bid.bidder)) {
return;
}
partnerBids.push({
'pn': getAdapterNameForAlias(bid.adapterCode || bid.bidder),
'pn': adapterName,
'bc': bid.bidderCode || bid.bidder,
'bidid': bid.bidId || bidId,
'db': bid.bidResponse ? 0 : 1,
Expand Down Expand Up @@ -419,13 +435,20 @@ 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];
let winningBid = winningBids[0];
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];
}

const adapterName = getAdapterNameForAlias(winningBid.adapterCode || winningBid.bidder);
if (isOWPubmaticBid(adapterName) && isS2SBidder(winningBid.bidder)) {
return;
}
let origAdUnit = getAdUnit(cache.auctions[auctionId].origAdUnits, adUnitId) || {};
let auctionCache = cache.auctions[auctionId];
let floorData = auctionCache.floorData;
Expand Down Expand Up @@ -479,7 +502,10 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
function auctionInitHandler(args) {
s2sBidders = (function() {
let s2sConf = config.getConfig('s2sConfig');
return (s2sConf && isArray(s2sConf.bidders)) ? s2sConf.bidders : [];
let s2sBidders = [];
(s2sConf || []) &&
isArray(s2sConf) ? s2sConf.map(conf => s2sBidders.push(...conf.bidders)) : s2sBidders.push(...s2sConf.bidders);
return s2sBidders || [];
}());
let cacheEntry = pick(args, [
'timestamp',
Expand Down Expand Up @@ -513,6 +539,10 @@ function bidRequestedHandler(args) {
}

function bidResponseHandler(args) {
if (!args.requestId) {
logWarn(LOG_PRE_FIX + 'Got null requestId in bidResponseHandler');
return;
}
let bid = cache.auctions[args.auctionId].adUnitCodes[args.adUnitCode].bids[args.requestId][0];
if (!bid) {
logError(LOG_PRE_FIX + 'Could not find associated bid request for bid response with requestId: ', args.requestId);
Expand Down Expand Up @@ -577,7 +607,7 @@ function auctionEndHandler(args) {
let highestCpmBids = getGlobal().getHighestCpmBids() || [];
setTimeout(() => {
executeBidsLoggerCall.call(this, args, highestCpmBids);
}, (cache.auctions[args.auctionId].bidderDonePendingCount === 0 ? 500 : SEND_TIMEOUT));
}, (cache.auctions[args.auctionId]?.bidderDonePendingCount === 0 ? 500 : SEND_TIMEOUT));
}

function bidTimeoutHandler(args) {
Expand Down
Loading