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 : Added extra fields in tracker for analytics #10090

Merged
merged 7 commits into from
Jun 12, 2023
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