Skip to content

Commit

Permalink
PubMatic Bid Adapter : Support geo (lat & lon) using ortb2.(device|us…
Browse files Browse the repository at this point in the history
…er) (#10371)

* Read geo from ortb2.device or user

* Read geo from ortb2.device or user
  • Loading branch information
kapil-tuptewar authored Aug 20, 2023
1 parent f075b1b commit 3263e6e
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 40 deletions.
29 changes: 18 additions & 11 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,10 +1150,7 @@ export const spec = {
payload.user.gender = (conf.gender ? conf.gender.trim() : UNDEFINED);
payload.user.geo = {};
// TODO: fix lat and long to only come from request object, not params
payload.user.geo.lat = _parseSlotParam('lat', 0);
payload.user.geo.lon = _parseSlotParam('lon', 0);
payload.user.yob = _parseSlotParam('yob', conf.yob);
payload.device.geo = payload.user.geo;
payload.site.page = conf.kadpageurl.trim() || payload.site.page.trim();
payload.site.domain = _getDomainFromURL(payload.site.page);

Expand Down Expand Up @@ -1212,22 +1209,32 @@ export const spec = {

// First Party Data
const commonFpd = (bidderRequest && bidderRequest.ortb2) || {};
if (commonFpd.site) {
const { user, device, site, bcat } = commonFpd;
if (site) {
const { page, domain, ref } = payload.site;
mergeDeep(payload, {site: commonFpd.site});
mergeDeep(payload, {site: site});
payload.site.page = page;
payload.site.domain = domain;
payload.site.ref = ref;
}
if (commonFpd.user) {
mergeDeep(payload, {user: commonFpd.user});
if (user) {
mergeDeep(payload, {user: user});
}
if (commonFpd.bcat) {
blockedIabCategories = blockedIabCategories.concat(commonFpd.bcat);
if (bcat) {
blockedIabCategories = blockedIabCategories.concat(bcat);
}
// check if fpd ortb2 contains device property with sua object
if (commonFpd.device?.sua) {
payload.device.sua = commonFpd.device?.sua;
if (device?.sua) {
payload.device.sua = device?.sua;
}

if (user?.geo && device?.geo) {
payload.device.geo = { ...payload.device.geo, ...device.geo };
payload.user.geo = { ...payload.user.geo, ...user.geo };
} else {
if (user?.geo || device?.geo) {
payload.user.geo = payload.device.geo = (user?.geo ? { ...payload.user.geo, ...user.geo } : { ...payload.user.geo, ...device.geo });
}
}

if (commonFpd.ext?.prebid?.bidderparams?.[bidderRequest.bidderCode]?.acat) {
Expand Down
140 changes: 111 additions & 29 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,19 @@ describe('PubMatic adapter', function () {
ortb2: {
source: {
tid: 'source-tid'
}
},
device: {
geo: {
lat: '36.5189',
lon: '-76.4063'
}
},
user: {
geo: {
lat: '26.8915',
lon: '-56.6340'
}
},
}
});
let data = JSON.parse(request.data);
Expand All @@ -1144,10 +1156,10 @@ describe('PubMatic adapter', function () {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id
expect(data.user.yob).to.equal(parseInt(bidRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(bidRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.user.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.device.geo.lat).to.equal('36.5189'); // Latitude
expect(data.device.geo.lon).to.equal('-76.4063'); // Lognitude
expect(data.user.geo.lat).to.equal('26.8915'); // Latitude
expect(data.user.geo.lon).to.equal('-56.6340'); // Lognitude
expect(data.ext.wrapper.wv).to.equal($$REPO_AND_VERSION$$); // Wrapper Version
expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId
expect(data.source.tid).to.equal('source-tid'); // Prebid TransactionId
Expand Down Expand Up @@ -1387,7 +1399,21 @@ describe('PubMatic adapter', function () {
it('Request params check: without adSlot', function () {
delete bidRequests[0].params.adSlot;
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
auctionId: 'new-auction-id',
ortb2: {
device: {
geo: {
lat: '36.5189',
lon: '-76.4063'
}
},
user: {
geo: {
lat: '26.8915',
lon: '-56.6340'
}
},
}
});
let data = JSON.parse(request.data);
expect(data.at).to.equal(1); // auction type
Expand All @@ -1397,10 +1423,10 @@ describe('PubMatic adapter', function () {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id
expect(data.user.yob).to.equal(parseInt(bidRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(bidRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.user.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.device.geo.lat).to.equal('36.5189'); // Latitude
expect(data.device.geo.lon).to.equal('-76.4063'); // Lognitude
expect(data.user.geo.lat).to.equal('26.8915'); // Latitude
expect(data.user.geo.lon).to.equal('-56.6340'); // Lognitude
expect(data.ext.wrapper.wv).to.equal($$REPO_AND_VERSION$$); // Wrapper Version
expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId
expect(data.ext.wrapper.wiid).to.equal(bidRequests[0].params.wiid); // OpenWrap: Wrapper Impression ID
Expand Down Expand Up @@ -1596,7 +1622,21 @@ describe('PubMatic adapter', function () {

it('Pass auctiondId as wiid if wiid is not passed in params', function () {
let bidRequest = {
auctionId: 'new-auction-id'
auctionId: 'new-auction-id',
ortb2: {
device: {
geo: {
lat: '36.5189',
lon: '-76.4063'
}
},
user: {
geo: {
lat: '26.8915',
lon: '-56.6340'
}
},
}
};
delete bidRequests[0].params.wiid;
let request = spec.buildRequests(bidRequests, bidRequest);
Expand All @@ -1608,10 +1648,10 @@ describe('PubMatic adapter', function () {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id
expect(data.user.yob).to.equal(parseInt(bidRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(bidRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Longitude
expect(data.user.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Longitude
expect(data.device.geo.lat).to.equal('36.5189'); // Latitude
expect(data.device.geo.lon).to.equal('-76.4063'); // Lognitude
expect(data.user.geo.lat).to.equal('26.8915'); // Latitude
expect(data.user.geo.lon).to.equal('-56.6340'); // Lognitude
expect(data.ext.wrapper.wv).to.equal($$REPO_AND_VERSION$$); // Wrapper Version
expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId
expect(data.ext.wrapper.wiid).to.equal('new-auction-id'); // OpenWrap: Wrapper Impression ID
Expand All @@ -1631,6 +1671,20 @@ describe('PubMatic adapter', function () {
gdprConsent: {
consentString: 'kjfdniwjnifwenrif3',
gdprApplies: true
},
ortb2: {
device: {
geo: {
lat: '36.5189',
lon: '-76.4063'
}
},
user: {
geo: {
lat: '26.8915',
lon: '-56.6340'
}
},
}
};
let request = spec.buildRequests(bidRequests, bidRequest);
Expand All @@ -1644,10 +1698,10 @@ describe('PubMatic adapter', function () {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id
expect(data.user.yob).to.equal(parseInt(bidRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(bidRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.user.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.device.geo.lat).to.equal('36.5189'); // Latitude
expect(data.device.geo.lon).to.equal('-76.4063'); // Lognitude
expect(data.user.geo.lat).to.equal('26.8915'); // Latitude
expect(data.user.geo.lon).to.equal('-56.6340'); // Lognitude
expect(data.ext.wrapper.wv).to.equal($$REPO_AND_VERSION$$); // Wrapper Version
expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId
expect(data.ext.wrapper.wiid).to.equal(bidRequests[0].params.wiid); // OpenWrap: Wrapper Impression ID
Expand All @@ -1664,7 +1718,21 @@ describe('PubMatic adapter', function () {

it('Request params check with USP/CCPA Consent', function () {
let bidRequest = {
uspConsent: '1NYN'
uspConsent: '1NYN',
ortb2: {
device: {
geo: {
lat: '36.5189',
lon: '-76.4063'
}
},
user: {
geo: {
lat: '26.8915',
lon: '-56.6340'
}
},
}
};
let request = spec.buildRequests(bidRequests, bidRequest);
let data = JSON.parse(request.data);
Expand All @@ -1676,10 +1744,10 @@ describe('PubMatic adapter', function () {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id
expect(data.user.yob).to.equal(parseInt(bidRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(bidRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.user.geo.lat).to.not.equal(parseFloat(bidRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.not.equal(parseFloat(bidRequests[0].params.lon)); // Lognitude
expect(data.device.geo.lat).to.equal('36.5189'); // Latitude
expect(data.device.geo.lon).to.equal('-76.4063'); // Lognitude
expect(data.user.geo.lat).to.equal('26.8915'); // Latitude
expect(data.user.geo.lon).to.equal('-56.6340'); // Lognitude
expect(data.ext.wrapper.wv).to.equal($$REPO_AND_VERSION$$); // Wrapper Version
expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId
expect(data.ext.wrapper.wiid).to.equal(bidRequests[0].params.wiid); // OpenWrap: Wrapper Impression ID
Expand Down Expand Up @@ -2325,7 +2393,21 @@ describe('PubMatic adapter', function () {

it('Request params check for 1 banner and 1 video ad', function () {
let request = spec.buildRequests(multipleMediaRequests, {
auctionId: 'new-auction-id'
auctionId: 'new-auction-id',
ortb2: {
device: {
geo: {
lat: '36.5189',
lon: '-76.4063'
}
},
user: {
geo: {
lat: '26.8915',
lon: '-56.6340'
}
},
}
});
let data = JSON.parse(request.data);

Expand All @@ -2339,10 +2421,10 @@ describe('PubMatic adapter', function () {
expect(data.site.publisher.id).to.equal(multipleMediaRequests[0].params.publisherId); // publisher Id
expect(data.user.yob).to.equal(parseInt(multipleMediaRequests[0].params.yob)); // YOB
expect(data.user.gender).to.equal(multipleMediaRequests[0].params.gender); // Gender
expect(data.device.geo.lat).to.not.equal(parseFloat(multipleMediaRequests[0].params.lat)); // Latitude
expect(data.device.geo.lon).to.not.equal(parseFloat(multipleMediaRequests[0].params.lon)); // Lognitude
expect(data.user.geo.lat).to.not.equal(parseFloat(multipleMediaRequests[0].params.lat)); // Latitude
expect(data.user.geo.lon).to.not.equal(parseFloat(multipleMediaRequests[0].params.lon)); // Lognitude
expect(data.device.geo.lat).to.equal('36.5189'); // Latitude
expect(data.device.geo.lon).to.equal('-76.4063'); // Lognitude
expect(data.user.geo.lat).to.equal('26.8915'); // Latitude
expect(data.user.geo.lon).to.equal('-56.6340'); // Lognitude
expect(data.ext.wrapper.wv).to.equal($$REPO_AND_VERSION$$); // Wrapper Version
expect(data.ext.wrapper.transactionId).to.equal(multipleMediaRequests[0].transactionId); // Prebid TransactionId
expect(data.ext.wrapper.wiid).to.equal(multipleMediaRequests[0].params.wiid); // OpenWrap: Wrapper Impression ID
Expand Down

0 comments on commit 3263e6e

Please sign in to comment.