Skip to content

Commit

Permalink
Yieldmo Adapter: Add support for structured user agent (prebid#9380)
Browse files Browse the repository at this point in the history
* Adding sua to device object

* Update

* import pick

* ESLint fixes

* Adding unit test

* Copying entire device object
  • Loading branch information
desidiver authored and JacobKlein26 committed Feb 8, 2023
1 parent 5e04276 commit 42f9513
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
13 changes: 1 addition & 12 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,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: {
Expand Down Expand Up @@ -507,17 +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),
};
return deviceObj;
}

/**
* Updates openRtbRequest with GDPR info from bidderRequest, if present.
* @param {Object} openRtbRequest OpenRTB's request to update.
Expand Down
70 changes: 70 additions & 0 deletions test/spec/modules/yieldmoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,76 @@ describe('YieldmoAdapter', function () {
};
expect(buildAndGetData([mockVideoBid({...params})]).user.eids).to.eql(params.fakeUserIdAsEids);
});
it('should add device info to payload if available', function () {
let videoBidder = mockBidderRequest({ ortb2: {
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'
}
}
}}, [mockVideoBid()]);
let payload = buildAndGetData([mockVideoBid()], 0, videoBidder);
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: '',
bitness: '64',
architecture: 'x86'
}
);
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;
});
});
});

Expand Down

0 comments on commit 42f9513

Please sign in to comment.