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

OpenWrap Release 21.7.0 #444

Merged
merged 6 commits into from
Jan 27, 2021
79 changes: 56 additions & 23 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import adapter from '../src/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import { ajax } from '../src/ajax.js';
import { config } from '../src/config.js';
import {
ajax
} from '../src/ajax.js';
import {
config
} from '../src/config.js';
import * as utils from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';
import {
getGlobal
} from '../src/prebidGlobal.js';

/// /////////// CONSTANTS //////////////
const ADAPTER_CODE = 'pubmatic';
Expand Down Expand Up @@ -47,7 +53,11 @@ function sizeToDimensions(size) {
}

function validMediaType(type) {
return ({'banner': 1, 'native': 1, 'video': 1}).hasOwnProperty(type);
return ({
'banner': 1,
'native': 1,
'video': 1
}).hasOwnProperty(type);
}

function formatSource(src) {
Expand Down Expand Up @@ -190,22 +200,38 @@ function getValueForKgpv(bid, adUnitId) {
} else if (bid.bidResponse && bid.bidResponse.regexPattern) {
return bid.bidResponse.regexPattern;
} else if (bid.params.kgpv) {
return bid.params.kgpv;
return getUpdatedKGPVForVideo(bid.params.kgpv, bid.bidResponse);
} else {
return adUnitId;
}
}

function getUpdatedKGPVForVideo(kgpv, bidResponse) {
if (bidResponse && bidResponse.mediaType && bidResponse.mediaType == 'video') {
var videoKgpv = ['', '0x0'];
var splitKgpv = kgpv.split('@');
if (splitKgpv.length == 2) {
if (splitKgpv[1].indexOf(':') > -1) {
var kgpvIndex = splitKgpv[1].split(':');
videoKgpv[1] = videoKgpv[1] + ':' + kgpvIndex[1];
}
videoKgpv[0] = splitKgpv[0];
}
kgpv = videoKgpv.join('@');
}
return kgpv;
}

