Skip to content

Commit

Permalink
Rubicon Bid Adapter: Provide backwards compatibility for transparency…
Browse files Browse the repository at this point in the history
… object (#11426)

* Provide backwards compatibility for transparency object

When the property `transparency.params` gets passed in the `ortb2` object, the Rubicon adapter throws an error. 

This change will provide backwards compatibility for the `params` property by adding it to the `dsaparams` property.

If `params` or `dsaparams` does not exist, the value will be turned into an empty string. The same is done for the `domain` property. This ensures that the Bid Adapter will not error if these properties do not exist.

* Refactor RubiconBidAdapter to fix transparency object compatibility

* Fix transparency object compatibility in RubiconBidAdapter

* Fix transparency object compatibility in RubiconBidAdapter

* Refactor dsatransparency check

---------

Co-authored-by: Harry King-Riches <109534328+Strife9224@users.noreply.github.com>
  • Loading branch information
harrykingriches and harrykingriches committed May 8, 2024
1 parent 8c5c9d5 commit 85fd44e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
18 changes: 16 additions & 2 deletions modules/rubiconBidAdapter.js
Expand Up @@ -982,11 +982,25 @@ function applyFPD(bidRequest, mediaType, data) {
'transparency', (transparency) => {
if (Array.isArray(transparency) && transparency.length) {
data['dsatransparency'] = transparency.reduce((param, transp) => {
// make sure domain is there, otherwise skip entry
const domain = transp.domain || '';
if (!domain) {
return param;
}

// make sure dsaParam array is there (try both 'dsaparams' and 'params', but prefer dsaparams)
const dsaParamArray = transp.dsaparams || transp.params;
if (!Array.isArray(dsaParamArray) || dsaParamArray.length === 0) {
return param;
}

// finally we will add this one, if param has been added already, add our seperator
if (param) {
param += '~~'
}
return param += `${transp.domain}~${transp.dsaparams.join('_')}`
}, '')

return param += `${domain}~${dsaParamArray.join('_')}`;
}, '');
}
}
])
Expand Down
58 changes: 58 additions & 0 deletions test/spec/modules/rubiconBidAdapter_spec.js
Expand Up @@ -1735,6 +1735,64 @@ describe('the rubicon adapter', function () {
}
}
}
it('should send valid dsaparams but filter out invalid ones', function () {
const ortb2Clone = JSON.parse(JSON.stringify(ortb2));
ortb2Clone.regs.ext.dsa.transparency = [
{
domain: 'testdomain.com',
dsaparams: [1],
},
{
domain: '',
dsaparams: [2],
}
];

const expectedTransparency = 'testdomain.com~1';
const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({ ...b, ortb2: ortb2Clone })), bidderRequest);
const data = parseQuery(request.data);

expect(data['dsatransparency']).to.equal(expectedTransparency);
})
it('should send dsaparams if \"ortb2.regs.ext.dsa.transparancy[0].params\"', function() {
const ortb2Clone = JSON.parse(JSON.stringify(ortb2));

ortb2Clone.regs.ext.dsa.transparency = [{
domain: 'testdomain.com',
dsaparams: [1],
}];

const expectedTransparency = 'testdomain.com~1';
const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest);
const data = parseQuery(request.data);

expect(data['dsatransparency']).to.equal(expectedTransparency);
})
it('should pass an empty transparency param if \"ortb2.regs.ext.dsa.transparency[0].params\" is empty', function() {
const ortb2Clone = JSON.parse(JSON.stringify(ortb2));

ortb2Clone.regs.ext.dsa.transparency = [{
domain: 'testdomain.com',
params: [],
}];

const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest);
const data = parseQuery(request.data);
expect(data['dsatransparency']).to.be.undefined
})
it('should send an empty transparency if \"ortb2.regs.ext.dsa.transparency[0].domain\" is empty', function() {
const ortb2Clone = JSON.parse(JSON.stringify(ortb2));

ortb2Clone.regs.ext.dsa.transparency = [{
domain: '',
dsaparams: [1],
}];

const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest);
const data = parseQuery(request.data);

expect(data['dsatransparency']).to.be.undefined
})
it('should send dsa signals if \"ortb2.regs.ext.dsa\"', function() {
const expectedTransparency = 'testdomain.com~1~~testdomain2.com~1_2'
const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2})), bidderRequest)
Expand Down

0 comments on commit 85fd44e

Please sign in to comment.