Skip to content

Commit

Permalink
PubMatic Analytics Adapter : Added extra fields in tracker for analyt…
Browse files Browse the repository at this point in the history
…ics (prebid#10090)

* Additional fields in tracker call for Analytics reporting

* Test cases change
  • Loading branch information
pm-priyanka-deshmane authored and Michele Nasti committed Aug 25, 2023
1 parent 51f4590 commit c9bab66
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
39 changes: 31 additions & 8 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ export function getMetadata(meta) {
return metaObj;
}

function isS2SBidder(bidder) {
return (s2sBidders.indexOf(bidder) > -1) ? 1 : 0
}

function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null;
return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) {
Expand All @@ -275,7 +279,7 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'l1': bid.bidResponse ? bid.clientLatencyTimeMs : 0,
'l2': 0,
'adv': bid.bidResponse ? getAdDomain(bid.bidResponse) || undefined : undefined,
'ss': (s2sBidders.indexOf(bid.bidder) > -1) ? 1 : 0,
'ss': isS2SBidder(bid.bidder),
't': (bid.status == ERROR && bid.error.code == TIMEOUT_ERROR) ? 1 : 0,
'wb': (highestBid && highestBid.adId === bid.adId ? 1 : 0),
'mi': bid.bidResponse ? (bid.bidResponse.mi || undefined) : undefined,
Expand Down Expand Up @@ -311,6 +315,14 @@ function getAdUnit(adUnits, adUnitId) {
return adUnits.filter(adUnit => (adUnit.divID && adUnit.divID == adUnitId) || (adUnit.code == adUnitId))[0];
}

function getTgId() {
var testGroupId = parseInt(config.getConfig('testGroupId') || 0);
if (testGroupId <= 15 && testGroupId >= 0) {
return testGroupId;
}
return 0;
}

function executeBidsLoggerCall(e, highestCpmBids) {
let auctionId = e.auctionId;
let referrer = config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '';
Expand All @@ -337,13 +349,7 @@ function executeBidsLoggerCall(e, highestCpmBids) {
outputObj['pid'] = '' + profileId;
outputObj['pdvid'] = '' + profileVersionId;
outputObj['dvc'] = {'plt': getDevicePlatform()};
outputObj['tgid'] = (function() {
var testGroupId = parseInt(config.getConfig('testGroupId') || 0);
if (testGroupId <= 15 && testGroupId >= 0) {
return testGroupId;
}
return 0;
})();
outputObj['tgid'] = getTgId();

if (floorData) {
outputObj['fmv'] = floorData.floorRequestData ? floorData.floorRequestData.modelVersion || undefined : undefined;
Expand Down Expand Up @@ -391,6 +397,12 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {

const adapterName = getAdapterNameForAlias(winningBid.adapterCode || winningBid.bidder);
let origAdUnit = getAdUnit(cache.auctions[auctionId].origAdUnits, adUnitId) || {};
let auctionCache = cache.auctions[auctionId];
let floorData = auctionCache.floorData;
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 pixelURL = END_POINT_WIN_BID_LOGGER;
pixelURL += 'pubid=' + publisherId;
pixelURL += '&purl=' + enc(config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '');
Expand All @@ -407,6 +419,17 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&eg=' + enc(winningBid.bidResponse.bidGrossCpmUSD);
pixelURL += '&kgpv=' + enc(getValueForKgpv(winningBid, adUnitId));
pixelURL += '&piid=' + enc(winningBid.bidResponse.partnerImpId || EMPTY_STRING);

pixelURL += '&plt=' + enc(getDevicePlatform());
pixelURL += '&psz=' + enc((winningBid?.bidResponse?.dimensions?.width || '0') + 'x' +
(winningBid?.bidResponse?.dimensions?.height || '0'));
pixelURL += '&tgid=' + enc(getTgId());
adv && (pixelURL += '&adv=' + enc(adv));
pixelURL += '&orig=' + enc(getDomainFromUrl(referrer));
pixelURL += '&ss=' + enc(isS2SBidder(winningBid.bidder));
(fskp != undefined) && (pixelURL += '&fskp=' + enc(fskp));
pixelURL += '&af=' + enc(winningBid.bidResponse ? (winningBid.bidResponse.mediaType || undefined) : undefined);

ajax(
pixelURL,
null,
Expand Down
7 changes: 7 additions & 0 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ describe('pubmatic analytics adapter', function () {
expect(data.eg).to.equal('1.23');
expect(data.en).to.equal('1.23');
expect(data.piid).to.equal('partnerImpressionID-1');
expect(data.plt).to.equal('1');
expect(data.psz).to.equal('640x480');
expect(data.tgid).to.equal('15');
expect(data.orig).to.equal('www.test.com');
expect(data.ss).to.equal('1');
expect(data.fskp).to.equal('0');
expect(data.af).to.equal('video');
});

it('bidCpmAdjustment: USD: Logger: best case + win tracker', function() {
Expand Down

0 comments on commit c9bab66

Please sign in to comment.