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

Staged Nightly update with regex fix #410

Merged
merged 1 commit into from
Oct 5, 2020
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
18 changes: 15 additions & 3 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function parseBidResponse(bid) {
'mediaType',
'params',
'mi',
'regexPattern', () => bid.regexPattern || undefined,
'partnerImpId', // partner impression ID
'dimensions', () => utils.pick(bid, [
'width',
Expand All @@ -166,6 +167,18 @@ function getDomainFromUrl(url) {
return a.hostname;
}

function getValueForKgpv(bid, adUnitId) {
if (bid.params.regexPattern) {
return bid.params.regexPattern;
} else if (bid.bidResponse && bid.bidResponse.regexPattern) {
return bid.bidResponse.regexPattern;
} else if (bid.params.kgpv) {
return bid.params.kgpv;
} else {
return adUnitId;
}
}

function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null;
return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) {
Expand All @@ -174,7 +187,7 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'pn': bid.bidder,
'bidid': bid.bidId,
'db': bid.bidResponse ? 0 : 1,
'kgpv': bid.params.kgpv ? bid.params.kgpv : adUnitId,
'kgpv': getValueForKgpv(bid, adUnitId),
'kgpsv': bid.params.kgpv ? bid.params.kgpv : adUnitId,
'psz': bid.bidResponse ? (bid.bidResponse.dimensions.width + 'x' + bid.bidResponse.dimensions.height) : '0x0',
'eg': bid.bidResponse ? bid.bidResponse.bidGrossCpmUSD : 0,
Expand Down Expand Up @@ -268,7 +281,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&pn=' + enc(winningBid.bidder);
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
pixelURL += '&eg=' + enc(winningBid.bidResponse.bidGrossCpmUSD);
pixelURL += '&kgpv=' + enc(winningBid.params.kgpv || adUnitId);
pixelURL += '&kgpv=' + enc(getValueForKgpv(winningBid, adUnitId));
pixelURL += '&piid=' + enc(winningBid.bidResponse.partnerImpId || EMPTY_STRING);
ajax(
pixelURL,
Expand Down Expand Up @@ -300,7 +313,6 @@ function auctionInitHandler(args) {
}

function bidRequestedHandler(args) {
cache.auctions[args.auctionId].gdprConsent = args.gdprConsent || undefined;
args.bids.forEach(function(bid) {
if (!cache.auctions[args.auctionId].adUnitCodes.hasOwnProperty(bid.adUnitCode)) {
cache.auctions[args.auctionId].adUnitCodes[bid.adUnitCode] = {
Expand Down
101 changes: 101 additions & 0 deletions test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,5 +696,106 @@ describe('pubmatic analytics adapter', function () {
expect(data.s[1].ps[0].ocpm).to.equal(100);
expect(data.s[1].ps[0].ocry).to.equal('JPY');
});

it('Logger: regexPattern in bid.params', function() {
const BID_REQUESTED_COPY = utils.deepClone(MOCK.BID_REQUESTED);
BID_REQUESTED_COPY.bids[1].params.regexPattern = '*';
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, BID_REQUESTED_COPY);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
events.emit(BID_RESPONSE, BID2);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);
events.emit(BID_WON, MOCK.BID_WON[0]);
events.emit(BID_WON, MOCK.BID_WON[1]);

clock.tick(2000 + 1000);
expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker
let request = requests[2]; // logger is executed late, trackers execute first
expect(request.url).to.equal('https://t.pubmatic.com/wl?pubid=9999');
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].sz).to.deep.equal(['1000x300', '970x250', '728x90']);
expect(data.s[1].ps).to.be.an('array');
expect(data.s[1].ps.length).to.equal(1);
expect(data.s[1].ps[0].pn).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('*');
expect(data.s[1].ps[0].kgpsv).to.equal('this-is-a-kgpv');
expect(data.s[1].ps[0].psz).to.equal('728x90');
expect(data.s[1].ps[0].eg).to.equal(1.52);
expect(data.s[1].ps[0].en).to.equal(1.52);
expect(data.s[1].ps[0].di).to.equal('the-deal-id');
expect(data.s[1].ps[0].dc).to.equal('PMP');
expect(data.s[1].ps[0].mi).to.equal('matched-impression');
expect(data.s[1].ps[0].l1).to.equal(3214);
expect(data.s[1].ps[0].l2).to.equal(0);
expect(data.s[1].ps[0].ss).to.equal(1);
expect(data.s[1].ps[0].t).to.equal(0);
expect(data.s[1].ps[0].wb).to.equal(0); // bidPriceUSD is not getting set as currency module is not added, so unable to set wb to 1
expect(data.s[1].ps[0].af).to.equal('banner');
expect(data.s[1].ps[0].ocpm).to.equal(1.52);
expect(data.s[1].ps[0].ocry).to.equal('USD');
// respective tracker slot
let firstTracker = requests[1].url;
expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt');
data = {};
firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]);
expect(data.kgpv).to.equal('*');
});

it('Logger: regexPattern in bid.bidResponse', function() {
const BID2_COPY = utils.deepClone(BID2);
BID2_COPY.regexPattern = '*';
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
events.emit(BID_RESPONSE, BID2_COPY);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);
events.emit(BID_WON, MOCK.BID_WON[0]);
events.emit(BID_WON, Object.assign({}, BID2_COPY, {
'status': 'rendered'
}));

clock.tick(2000 + 1000);
expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker
let request = requests[2]; // logger is executed late, trackers execute first
expect(request.url).to.equal('https://t.pubmatic.com/wl?pubid=9999');
let data = getLoggerJsonFromRequest(request.requestBody);
expect(data.s[1].sn).to.equal('/19968336/header-bid-tag-1');
expect(data.s[1].sz).to.deep.equal(['1000x300', '970x250', '728x90']);
expect(data.s[1].ps).to.be.an('array');
expect(data.s[1].ps.length).to.equal(1);
expect(data.s[1].ps[0].pn).to.equal('pubmatic');
expect(data.s[1].ps[0].bidid).to.equal('3bd4ebb1c900e2');
expect(data.s[1].ps[0].db).to.equal(0);
expect(data.s[1].ps[0].kgpv).to.equal('*');
expect(data.s[1].ps[0].kgpsv).to.equal('this-is-a-kgpv');
expect(data.s[1].ps[0].psz).to.equal('728x90');
expect(data.s[1].ps[0].eg).to.equal(1.52);
expect(data.s[1].ps[0].en).to.equal(1.52);
expect(data.s[1].ps[0].di).to.equal('the-deal-id');
expect(data.s[1].ps[0].dc).to.equal('PMP');
expect(data.s[1].ps[0].mi).to.equal('matched-impression');
expect(data.s[1].ps[0].l1).to.equal(3214);
expect(data.s[1].ps[0].l2).to.equal(0);
expect(data.s[1].ps[0].ss).to.equal(1);
expect(data.s[1].ps[0].t).to.equal(0);
expect(data.s[1].ps[0].wb).to.equal(0); // bidPriceUSD is not getting set as currency module is not added, so unable to set wb to 1
expect(data.s[1].ps[0].af).to.equal('banner');
expect(data.s[1].ps[0].ocpm).to.equal(1.52);
expect(data.s[1].ps[0].ocry).to.equal('USD');
// respective tracker slot
let firstTracker = requests[1].url;
expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt');
data = {};
firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]);
expect(data.kgpv).to.equal('*');
});
});
});