Skip to content

Commit

Permalink
Merge pull request #536 from PubMatic-OpenWrap/UOE-7811
Browse files Browse the repository at this point in the history
Stop overwriting site.page, site.domain & site.ref information
  • Loading branch information
kapil-tuptewar authored Jun 28, 2022
2 parents dd731a5 + ced7fb2 commit ca22a8a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
22 changes: 21 additions & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ let defaultAliases = {
pubmatic2: 'pubmatic'
}
let isPrebidKeys = false;
let siteObj = {};
let siteProperties = ['page', 'domain', 'ref'];
/**
* @typedef {Object} AdapterOptions
* @summary s2sConfig parameter that adds arguments to resulting OpenRTB payload that goes to Prebid Server
Expand Down Expand Up @@ -366,6 +368,8 @@ function _appendSiteAppDevice(request, pageUrl, accountId) {
if (!request.site.page) {
request.site.page = pageUrl;
}
siteObj.domain = _getDomainFromURL(request.site.page);
siteObj.ref = window.document.referrer;
}
if (typeof config.getConfig('device') === 'object') {
request.device = config.getConfig('device');
Expand All @@ -384,13 +388,27 @@ function _appendSiteAppDevice(request, pageUrl, accountId) {
request.device.language = request.device.language && request.device.language.split('-')[0];
}

function updateSiteObject(request) {
for (let key in siteObj) {
if (deepAccess(request, `site.${key}`) && siteProperties.includes(key)) {
request.site[key] = siteObj[key];
}
}
}

function _getDomainFromURL(url) {
let anchor = document.createElement('a');
anchor.href = url;
return anchor.hostname;
}

function addBidderFirstPartyDataToRequest(request) {
const bidderConfig = config.getBidderConfig();
const fpdConfigs = Object.keys(bidderConfig).reduce((acc, bidder) => {
const currBidderConfig = bidderConfig[bidder];
if (currBidderConfig.ortb2) {
const ortb2 = mergeDeep({}, currBidderConfig.ortb2);

updateSiteObject(ortb2);
acc.push({
bidders: [ bidder ],
config: { ortb2 }
Expand Down Expand Up @@ -993,8 +1011,10 @@ Object.assign(ORTB2.prototype, {
deepSetValue(request, 'regs.coppa', 1);
}

siteObj = mergeDeep(siteObj, request.site);
const commonFpd = getConfig('ortb2') || {};
mergeDeep(request, commonFpd);
updateSiteObject(request);
// delete isPrebidPubMaticAnalyticsEnabled from extPrebid object as it not required in request.
// it is only used to decide impressionId for wiid parameter in logger and tracker calls.
delete request.ext.prebid.isPrebidPubMaticAnalyticsEnabled;
Expand Down
6 changes: 6 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,13 @@ export const spec = {
// First Party Data
const commonFpd = config.getConfig('ortb2') || {};
if (commonFpd.site) {
// Saving page, domain & ref property from payload before getting replaced by fpd modules.
const {page, domain, ref} = payload.site;
mergeDeep(payload, {site: commonFpd.site});
// Replace original values for page, domain & ref
payload.site.page = page;
payload.site.domain = domain;
payload.site.ref = ref;
}
if (commonFpd.user) {
mergeDeep(payload, {user: commonFpd.user});
Expand Down
2 changes: 1 addition & 1 deletion modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const USER_IDS_CONFIG = {
source: 'zeotap.com',
atype: 1,
getValue: function getValue(data) {
return isPlainObject(data)? data.id : data;
return isPlainObject(data) ? data.id : data;
}
},

Expand Down
2 changes: 1 addition & 1 deletion modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ function encryptSignals(signals, version = 1) {
* This function will be exposed in the global-name-space so that publisher can register the signals-ESP.
*/
function registerSignalSources() {
//Need to keep below change always instead of using isGptPubadsDefined()
// Need to keep below change always instead of using isGptPubadsDefined()
if (!window.googletag) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1590,13 +1590,12 @@ describe('PubMatic adapter', function () {
describe('FPD', function() {
let newRequest;

it('ortb2.site should be merged in the request', function() {
it('ortb2.site should be merged except page, domain & ref in the request', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
'ortb2': {
site: {
domain: 'page.example.com',
cat: ['IAB2'],
sectioncat: ['IAB2-2']
}
Expand All @@ -1606,7 +1605,6 @@ describe('PubMatic adapter', function () {
});
const request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.site.domain).to.equal('page.example.com');
expect(data.site.cat).to.deep.equal(['IAB2']);
expect(data.site.sectioncat).to.deep.equal(['IAB2-2']);
sandbox.restore();
Expand Down

0 comments on commit ca22a8a

Please sign in to comment.