function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null;
return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) {
return Object.keys(adUnit.bids).reduce(function (partnerBids, bidId) {
let bid = adUnit.bids[bidId];
partnerBids.push({
'pn': bid.bidder,
'bidid': bid.bidId,
'db': bid.bidResponse ? 0 : 1,
'kgpv': getValueForKgpv(bid, adUnitId),
'kgpsv': bid.params.kgpv ? bid.params.kgpv : adUnitId,
'kgpsv': bid.params.kgpv ? getUpdatedKGPVForVideo(bid.params.kgpv, bid.bidResponse) : adUnitId,
'psz': bid.bidResponse ? (bid.bidResponse.dimensions.width + 'x' + bid.bidResponse.dimensions.height) : '0x0',
'eg': bid.bidResponse ? bid.bidResponse.bidGrossCpmUSD : 0,
'en': bid.bidResponse ? bid.bidResponse.bidPriceUSD : 0,
Expand All @@ -215,7 +241,7 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'l2': 0,
'ss': (s2sBidders.indexOf(bid.bidder) > -1) ? 1 : 0,
't': (bid.status == ERROR && bid.error.code == TIMEOUT_ERROR) ? 1 : 0,
'wb': (highestBid && highestBid.requestId === bid.bidId ? 1 : 0),
'wb': (highestBid && highestBid.adId === bid.bidId ? 1 : 0),
'mi': bid.bidResponse ? (bid.bidResponse.mi || undefined) : undefined,
'af': bid.bidResponse ? (bid.bidResponse.mediaType || undefined) : undefined,
'ocpm': bid.bidResponse ? (bid.bidResponse.originalCpm || 0) : 0,
Expand All @@ -230,7 +256,9 @@ function executeBidsLoggerCall(e, highestCpmBids) {
let auctionId = e.auctionId;
let referrer = config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '';
let auctionCache = cache.auctions[auctionId];
let outputObj = { s: [] };
let outputObj = {
s: []
};
let pixelURL = END_POINT_BID_LOGGER;

if (!auctionCache) {
Expand All @@ -250,16 +278,18 @@ function executeBidsLoggerCall(e, highestCpmBids) {
outputObj['tst'] = Math.round((new window.Date()).getTime() / 1000);
outputObj['pid'] = '' + profileId;
outputObj['pdvid'] = '' + profileVersionId;
outputObj['dvc'] = {'plt': getDevicePlatform()};
outputObj['tgid'] = (function() {
outputObj['dvc'] = {
'plt': getDevicePlatform()
};
outputObj['tgid'] = (function () {
var testGroupId = parseInt(config.getConfig('testGroupId') || 0);
if (testGroupId <= 15 && testGroupId >= 0) {
return testGroupId;
}
return 0;
})();

outputObj.s = Object.keys(auctionCache.adUnitCodes).reduce(function(slotsArray, adUnitId) {
outputObj.s = Object.keys(auctionCache.adUnitCodes).reduce(function (slotsArray, adUnitId) {
let adUnit = auctionCache.adUnitCodes[adUnitId];
let slotObject = {
'sn': adUnitId,
Expand All @@ -275,8 +305,7 @@ function executeBidsLoggerCall(e, highestCpmBids) {
ajax(
pixelURL,
null,
'json=' + enc(JSON.stringify(outputObj)),
{
'json=' + enc(JSON.stringify(outputObj)), {
contentType: 'application/x-www-form-urlencoded',
withCredentials: true,
method: 'POST'
Expand All @@ -292,7 +321,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&purl=' + enc(config.getConfig('pageUrl') || cache.auctions[auctionId].referer || '');
pixelURL += '&tst=' + Math.round((new window.Date()).getTime() / 1000);
pixelURL += '&iid=' + enc(auctionId);
pixelURL += '&bidid=' + enc(winningBidId);
pixelURL += '&bidid=' + enc(winningBid.bidId);
pixelURL += '&pid=' + enc(profileId);
pixelURL += '&pdvid=' + enc(profileVersionId);
pixelURL += '&slot=' + enc(adUnitId);
Expand All @@ -304,19 +333,17 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
ajax(
pixelURL,
null,
null,
{
null, {
contentType: 'application/x-www-form-urlencoded',
withCredentials: true,
method: 'GET'
}
);
}

/// /////////// ADAPTER EVENT HANDLER FUNCTIONS //////////////

function auctionInitHandler(args) {
s2sBidders = (function() {
s2sBidders = (function () {
let s2sConf = config.getConfig('s2sConfig');
return (s2sConf && utils.isArray(s2sConf.bidders)) ? s2sConf.bidders : [];
}());
Expand All @@ -331,7 +358,7 @@ function auctionInitHandler(args) {
}

function bidRequestedHandler(args) {
args.bids.forEach(function(bid) {
args.bids.forEach(function (bid) {
if (!cache.auctions[args.auctionId].adUnitCodes.hasOwnProperty(bid.adUnitCode)) {
cache.auctions[args.auctionId].adUnitCodes[bid.adUnitCode] = {
bids: {},
Expand All @@ -349,6 +376,7 @@ function bidResponseHandler(args) {
utils.logError(LOG_PRE_FIX + 'Could not find associated bid request for bid response with requestId: ', args.requestId);
return;
}
bid.bidId = args.adId;
bid.source = formatSource(bid.source || args.source);
setBidStatus(bid, args);
bid.clientLatencyTimeMs = Date.now() - cache.auctions[args.auctionId].timestamp;
Expand Down Expand Up @@ -390,7 +418,7 @@ function bidTimeoutHandler(args) {
// db = 0 and t = 1 means bidder did respond with a bid but post timeout
args.forEach(badBid => {
let auctionCache = cache.auctions[badBid.auctionId];
let bid = auctionCache.adUnitCodes[badBid.adUnitCode].bids[ badBid.bidId || badBid.requestId ];
let bid = auctionCache.adUnitCodes[badBid.adUnitCode].bids[badBid.bidId || badBid.requestId];
if (bid) {
bid.status = ERROR;
bid.error = {
Expand All @@ -404,7 +432,9 @@ function bidTimeoutHandler(args) {

/// /////////// ADAPTER DEFINITION //////////////

let baseAdapter = adapter({analyticsType: 'endpoint'});
let baseAdapter = adapter({
analyticsType: 'endpoint'
});
let pubmaticAdapter = Object.assign({}, baseAdapter, {

enableAnalytics(conf = {}) {
Expand Down Expand Up @@ -441,7 +471,10 @@ let pubmaticAdapter = Object.assign({}, baseAdapter, {
baseAdapter.disableAnalytics.apply(this, arguments);
},

track({eventType, args}) {
track({
eventType,
args
}) {
switch (eventType) {
case CONSTANTS.EVENTS.AUCTION_INIT:
auctionInitHandler(args);
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const NATIVE_MINIMUM_REQUIRED_IMAGE_ASSETS = [
}
]

const NET_REVENUE = false;
const NET_REVENUE = true;
const dealChannelValues = {
1: 'PMP',
5: 'PREF',
Expand Down
12 changes: 6 additions & 6 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const BID = {
'statusMessage': 'Bid available',
'bidId': '2ecff0db240757',
'partnerImpId': 'partnerImpressionID-1',
'adId': 'fake_ad_id',
'adId': '2ecff0db240712',
'source': 's2s',
'requestId': '2ecff0db240757',
'currency': 'USD',
Expand Down Expand Up @@ -77,7 +77,7 @@ const BID2 = Object.assign({}, BID, {
adUnitCode: '/19968336/header-bid-tag-1',
bidId: '3bd4ebb1c900e2',
partnerImpId: 'partnerImpressionID-2',
adId: 'fake_ad_id_2',
adId: '3bd4ebb1c900e2',
requestId: '3bd4ebb1c900e2',
width: 728,
height: 90,
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].ps.length).to.equal(1);
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240712');
expect(data.s[0].ps[0].piid).to.equal('partnerImpressionID-1');
expect(data.s[0].ps[0].db).to.equal(0);
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -395,7 +395,7 @@ describe('pubmatic analytics adapter', function () {
expect(decodeURIComponent(data.purl)).to.equal('http://www.test.com/page.html');
expect(data.tst).to.equal('1519767014');
expect(data.iid).to.equal('25c6d7f5-699a-4bfc-87c9-996f915341fa');
expect(data.bidid).to.equal('2ecff0db240757');
expect(data.bidid).to.equal('2ecff0db240712');
expect(data.pid).to.equal('1111');
expect(data.pdvid).to.equal('20');
expect(decodeURIComponent(data.slot)).to.equal('/19968336/header-bid-tag-0');
Expand Down Expand Up @@ -441,7 +441,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].ps.length).to.equal(1);
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240712');
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].eg).to.equal(1.23);
expect(data.s[0].ps[0].en).to.equal(2.46);
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[0].ps).to.be.an('array');
expect(data.s[0].ps.length).to.equal(1);
expect(data.s[0].ps[0].pn).to.equal('pubmatic');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240757');
expect(data.s[0].ps[0].bidid).to.equal('2ecff0db240712');
expect(data.s[0].ps[0].kgpv).to.equal('/19968336/header-bid-tag-0');
expect(data.s[0].ps[0].eg).to.equal(1);
expect(data.s[0].ps[0].en).to.equal(200);
Expand Down
16 changes: 8 additions & 8 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ describe('PubMatic adapter', function () {
}
expect(response[0].dealId).to.equal(bidResponses.body.seatbid[0].bid[0].dealid);
expect(response[0].currency).to.equal('USD');
expect(response[0].netRevenue).to.equal(false);
expect(response[0].netRevenue).to.equal(true);
expect(response[0].ttl).to.equal(300);
expect(response[0].meta.networkId).to.equal(123);
expect(response[0].meta.buyerId).to.equal(976);
Expand All @@ -2702,7 +2702,7 @@ describe('PubMatic adapter', function () {
}
expect(response[1].dealId).to.equal(bidResponses.body.seatbid[1].bid[0].dealid);
expect(response[1].currency).to.equal('USD');
expect(response[1].netRevenue).to.equal(false);
expect(response[1].netRevenue).to.equal(true);
expect(response[1].ttl).to.equal(300);
expect(response[1].meta.networkId).to.equal(422);
expect(response[1].meta.buyerId).to.equal(832);
Expand Down Expand Up @@ -2795,7 +2795,7 @@ describe('PubMatic adapter', function () {
}
expect(response[0].dealId).to.equal(bidResponses.body.seatbid[0].bid[0].dealid);
expect(response[0].currency).to.equal('USD');
expect(response[0].netRevenue).to.equal(false);
expect(response[0].netRevenue).to.equal(true);
expect(response[0].ttl).to.equal(300);
expect(response[0].meta.networkId).to.equal(123);
expect(response[0].adserverTargeting.hb_buyid_pubmatic).to.equal('BUYER-ID-987');
Expand All @@ -2819,7 +2819,7 @@ describe('PubMatic adapter', function () {
}
expect(response[1].dealId).to.equal(bidResponses.body.seatbid[1].bid[0].dealid);
expect(response[1].currency).to.equal('USD');
expect(response[1].netRevenue).to.equal(false);
expect(response[1].netRevenue).to.equal(true);
expect(response[1].ttl).to.equal(300);
expect(response[1].meta.networkId).to.equal(422);
expect(response[1].adserverTargeting.hb_buyid_pubmatic).to.equal('BUYER-ID-789');
Expand All @@ -2845,7 +2845,7 @@ describe('PubMatic adapter', function () {
expect(response[0].ttl).to.equal(300);
expect(response[0].ad).to.equal('');
expect(response[0].creativeId).to.equal(0);
expect(response[0].netRevenue).to.equal(false);
expect(response[0].netRevenue).to.equal(true);
expect(response[0].cpm).to.equal(0);
expect(response[0].currency).to.equal('USD');
expect(response[0].referrer).to.equal(request.site && request.site.ref ? request.site.ref : '');
Expand Down Expand Up @@ -2876,7 +2876,7 @@ describe('PubMatic adapter', function () {
}
expect(response[0].dealId).to.equal(bidResponses.body.seatbid[0].bid[0].dealid);
expect(response[0].currency).to.equal('USD');
expect(response[0].netRevenue).to.equal(false);
expect(response[0].netRevenue).to.equal(true);
expect(response[0].ttl).to.equal(300);
expect(response[0].referrer).to.include(request.site && request.site.ref ? request.site.ref : '');
expect(response[0].ad).to.equal(bidResponses.body.seatbid[0].bid[0].adm);
Expand All @@ -2886,7 +2886,7 @@ describe('PubMatic adapter', function () {
expect(response[1].ttl).to.equal(300);
expect(response[1].ad).to.equal('');
expect(response[1].creativeId).to.equal(0);
expect(response[1].netRevenue).to.equal(false);
expect(response[1].netRevenue).to.equal(true);
expect(response[1].cpm).to.equal(0);
expect(response[1].currency).to.equal('USD');
expect(response[1].referrer).to.equal(request.site && request.site.ref ? request.site.ref : '');
Expand All @@ -2911,7 +2911,7 @@ describe('PubMatic adapter', function () {
}
expect(response[0].dealId).to.equal(bidResponses.body.seatbid[0].bid[0].dealid);
expect(response[0].currency).to.equal('USD');
expect(response[0].netRevenue).to.equal(false);
expect(response[0].netRevenue).to.equal(true);
expect(response[0].ttl).to.equal(300);
expect(response[0].referrer).to.include(request.site && request.site.ref ? request.site.ref : '');
expect(response[0].ad).to.equal(bidResponses.body.seatbid[0].bid[0].adm);
Expand Down