Skip to content

Commit

Permalink
Pubmatic Analytics Adapter : skip duplicate data for pubmatic bids in…
Browse files Browse the repository at this point in the history
… logger and tracker (prebid#10787)

* Adding config for openwrap metadapter

* Changed from http to https and timeout to 500

* Timeout value update

* 1.Added safechecks for s2s metadapter case 2.Skipped firing client side tracker for pubmatic 3.Skipped adding pubmatic bid in logger

* Analytics adapter changes to avoid duplicate data in case of OW S2S setup

* Moved to bottom

* kick off tests

---------

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
pm-priyanka-deshmane and ChrisHuie authored Dec 12, 2023
1 parent 6275c00 commit 048f735
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 27 deletions.
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 @@ -418,13 +434,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 @@ -477,7 +500,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 @@ -508,6 +534,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 @@ -572,7 +602,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

0 comments on commit 048f735

Please sign in to comment.