From 6918463258115671fca44208521c98a5f568f5bc Mon Sep 17 00:00:00 2001 From: Nayan Date: Tue, 27 Dec 2022 18:16:45 +0200 Subject: [PATCH 1/6] Adding sua to device object --- modules/yieldmoBidAdapter.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 64ab8a87eea..55dd2ad2602 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -513,8 +513,17 @@ function openRtbSite(bidRequest, bidderRequest) { function openRtbDevice(bidRequest) { const deviceObj = { ua: navigator.userAgent, - language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), + language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), }; + // Add User Agent Client hunts. + const uaClientHints = deepAccess(bidRequest, 'ortb2Imp.device.sua'); + let sua = null; + if (uaClientHints) { + sua = pick(uaClientHints, ['browsers', 'platform', 'mobile', 'model']); + } + if (sua) { + deepSetValue(deviceObj, 'sua', Object.assign({}, sua, deviceObj.sua)); + } return deviceObj; } From 9acb25ae4d2e9c3e21281a8ca05cd0f615e8d93f Mon Sep 17 00:00:00 2001 From: Nayan Date: Tue, 27 Dec 2022 18:51:02 +0200 Subject: [PATCH 2/6] Update --- modules/yieldmoBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 55dd2ad2602..87e44e1688f 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -522,7 +522,7 @@ function openRtbDevice(bidRequest) { sua = pick(uaClientHints, ['browsers', 'platform', 'mobile', 'model']); } if (sua) { - deepSetValue(deviceObj, 'sua', Object.assign({}, sua, deviceObj.sua)); + deepSetValue(deviceObj, 'sua', sua); } return deviceObj; } From 9f0cb6cc37712208bda5fbe3b5d52e5293f043e3 Mon Sep 17 00:00:00 2001 From: Nayan Date: Wed, 28 Dec 2022 18:58:37 +0200 Subject: [PATCH 3/6] import pick --- modules/yieldmoBidAdapter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 87e44e1688f..719f9a8d88b 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -11,7 +11,8 @@ import { isStr, logError, parseQueryStringParameters, - parseUrl + parseUrl, + pick } from '../src/utils.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; From 891e0a7a04440d2c9368312a0561eaefdffa5e14 Mon Sep 17 00:00:00 2001 From: Nayan Date: Wed, 28 Dec 2022 19:37:30 +0200 Subject: [PATCH 4/6] ESLint fixes --- modules/yieldmoBidAdapter.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 719f9a8d88b..b2f9736cb44 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -514,17 +514,17 @@ function openRtbSite(bidRequest, bidderRequest) { function openRtbDevice(bidRequest) { const deviceObj = { ua: navigator.userAgent, - language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), + language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), }; - // Add User Agent Client hunts. - const uaClientHints = deepAccess(bidRequest, 'ortb2Imp.device.sua'); - let sua = null; - if (uaClientHints) { - sua = pick(uaClientHints, ['browsers', 'platform', 'mobile', 'model']); - } - if (sua) { - deepSetValue(deviceObj, 'sua', sua); - } + // Add User Agent Client hunts. + const uaClientHints = deepAccess(bidRequest, 'ortb2Imp.device.sua'); + let sua = null; + if (uaClientHints) { + sua = pick(uaClientHints, ['browsers', 'platform', 'mobile', 'model']); + } + if (sua) { + deepSetValue(deviceObj, 'sua', sua); + } return deviceObj; } From c1c8c6d0dc0de656d588917aab92b97052d1a095 Mon Sep 17 00:00:00 2001 From: Nayan Date: Tue, 3 Jan 2023 12:30:30 -0800 Subject: [PATCH 5/6] Adding unit test --- modules/yieldmoBidAdapter.js | 2 +- test/spec/modules/yieldmoBidAdapter_spec.js | 57 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index b2f9736cb44..9065a1469c7 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -516,7 +516,7 @@ function openRtbDevice(bidRequest) { ua: navigator.userAgent, language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), }; - // Add User Agent Client hunts. + // Add User Agent Client hints. const uaClientHints = deepAccess(bidRequest, 'ortb2Imp.device.sua'); let sua = null; if (uaClientHints) { diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index 8a0ebf863dd..7e63c2e5397 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -543,6 +543,63 @@ describe('YieldmoAdapter', function () { }; expect(buildAndGetData([mockVideoBid({...params})]).user.eids).to.eql(params.fakeUserIdAsEids); }); + it('should add device sua info to payload if available', function () { + let videoBid = mockVideoBid({ ortb2Imp: { + device: { + sua: { + platform: { + brand: 'macOS', + version: [ '12', '4', '0' ] + }, + browsers: [ + { + brand: 'Chromium', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Google Chrome', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Not;A=Brand', + version: [ '99', '0', '0', '0' ] + } + ], + mobile: 0, + model: '', + bitness: '64', + architecture: 'x86' + } + } + }}); + const payload = buildAndGetData([videoBid]); + expect(payload.device.sua).to.exist; + expect(payload.device.sua).to.deep.equal({ + platform: { + brand: 'macOS', + version: [ '12', '4', '0' ] + }, + browsers: [ + { + brand: 'Chromium', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Google Chrome', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Not;A=Brand', + version: [ '99', '0', '0', '0' ] + } + ], + mobile: 0, + model: '' + } + ); + videoBid = buildAndGetData([mockVideoBid()]); + expect(videoBid.device.sua).to.not.exist; + }); }); }); From a3dad9118e8786e8a86136fb324031819766cc17 Mon Sep 17 00:00:00 2001 From: Nayan Date: Thu, 5 Jan 2023 10:02:15 -0800 Subject: [PATCH 6/6] Copying entire device object --- modules/yieldmoBidAdapter.js | 25 ++----------------- test/spec/modules/yieldmoBidAdapter_spec.js | 27 +++++++++++++++------ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 9065a1469c7..5a0f302ab34 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -11,8 +11,7 @@ import { isStr, logError, parseQueryStringParameters, - parseUrl, - pick + parseUrl } from '../src/utils.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; @@ -386,7 +385,7 @@ function openRtbRequest(bidRequests, bidderRequest) { at: 1, imp: bidRequests.map(bidRequest => openRtbImpression(bidRequest)), site: openRtbSite(bidRequests[0], bidderRequest), - device: openRtbDevice(bidRequests[0]), + device: deepAccess(bidderRequest, 'ortb2.device'), badv: bidRequests[0].params.badv || [], bcat: deepAccess(bidderRequest, 'bcat') || bidRequests[0].params.bcat || [], ext: { @@ -508,26 +507,6 @@ function openRtbSite(bidRequest, bidderRequest) { return result; } -/** - * @return Object OpenRTB's 'device' object - */ -function openRtbDevice(bidRequest) { - const deviceObj = { - ua: navigator.userAgent, - language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), - }; - // Add User Agent Client hints. - const uaClientHints = deepAccess(bidRequest, 'ortb2Imp.device.sua'); - let sua = null; - if (uaClientHints) { - sua = pick(uaClientHints, ['browsers', 'platform', 'mobile', 'model']); - } - if (sua) { - deepSetValue(deviceObj, 'sua', sua); - } - return deviceObj; -} - /** * Updates openRtbRequest with GDPR info from bidderRequest, if present. * @param {Object} openRtbRequest OpenRTB's request to update. diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index 7e63c2e5397..4123422ce6e 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -543,8 +543,8 @@ describe('YieldmoAdapter', function () { }; expect(buildAndGetData([mockVideoBid({...params})]).user.eids).to.eql(params.fakeUserIdAsEids); }); - it('should add device sua info to payload if available', function () { - let videoBid = mockVideoBid({ ortb2Imp: { + it('should add device info to payload if available', function () { + let videoBidder = mockBidderRequest({ ortb2: { device: { sua: { platform: { @@ -571,8 +571,8 @@ describe('YieldmoAdapter', function () { architecture: 'x86' } } - }}); - const payload = buildAndGetData([videoBid]); + }}, [mockVideoBid()]); + let payload = buildAndGetData([mockVideoBid()], 0, videoBidder); expect(payload.device.sua).to.exist; expect(payload.device.sua).to.deep.equal({ platform: { @@ -594,11 +594,24 @@ describe('YieldmoAdapter', function () { } ], mobile: 0, - model: '' + model: '', + bitness: '64', + architecture: 'x86' } ); - videoBid = buildAndGetData([mockVideoBid()]); - expect(videoBid.device.sua).to.not.exist; + expect(payload.device.ua).to.not.exist; + expect(payload.device.language).to.not.exist; + // remove sua info and check device object + videoBidder = mockBidderRequest({ ortb2: { + device: { + ua: navigator.userAgent, + language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), + } + }}, [mockVideoBid()]); + payload = buildAndGetData([mockVideoBid()], 0, videoBidder); + expect(payload.device.sua).to.not.exist; + expect(payload.device.ua).to.exist; + expect(payload.device.language).to.exist; }); }); });