Skip to content

Commit

Permalink
PubMatic Analytics Adapter: add logging for "advertiser domain" (preb…
Browse files Browse the repository at this point in the history
…id#7888)

* Changed net revenue to True

* Logging adomain in logger

* Handled with different variable names

* Changed string in double quotes to single quotes

Co-authored-by: Azhar <azhar@L1119.local>
  • Loading branch information
2 people authored and avj83 committed Jan 24, 2022
1 parent 7648f07 commit 63469f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ function getAdapterNameForAlias(aliasName) {
return adapterManager.aliasRegistry[aliasName] || aliasName;
}

function getAdDomain(bidResponse) {
if (bidResponse.meta && bidResponse.meta.advertiserDomains) {
let adomain = bidResponse.meta.advertiserDomains[0]
if (adomain) {
try {
let hostname = (new URL(adomain));
return hostname.hostname.replace('www.', '');
} catch (e) {
logWarn(LOG_PRE_FIX + 'Adomain URL (Not a proper URL):', adomain);
return adomain.replace('www.', '');
}
}
}
}

function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null;
return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) {
Expand All @@ -218,6 +233,7 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) {
'dc': bid.bidResponse ? (bid.bidResponse.dealChannel || EMPTY_STRING) : EMPTY_STRING,
'l1': bid.bidResponse ? bid.clientLatencyTimeMs : 0,
'l2': 0,
'adv': bid.bidResponse ? getAdDomain(bid.bidResponse) || undefined : undefined,
'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),
Expand Down
14 changes: 13 additions & 1 deletion test/spec/modules/pubmaticAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const BID2 = Object.assign({}, BID, {
'hb_pb': '1.500',
'hb_size': '728x90',
'hb_source': 'server'
},
meta: {
advertiserDomains: ['example.com']
}
});

Expand Down Expand Up @@ -382,6 +385,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down Expand Up @@ -651,6 +655,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down Expand Up @@ -708,6 +713,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down Expand Up @@ -754,6 +760,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand All @@ -771,9 +778,10 @@ describe('pubmatic analytics adapter', function () {
expect(data.kgpv).to.equal('*');
});

it('Logger: regexPattern in bid.bidResponse', function() {
it('Logger: regexPattern in bid.bidResponse and url in adomain', function() {
const BID2_COPY = utils.deepClone(BID2);
BID2_COPY.regexPattern = '*';
BID2_COPY.meta.advertiserDomains = ['https://www.example.com/abc/223']
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
Expand Down Expand Up @@ -808,6 +816,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down Expand Up @@ -859,6 +868,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down Expand Up @@ -912,6 +922,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down Expand Up @@ -1011,6 +1022,7 @@ describe('pubmatic analytics adapter', function () {
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].adv).to.equal('example.com');
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);
Expand Down

0 comments on commit 63469f2

Please sign in to comment.